diff --git a/src/modules/speex/protocols/rpc/rpc.client.ts b/src/modules/speex/protocols/rpc/rpc.client.ts index e124551a5..67b437a7e 100644 --- a/src/modules/speex/protocols/rpc/rpc.client.ts +++ b/src/modules/speex/protocols/rpc/rpc.client.ts @@ -17,6 +17,7 @@ import { AudioPlayer } from '~/common/util/audio/AudioPlayer'; import type { DSpeexEngine, SpeexSpeakResult } from '../../speex.types'; import type { SpeexWire_Access, SpeexWire_ListVoices_Output, SpeexWire_Voice } from './rpc.wiretypes'; +import { SPEEX_DEBUG } from '../../speex.config'; type _DSpeexEngineRPC = DSpeexEngine<'elevenlabs'> | DSpeexEngine<'localai'> | DSpeexEngine<'openai'>; @@ -44,6 +45,7 @@ export async function speexSynthesize_RPC( ): Promise { // engine credentials (DCredentials..) -> wire Access + if (SPEEX_DEBUG) console.log(`[Speex RPC] Synthesize request (engine: ${engine.engineId}, ${text.length} chars) - options:`, options); const access = _buildRPCWireAccess(engine); if (!access) { const error = new Error(`Failed to resolve credentials for engine ${engine.engineId}`); @@ -72,6 +74,7 @@ export async function speexSynthesize_RPC( // process streaming particles for await (const particle of particleStream) { + if (SPEEX_DEBUG) console.log('[Speex RPC] <-', particle); switch (particle.t) { case 'start': callbacks?.onStart?.(); @@ -134,7 +137,9 @@ export async function speexSynthesize_RPC( return result; } catch (error: any) { - // Cleanup + if (SPEEX_DEBUG) console.error('[Speex RPC] Synthesis error:', { error }); + + // cleanup if (audioPlayer) void audioPlayer.stop(); diff --git a/src/modules/speex/protocols/rpc/synthesize-elevenlabs.ts b/src/modules/speex/protocols/rpc/synthesize-elevenlabs.ts index eb184e22d..81490b72c 100644 --- a/src/modules/speex/protocols/rpc/synthesize-elevenlabs.ts +++ b/src/modules/speex/protocols/rpc/synthesize-elevenlabs.ts @@ -4,6 +4,7 @@ import { fetchJsonOrTRPCThrow, fetchResponseOrTRPCThrow } from '~/server/trpc/tr import type { SpeexSpeechParticle, SpeexWire_Access_ElevenLabs, SpeexWire_ListVoices_Output } from './rpc.wiretypes'; import type { SynthesizeBackendFn } from './rpc.router'; +import { SPEEX_DEBUG } from '../../speex.config'; import { returnAudioWholeOrThrow, streamAudioChunksOrThrow } from './rpc.streaming'; @@ -53,6 +54,7 @@ export const synthesizeElevenLabs: SynthesizeBackendFn): SpeexListVoiceOption[] { return browserVoices.map(v => ({ @@ -128,6 +130,7 @@ export function speexSynthesize_WebSpeech( speechSynthesis.cancel(); // safe // create utterance + if (SPEEX_DEBUG) console.debug(`[Speex][WebSpeech] New utterance (${text.length} chars, voice: ${voice.ttsVoiceURI}, s=${voice.ttsSpeed}, p=${voice.ttsPitch})`); const utterance = new SpeechSynthesisUtterance(text); // find and set voice by URI @@ -144,15 +147,18 @@ export function speexSynthesize_WebSpeech( // set up event handlers utterance.onstart = () => { + if (SPEEX_DEBUG) console.debug(`[Speex][WebSpeech] Utterance started`); callbacks?.onStart?.(); }; utterance.onend = () => { + if (SPEEX_DEBUG) console.debug(`[Speex][WebSpeech] Utterance completed`); callbacks?.onComplete?.(); resolve({ success: true }); }; utterance.onerror = (event) => { + if (SPEEX_DEBUG) console.error(`[Speex][WebSpeech] Utterance error`, event.error); const errorMessage = event.error || 'Speech synthesis failed'; const error = new Error(errorMessage); callbacks?.onError?.(error); diff --git a/src/modules/speex/speex.config.ts b/src/modules/speex/speex.config.ts new file mode 100644 index 000000000..a935fa6a8 --- /dev/null +++ b/src/modules/speex/speex.config.ts @@ -0,0 +1,2 @@ +// configuration +export const SPEEX_DEBUG = false; \ No newline at end of file