Skip to content

Commit 87687cf

Browse files
committed
fix: validate OpenAI TTS voice names, fall back to nova for unknown IDs
When the BatchTTSFallback chain passes an ElevenLabs voice ID to the OpenAI provider, OpenAI returns 400 because it's not a valid voice name. Now validates against the known set and falls back to 'nova'.
1 parent f697654 commit 87687cf

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/voice-pipeline/providers/OpenAIBatchTTS.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ export class OpenAIBatchTTS implements IBatchTTS {
4646
* @param config - Optional voice, format, and speed overrides.
4747
* @returns The synthesized audio buffer with metadata.
4848
*/
49+
/** Valid OpenAI TTS voice names. */
50+
private static readonly VALID_VOICES = new Set([
51+
'nova', 'shimmer', 'echo', 'onyx', 'fable', 'alloy', 'ash', 'sage', 'coral',
52+
]);
53+
4954
async synthesize(text: string, config?: BatchTTSConfig): Promise<BatchTTSResult> {
50-
const voice = config?.voice ?? 'nova';
55+
// Validate voice name — if an external voice ID (e.g. ElevenLabs) is passed
56+
// via the fallback chain, fall back to 'nova' instead of sending it to OpenAI.
57+
const rawVoice = config?.voice ?? 'nova';
58+
const voice = OpenAIBatchTTS.VALID_VOICES.has(rawVoice) ? rawVoice : 'nova';
5159
const format = config?.format ?? 'mp3';
5260

5361
const body: Record<string, unknown> = {

0 commit comments

Comments
 (0)