@@ -101,7 +101,7 @@ export class SttTtsPlugin implements Plugin {
101
101
102
102
init ( params : { space : Space ; pluginConfig ?: Record < string , any > } ) : void {
103
103
elizaLogger . log (
104
- "[SttTtsPlugin] init => Space fully ready. Subscribing to events."
104
+ "[SttTtsPlugin] init => Space fully ready. Subscribing to events." ,
105
105
) ;
106
106
107
107
this . space = params . space ;
@@ -127,7 +127,6 @@ export class SttTtsPlugin implements Plugin {
127
127
if ( config ?. chatContext ) {
128
128
this . chatContext = config . chatContext ;
129
129
}
130
- elizaLogger . log ( "[SttTtsPlugin] Plugin config =>" , config ) ;
131
130
132
131
this . volumeBuffers = new Map < string , number [ ] > ( ) ;
133
132
}
@@ -163,14 +162,14 @@ export class SttTtsPlugin implements Plugin {
163
162
this . userSpeakingTimer = setTimeout ( ( ) => {
164
163
elizaLogger . log (
165
164
"[SttTtsPlugin] start processing audio for user =>" ,
166
- data . userId
165
+ data . userId ,
167
166
) ;
168
167
this . userSpeakingTimer = null ;
169
168
this . processAudio ( data . userId ) . catch ( ( err ) =>
170
169
elizaLogger . error (
171
170
"[SttTtsPlugin] handleSilence error =>" ,
172
- err
173
- )
171
+ err ,
172
+ ) ,
174
173
) ;
175
174
} , SILENCE_DETECTION_THRESHOLD_MS ) ;
176
175
} else {
@@ -183,7 +182,7 @@ export class SttTtsPlugin implements Plugin {
183
182
const samples = new Int16Array (
184
183
data . samples . buffer ,
185
184
data . samples . byteOffset ,
186
- data . samples . length / 2
185
+ data . samples . length / 2 ,
187
186
) ;
188
187
const maxAmplitude = Math . max ( ...samples . map ( Math . abs ) ) / 32768 ;
189
188
volumeBuffer . push ( maxAmplitude ) ;
@@ -209,7 +208,7 @@ export class SttTtsPlugin implements Plugin {
209
208
// /src/sttTtsPlugin.ts
210
209
private async convertPcmToWavInMemory (
211
210
pcmData : Int16Array ,
212
- sampleRate : number
211
+ sampleRate : number ,
213
212
) : Promise < ArrayBuffer > {
214
213
// number of channels
215
214
const numChannels = 1 ;
@@ -268,20 +267,20 @@ export class SttTtsPlugin implements Plugin {
268
267
try {
269
268
elizaLogger . log (
270
269
"[SttTtsPlugin] Starting audio processing for user:" ,
271
- userId
270
+ userId ,
272
271
) ;
273
272
const chunks = this . pcmBuffers . get ( userId ) || [ ] ;
274
273
this . pcmBuffers . clear ( ) ;
275
274
276
275
if ( ! chunks . length ) {
277
276
elizaLogger . warn (
278
277
"[SttTtsPlugin] No audio chunks for user =>" ,
279
- userId
278
+ userId ,
280
279
) ;
281
280
return ;
282
281
}
283
282
elizaLogger . log (
284
- `[SttTtsPlugin] Flushing STT buffer for user=${ userId } , chunks=${ chunks . length } `
283
+ `[SttTtsPlugin] Flushing STT buffer for user=${ userId } , chunks=${ chunks . length } ` ,
285
284
) ;
286
285
287
286
const totalLen = chunks . reduce ( ( acc , c ) => acc + c . length , 0 ) ;
@@ -296,36 +295,35 @@ export class SttTtsPlugin implements Plugin {
296
295
const wavBuffer = await this . convertPcmToWavInMemory ( merged , 48000 ) ;
297
296
298
297
// Whisper STT
299
- const sttText = await this . transcriptionService . transcribe (
300
- wavBuffer
301
- ) ;
298
+ const sttText =
299
+ await this . transcriptionService . transcribe ( wavBuffer ) ;
302
300
303
301
elizaLogger . log (
304
- `[SttTtsPlugin] Transcription result: "${ sttText } "`
302
+ `[SttTtsPlugin] Transcription result: "${ sttText } "` ,
305
303
) ;
306
304
307
305
if ( ! sttText || ! sttText . trim ( ) ) {
308
306
elizaLogger . warn (
309
307
"[SttTtsPlugin] No speech recognized for user =>" ,
310
- userId
308
+ userId ,
311
309
) ;
312
310
return ;
313
311
}
314
312
elizaLogger . log (
315
- `[SttTtsPlugin] STT => user=${ userId } , text="${ sttText } "`
313
+ `[SttTtsPlugin] STT => user=${ userId } , text="${ sttText } "` ,
316
314
) ;
317
315
318
316
// Get response
319
317
const replyText = await this . handleUserMessage ( sttText , userId ) ;
320
318
if ( ! replyText || ! replyText . length || ! replyText . trim ( ) ) {
321
319
elizaLogger . warn (
322
320
"[SttTtsPlugin] No replyText for user =>" ,
323
- userId
321
+ userId ,
324
322
) ;
325
323
return ;
326
324
}
327
325
elizaLogger . log (
328
- `[SttTtsPlugin] user=${ userId } , reply="${ replyText } "`
326
+ `[SttTtsPlugin] user=${ userId } , reply="${ replyText } "` ,
329
327
) ;
330
328
this . isProcessingAudio = false ;
331
329
this . volumeBuffers . clear ( ) ;
@@ -348,7 +346,7 @@ export class SttTtsPlugin implements Plugin {
348
346
this . processTtsQueue ( ) . catch ( ( err ) => {
349
347
elizaLogger . error (
350
348
"[SttTtsPlugin] processTtsQueue error =>" ,
351
- err
349
+ err ,
352
350
) ;
353
351
} ) ;
354
352
}
@@ -370,14 +368,14 @@ export class SttTtsPlugin implements Plugin {
370
368
const pcm = await this . convertMp3ToPcm ( ttsAudio , 48000 ) ;
371
369
if ( signal . aborted ) {
372
370
elizaLogger . log (
373
- "[SttTtsPlugin] TTS interrupted before streaming"
371
+ "[SttTtsPlugin] TTS interrupted before streaming" ,
374
372
) ;
375
373
return ;
376
374
}
377
375
await this . streamToJanus ( pcm , 48000 ) ;
378
376
if ( signal . aborted ) {
379
377
elizaLogger . log (
380
- "[SttTtsPlugin] TTS interrupted after streaming"
378
+ "[SttTtsPlugin] TTS interrupted after streaming" ,
381
379
) ;
382
380
return ;
383
381
}
@@ -396,7 +394,7 @@ export class SttTtsPlugin implements Plugin {
396
394
*/
397
395
private async handleUserMessage (
398
396
userText : string ,
399
- userId : string // This is the raw Twitter user ID like 'tw-1865462035586142208'
397
+ userId : string , // This is the raw Twitter user ID like 'tw-1865462035586142208'
400
398
) : Promise < string > {
401
399
// Extract the numeric ID part
402
400
const numericId = userId . replace ( "tw-" , "" ) ;
@@ -410,7 +408,7 @@ export class SttTtsPlugin implements Plugin {
410
408
userUuid ,
411
409
userId , // Use full Twitter ID as username
412
410
`Twitter User ${ numericId } ` ,
413
- "twitter"
411
+ "twitter" ,
414
412
) ;
415
413
416
414
// Ensure room exists and user is in it
@@ -427,7 +425,7 @@ export class SttTtsPlugin implements Plugin {
427
425
{
428
426
twitterUserName : this . client . profile . username ,
429
427
agentName : this . runtime . character . name ,
430
- }
428
+ } ,
431
429
) ;
432
430
433
431
const memory = {
@@ -492,7 +490,7 @@ export class SttTtsPlugin implements Plugin {
492
490
493
491
private async _generateResponse (
494
492
message : Memory ,
495
- context : string
493
+ context : string ,
496
494
) : Promise < Content > {
497
495
const { userId, roomId } = message ;
498
496
@@ -506,7 +504,7 @@ export class SttTtsPlugin implements Plugin {
506
504
507
505
if ( ! response ) {
508
506
elizaLogger . error (
509
- "[SttTtsPlugin] No response from generateMessageResponse"
507
+ "[SttTtsPlugin] No response from generateMessageResponse" ,
510
508
) ;
511
509
return ;
512
510
}
@@ -554,7 +552,7 @@ export class SttTtsPlugin implements Plugin {
554
552
if (
555
553
( message . content as Content ) . text . length < 50 &&
556
554
loseInterestWords . some ( ( word ) =>
557
- ( message . content as Content ) . text ?. toLowerCase ( ) . includes ( word )
555
+ ( message . content as Content ) . text ?. toLowerCase ( ) . includes ( word ) ,
558
556
)
559
557
) {
560
558
return true ;
@@ -564,7 +562,7 @@ export class SttTtsPlugin implements Plugin {
564
562
if (
565
563
( message . content as Content ) . text ?. length < 8 &&
566
564
ignoreWords . some ( ( word ) =>
567
- ( message . content as Content ) . text ?. toLowerCase ( ) . includes ( word )
565
+ ( message . content as Content ) . text ?. toLowerCase ( ) . includes ( word ) ,
568
566
)
569
567
) {
570
568
return true ;
@@ -575,7 +573,7 @@ export class SttTtsPlugin implements Plugin {
575
573
576
574
private async _shouldRespond (
577
575
message : string ,
578
- state : State
576
+ state : State ,
579
577
) : Promise < boolean > {
580
578
const lowerMessage = message . toLowerCase ( ) ;
581
579
const characterName = this . runtime . character . name . toLowerCase ( ) ;
@@ -610,7 +608,7 @@ export class SttTtsPlugin implements Plugin {
610
608
611
609
elizaLogger . error (
612
610
"Invalid response from response generateText:" ,
613
- response
611
+ response ,
614
612
) ;
615
613
return false ;
616
614
}
@@ -638,7 +636,7 @@ export class SttTtsPlugin implements Plugin {
638
636
if ( ! resp . ok ) {
639
637
const errText = await resp . text ( ) ;
640
638
throw new Error (
641
- `[SttTtsPlugin] ElevenLabs TTS error => ${ resp . status } ${ errText } `
639
+ `[SttTtsPlugin] ElevenLabs TTS error => ${ resp . status } ${ errText } ` ,
642
640
) ;
643
641
}
644
642
const arrayBuf = await resp . arrayBuffer ( ) ;
@@ -650,7 +648,7 @@ export class SttTtsPlugin implements Plugin {
650
648
*/
651
649
private convertMp3ToPcm (
652
650
mp3Buf : Buffer ,
653
- outRate : number
651
+ outRate : number ,
654
652
) : Promise < Int16Array > {
655
653
return new Promise ( ( resolve , reject ) => {
656
654
const ff = spawn ( "ffmpeg" , [
@@ -680,7 +678,7 @@ export class SttTtsPlugin implements Plugin {
680
678
const samples = new Int16Array (
681
679
raw . buffer ,
682
680
raw . byteOffset ,
683
- raw . byteLength / 2
681
+ raw . byteLength / 2 ,
684
682
) ;
685
683
resolve ( samples ) ;
686
684
} ) ;
@@ -696,7 +694,7 @@ export class SttTtsPlugin implements Plugin {
696
694
*/
697
695
private async streamToJanus (
698
696
samples : Int16Array ,
699
- sampleRate : number
697
+ sampleRate : number ,
700
698
) : Promise < void > {
701
699
// TODO: Check if better than 480 fixed
702
700
const FRAME_SIZE = Math . floor ( sampleRate * 0.01 ) ; // 10ms frames => 480 @48kHz
@@ -726,7 +724,7 @@ export class SttTtsPlugin implements Plugin {
726
724
public addMessage ( role : "system" | "user" | "assistant" , content : string ) {
727
725
this . chatContext . push ( { role, content } ) ;
728
726
elizaLogger . log (
729
- `[SttTtsPlugin] addMessage => role=${ role } , content=${ content } `
727
+ `[SttTtsPlugin] addMessage => role=${ role } , content=${ content } ` ,
730
728
) ;
731
729
}
732
730
0 commit comments