Skip to content

Commit 2af84f8

Browse files
authored
Merge pull request #2716 from elizaOS/tcm-remove-config-log
Remove the log as it may potentially cause the app to crash
2 parents 2cac5df + b9d0dc3 commit 2af84f8

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

packages/client-twitter/src/plugins/SttTtsSpacesPlugin.ts

+33-35
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class SttTtsPlugin implements Plugin {
101101

102102
init(params: { space: Space; pluginConfig?: Record<string, any> }): void {
103103
elizaLogger.log(
104-
"[SttTtsPlugin] init => Space fully ready. Subscribing to events."
104+
"[SttTtsPlugin] init => Space fully ready. Subscribing to events.",
105105
);
106106

107107
this.space = params.space;
@@ -127,7 +127,6 @@ export class SttTtsPlugin implements Plugin {
127127
if (config?.chatContext) {
128128
this.chatContext = config.chatContext;
129129
}
130-
elizaLogger.log("[SttTtsPlugin] Plugin config =>", config);
131130

132131
this.volumeBuffers = new Map<string, number[]>();
133132
}
@@ -163,14 +162,14 @@ export class SttTtsPlugin implements Plugin {
163162
this.userSpeakingTimer = setTimeout(() => {
164163
elizaLogger.log(
165164
"[SttTtsPlugin] start processing audio for user =>",
166-
data.userId
165+
data.userId,
167166
);
168167
this.userSpeakingTimer = null;
169168
this.processAudio(data.userId).catch((err) =>
170169
elizaLogger.error(
171170
"[SttTtsPlugin] handleSilence error =>",
172-
err
173-
)
171+
err,
172+
),
174173
);
175174
}, SILENCE_DETECTION_THRESHOLD_MS);
176175
} else {
@@ -183,7 +182,7 @@ export class SttTtsPlugin implements Plugin {
183182
const samples = new Int16Array(
184183
data.samples.buffer,
185184
data.samples.byteOffset,
186-
data.samples.length / 2
185+
data.samples.length / 2,
187186
);
188187
const maxAmplitude = Math.max(...samples.map(Math.abs)) / 32768;
189188
volumeBuffer.push(maxAmplitude);
@@ -209,7 +208,7 @@ export class SttTtsPlugin implements Plugin {
209208
// /src/sttTtsPlugin.ts
210209
private async convertPcmToWavInMemory(
211210
pcmData: Int16Array,
212-
sampleRate: number
211+
sampleRate: number,
213212
): Promise<ArrayBuffer> {
214213
// number of channels
215214
const numChannels = 1;
@@ -268,20 +267,20 @@ export class SttTtsPlugin implements Plugin {
268267
try {
269268
elizaLogger.log(
270269
"[SttTtsPlugin] Starting audio processing for user:",
271-
userId
270+
userId,
272271
);
273272
const chunks = this.pcmBuffers.get(userId) || [];
274273
this.pcmBuffers.clear();
275274

276275
if (!chunks.length) {
277276
elizaLogger.warn(
278277
"[SttTtsPlugin] No audio chunks for user =>",
279-
userId
278+
userId,
280279
);
281280
return;
282281
}
283282
elizaLogger.log(
284-
`[SttTtsPlugin] Flushing STT buffer for user=${userId}, chunks=${chunks.length}`
283+
`[SttTtsPlugin] Flushing STT buffer for user=${userId}, chunks=${chunks.length}`,
285284
);
286285

287286
const totalLen = chunks.reduce((acc, c) => acc + c.length, 0);
@@ -296,36 +295,35 @@ export class SttTtsPlugin implements Plugin {
296295
const wavBuffer = await this.convertPcmToWavInMemory(merged, 48000);
297296

298297
// Whisper STT
299-
const sttText = await this.transcriptionService.transcribe(
300-
wavBuffer
301-
);
298+
const sttText =
299+
await this.transcriptionService.transcribe(wavBuffer);
302300

303301
elizaLogger.log(
304-
`[SttTtsPlugin] Transcription result: "${sttText}"`
302+
`[SttTtsPlugin] Transcription result: "${sttText}"`,
305303
);
306304

307305
if (!sttText || !sttText.trim()) {
308306
elizaLogger.warn(
309307
"[SttTtsPlugin] No speech recognized for user =>",
310-
userId
308+
userId,
311309
);
312310
return;
313311
}
314312
elizaLogger.log(
315-
`[SttTtsPlugin] STT => user=${userId}, text="${sttText}"`
313+
`[SttTtsPlugin] STT => user=${userId}, text="${sttText}"`,
316314
);
317315

318316
// Get response
319317
const replyText = await this.handleUserMessage(sttText, userId);
320318
if (!replyText || !replyText.length || !replyText.trim()) {
321319
elizaLogger.warn(
322320
"[SttTtsPlugin] No replyText for user =>",
323-
userId
321+
userId,
324322
);
325323
return;
326324
}
327325
elizaLogger.log(
328-
`[SttTtsPlugin] user=${userId}, reply="${replyText}"`
326+
`[SttTtsPlugin] user=${userId}, reply="${replyText}"`,
329327
);
330328
this.isProcessingAudio = false;
331329
this.volumeBuffers.clear();
@@ -348,7 +346,7 @@ export class SttTtsPlugin implements Plugin {
348346
this.processTtsQueue().catch((err) => {
349347
elizaLogger.error(
350348
"[SttTtsPlugin] processTtsQueue error =>",
351-
err
349+
err,
352350
);
353351
});
354352
}
@@ -370,14 +368,14 @@ export class SttTtsPlugin implements Plugin {
370368
const pcm = await this.convertMp3ToPcm(ttsAudio, 48000);
371369
if (signal.aborted) {
372370
elizaLogger.log(
373-
"[SttTtsPlugin] TTS interrupted before streaming"
371+
"[SttTtsPlugin] TTS interrupted before streaming",
374372
);
375373
return;
376374
}
377375
await this.streamToJanus(pcm, 48000);
378376
if (signal.aborted) {
379377
elizaLogger.log(
380-
"[SttTtsPlugin] TTS interrupted after streaming"
378+
"[SttTtsPlugin] TTS interrupted after streaming",
381379
);
382380
return;
383381
}
@@ -396,7 +394,7 @@ export class SttTtsPlugin implements Plugin {
396394
*/
397395
private async handleUserMessage(
398396
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'
400398
): Promise<string> {
401399
// Extract the numeric ID part
402400
const numericId = userId.replace("tw-", "");
@@ -410,7 +408,7 @@ export class SttTtsPlugin implements Plugin {
410408
userUuid,
411409
userId, // Use full Twitter ID as username
412410
`Twitter User ${numericId}`,
413-
"twitter"
411+
"twitter",
414412
);
415413

416414
// Ensure room exists and user is in it
@@ -427,7 +425,7 @@ export class SttTtsPlugin implements Plugin {
427425
{
428426
twitterUserName: this.client.profile.username,
429427
agentName: this.runtime.character.name,
430-
}
428+
},
431429
);
432430

433431
const memory = {
@@ -492,7 +490,7 @@ export class SttTtsPlugin implements Plugin {
492490

493491
private async _generateResponse(
494492
message: Memory,
495-
context: string
493+
context: string,
496494
): Promise<Content> {
497495
const { userId, roomId } = message;
498496

@@ -506,7 +504,7 @@ export class SttTtsPlugin implements Plugin {
506504

507505
if (!response) {
508506
elizaLogger.error(
509-
"[SttTtsPlugin] No response from generateMessageResponse"
507+
"[SttTtsPlugin] No response from generateMessageResponse",
510508
);
511509
return;
512510
}
@@ -554,7 +552,7 @@ export class SttTtsPlugin implements Plugin {
554552
if (
555553
(message.content as Content).text.length < 50 &&
556554
loseInterestWords.some((word) =>
557-
(message.content as Content).text?.toLowerCase().includes(word)
555+
(message.content as Content).text?.toLowerCase().includes(word),
558556
)
559557
) {
560558
return true;
@@ -564,7 +562,7 @@ export class SttTtsPlugin implements Plugin {
564562
if (
565563
(message.content as Content).text?.length < 8 &&
566564
ignoreWords.some((word) =>
567-
(message.content as Content).text?.toLowerCase().includes(word)
565+
(message.content as Content).text?.toLowerCase().includes(word),
568566
)
569567
) {
570568
return true;
@@ -575,7 +573,7 @@ export class SttTtsPlugin implements Plugin {
575573

576574
private async _shouldRespond(
577575
message: string,
578-
state: State
576+
state: State,
579577
): Promise<boolean> {
580578
const lowerMessage = message.toLowerCase();
581579
const characterName = this.runtime.character.name.toLowerCase();
@@ -610,7 +608,7 @@ export class SttTtsPlugin implements Plugin {
610608

611609
elizaLogger.error(
612610
"Invalid response from response generateText:",
613-
response
611+
response,
614612
);
615613
return false;
616614
}
@@ -638,7 +636,7 @@ export class SttTtsPlugin implements Plugin {
638636
if (!resp.ok) {
639637
const errText = await resp.text();
640638
throw new Error(
641-
`[SttTtsPlugin] ElevenLabs TTS error => ${resp.status} ${errText}`
639+
`[SttTtsPlugin] ElevenLabs TTS error => ${resp.status} ${errText}`,
642640
);
643641
}
644642
const arrayBuf = await resp.arrayBuffer();
@@ -650,7 +648,7 @@ export class SttTtsPlugin implements Plugin {
650648
*/
651649
private convertMp3ToPcm(
652650
mp3Buf: Buffer,
653-
outRate: number
651+
outRate: number,
654652
): Promise<Int16Array> {
655653
return new Promise((resolve, reject) => {
656654
const ff = spawn("ffmpeg", [
@@ -680,7 +678,7 @@ export class SttTtsPlugin implements Plugin {
680678
const samples = new Int16Array(
681679
raw.buffer,
682680
raw.byteOffset,
683-
raw.byteLength / 2
681+
raw.byteLength / 2,
684682
);
685683
resolve(samples);
686684
});
@@ -696,7 +694,7 @@ export class SttTtsPlugin implements Plugin {
696694
*/
697695
private async streamToJanus(
698696
samples: Int16Array,
699-
sampleRate: number
697+
sampleRate: number,
700698
): Promise<void> {
701699
// TODO: Check if better than 480 fixed
702700
const FRAME_SIZE = Math.floor(sampleRate * 0.01); // 10ms frames => 480 @48kHz
@@ -726,7 +724,7 @@ export class SttTtsPlugin implements Plugin {
726724
public addMessage(role: "system" | "user" | "assistant", content: string) {
727725
this.chatContext.push({ role, content });
728726
elizaLogger.log(
729-
`[SttTtsPlugin] addMessage => role=${role}, content=${content}`
727+
`[SttTtsPlugin] addMessage => role=${role}, content=${content}`,
730728
);
731729
}
732730

0 commit comments

Comments
 (0)