Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/every-voice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@everyvoice/every-voice",
"version": "0.0.5",
"version": "0.0.6",
"peerDependencies": {
"@angular/common": "^14.2.0",
"@angular/core": "^14.2.0",
Expand Down
8 changes: 7 additions & 1 deletion projects/every-voice/src/lib/every-voice.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export interface Speaker {
display: string;
slug: string;
}

export interface EveryVoiceConfig {
enableTTS: boolean;
requiresAuth: boolean;
apiUrl?: string;
developmentBearerToken?: string; // Optional: Token for authentication
speakerID?: string; // Optional: Speaker ID for TTS
availableSpeakers?: Speaker[]; // Optional: Available Speaker IDs for TTS
defaultSpeaker?: Speaker; // Optional: Speaker ID for TTS
diffusionSteps?: number; // Optional: Number of steps for TTS
domain?: string; // Optional: Auth0 Domain
clientId?: string; // Optional: Auth0 ClientId
Expand Down
44 changes: 7 additions & 37 deletions projects/every-voice/src/lib/every-voice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ import {
EveryVoiceConfig,
EveryVoiceServiceStatus,
EveryVoiceServiceMiddlewareInfoResponse,
Speaker,
} from "./every-voice.config";
import {
BehaviorSubject,
from,
Subject,
Observable,
throwError,
of,
} from "rxjs";
import { BehaviorSubject, from, Subject, Observable, throwError } from "rxjs";
import { catchError, finalize, map, switchMap, tap } from "rxjs/operators";
import { AuthService } from "@auth0/auth0-angular";

Expand All @@ -23,8 +17,8 @@ export class EveryVoiceService {
public status$: Subject<{ id: string; status: EveryVoiceServiceStatus }>;
public ttsEnabledAndAuthenticated$ = new BehaviorSubject<boolean>(false);
public loading$ = new BehaviorSubject<boolean>(false);
public speakers$ = new BehaviorSubject<string[]>([]);
public speakerID: string | undefined;
public speakers$ = new BehaviorSubject<Speaker[]>([]);
public speakerID: Speaker | undefined;
public diffusionSteps: number | undefined;
private enableTTS: boolean;
private requiresAuth: boolean;
Expand Down Expand Up @@ -52,36 +46,12 @@ export class EveryVoiceService {
? config.enableTTS
: config?.apiUrl?.length > 0; // Only enable TTS by default if apiUrl is defined
this.bearerToken = config?.developmentBearerToken;
this.speakerID = config?.speakerID;
this.speakers$.next(config?.availableSpeakers);
this.speakerID = config?.defaultSpeaker;
this.diffusionSteps = config?.diffusionSteps;
this.requiresAuth = config?.requiresAuth;
// If authentication is not required, then we set the default to true
this.ttsEnabledAndAuthenticated$.next(this.enableTTS && !this.requiresAuth);
// If tts enabled and authenticated, then look for fetch and set the tts options
this.ttsEnabledAndAuthenticated$
.pipe(
switchMap((isAuthenticated) => {
if (isAuthenticated && this.requiresAuth) {
return this.setTTSOptions().pipe(
tap((response) => {
this.speakers$.next(response.speakers || []);

this.speakerID = this.speakerID || response.defaultSpeaker;

this.diffusionSteps =
this.diffusionSteps || response.defaultDiffusionSteps;
})
);
} else {
return of(isAuthenticated);
}
}),
catchError((err) => {
console.error("[ERROR] Failed to set TTS options:", err);
return throwError(err);
})
)
.subscribe();
console.log("[DEBUG] initialized EveryVoiceService with config:", config);
this.status$.next({ id: "all", status: "READY" });
}
Expand Down Expand Up @@ -514,7 +484,7 @@ export class EveryVoiceService {
const options: EveryVoiceServiceMiddlewareInfoResponse = {
speakers: [],
defaultDiffusionSteps: this.diffusionSteps,
defaultSpeaker: this.speakerID,
defaultSpeaker: this.speakerID.slug,
};
if (infoResponse["named_endpoints"]) {
const namedEndpoints = infoResponse["named_endpoints"];
Expand Down
Loading