Skip to content

Commit 687075c

Browse files
committed
clean up code and comments
1 parent e09963f commit 687075c

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

examples/src/inworld_tts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default defineAgent({
4141
maxBufferDelayMs: 3000,
4242
});
4343

44-
// List available voices (non-blocking)
44+
// List available voices
4545
tts
4646
.listVoices()
4747
.then((voices: inworld.Voice[]) => {
@@ -79,7 +79,7 @@ export default defineAgent({
7979
},
8080
});
8181

82-
// timestamp handling for inworld TTS
82+
// timestamp handling (if enabled)
8383
session.tts!.on('alignment' as any, (data: any) => {
8484
if (data.wordAlignment) {
8585
const { words, starts, ends } = data.wordAlignment;

plugins/inworld/src/tts.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class WSConnectionPool {
192192
#attemptConnection(): Promise<WebSocket> {
193193
return new Promise((resolve, reject) => {
194194
const wsUrl = new URL('tts/v1/voice:streamBidirectional', this.#url);
195-
// Ensure protocol is wss
196195
if (wsUrl.protocol === 'https:') wsUrl.protocol = 'wss:';
197196
else if (wsUrl.protocol === 'http:') wsUrl.protocol = 'ws:';
198197

@@ -224,7 +223,6 @@ class WSConnectionPool {
224223
const json = JSON.parse(data.toString()) as InworldMessage;
225224
const result = json.result;
226225
if (result) {
227-
// Try to find contextId in result or top level
228226
const contextId = result.contextId || json.contextId;
229227
if (contextId && this.#listeners.has(contextId)) {
230228
this.#listeners.get(contextId)!(json);
@@ -288,7 +286,7 @@ export class TTS extends tts.TTS {
288286
}
289287

290288
/**
291-
* List all available voices.
289+
* List all available voices in the workspace associated with the API key.
292290
* @param language - Optional ISO 639-1 language code to filter voices (e.g., 'en', 'es', 'fr')
293291
*/
294292
async listVoices(language?: string): Promise<Voice[]> {
@@ -327,10 +325,6 @@ export class TTS extends tts.TTS {
327325
this.#opts = { ...this.#opts, ...opts };
328326
if (opts.apiKey) {
329327
this.#authorization = `Basic ${opts.apiKey}`;
330-
// If API key changes, we might need to reset the pool or create a new one?
331-
// For now, assume WS url doesn't change or we just create new pool if needed.
332-
// But existing pool has hardcoded auth in constructor.
333-
// Re-creating pool is safer.
334328
this.#pool.close();
335329
this.#pool = new WSConnectionPool(this.#opts.wsURL, this.#authorization);
336330
}
@@ -482,22 +476,16 @@ class SynthesizeStream extends tts.SynthesizeStream {
482476
if (!result) return;
483477

484478
if (result.contextCreated) {
485-
// context created
486479
} else if (result.contextClosed) {
487480
resolveProcessing();
488481
} else if (result.audioChunk) {
489482
if (result.audioChunk.timestampInfo) {
490-
// Log word timestamps if available
491483
const tsInfo = result.audioChunk.timestampInfo;
492484
if (tsInfo.wordAlignment) {
493485
const words = tsInfo.wordAlignment.words || [];
494486
const starts = tsInfo.wordAlignment.wordStartTimeSeconds || [];
495487
const ends = tsInfo.wordAlignment.wordEndTimeSeconds || [];
496488

497-
for (let i = 0; i < words.length; i++) {
498-
// console.log(`[Inworld TTS] Word: "${words[i]}", Start: ${starts[i]}, End: ${ends[i]}`);
499-
}
500-
501489
// eslint-disable-next-line @typescript-eslint/no-explicit-any
502490
(this.#tts as any).emit('alignment', {
503491
requestId: this.#contextId,
@@ -521,7 +509,6 @@ class SynthesizeStream extends tts.SynthesizeStream {
521509
}
522510

523511
if (result.audioChunk.audioContent) {
524-
// Some servers may return either nested audioContent or top-level
525512
const b64Content = result.audioChunk.audioContent || result.audioContent;
526513
if (b64Content) {
527514
const audio = Buffer.from(b64Content, 'base64');

0 commit comments

Comments
 (0)