Skip to content

Commit e9cc2fe

Browse files
committed
fix(voice-call): reject containerized mulaw TTS
1 parent 4283f6e commit e9cc2fe

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

‎extensions/voice-call/src/telephony-tts.test.ts‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,30 @@ describe("createTelephonyTtsProvider", () => {
7272
);
7373
});
7474

75-
it("rejects unsupported container output with provider context", async () => {
76-
const provider = await createTelephonyTtsProvider({
77-
coreConfig: createCoreConfig(),
78-
runtime: createRuntime(async () => ({
79-
success: true,
80-
audioBuffer: Buffer.from("container"),
81-
outputFormat: "mp3",
82-
sampleRate: 24_000,
83-
provider: "example-provider",
84-
})),
85-
});
75+
it.each([
76+
["mp3", 24_000],
77+
["riff-8khz-8bit-mono-mulaw", 8_000],
78+
])(
79+
"rejects unsupported %s container output with provider context",
80+
async (outputFormat, sampleRate) => {
81+
const provider = await createTelephonyTtsProvider({
82+
coreConfig: createCoreConfig(),
83+
runtime: createRuntime(async () => ({
84+
success: true,
85+
audioBuffer: Buffer.from("container"),
86+
outputFormat,
87+
sampleRate,
88+
provider: "example-provider",
89+
})),
90+
});
8691

87-
const synthesis = provider.synthesizeForTelephony("hello");
88-
await expect(synthesis).rejects.toMatchObject({
89-
name: "UnsupportedTelephonyTtsOutputFormatError",
90-
message: 'Unsupported telephony TTS output format "mp3" from provider "example-provider"',
91-
});
92-
});
92+
const synthesis = provider.synthesizeForTelephony("hello");
93+
await expect(synthesis).rejects.toMatchObject({
94+
name: "UnsupportedTelephonyTtsOutputFormatError",
95+
message: `Unsupported telephony TTS output format "${outputFormat}" from provider "example-provider"`,
96+
});
97+
},
98+
);
9399

94100
it("uses shared preparation for the surface override and request text", async () => {
95101
const effectiveConfig: OpenClawConfig = {

‎extensions/voice-call/src/telephony-tts.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ function convertTelephonyTtsOutput(result: {
6262
const format = result.outputFormat?.trim().toLowerCase();
6363
// Bundled provider contracts: Azure/Gradium emit raw-8khz-8bit-mono-mulaw/ulaw_8000;
6464
// ElevenLabs/OpenAI emit pcm_22050/pcm. An absent format is the shipped PCM default.
65-
const isMulaw = format?.includes("mulaw") || format?.includes("ulaw");
66-
const names8Khz = format?.includes("8khz") || format?.includes("8000");
67-
if (isMulaw && names8Khz && result.sampleRate === 8_000) {
65+
const isRawMulaw = format === "raw-8khz-8bit-mono-mulaw" || format === "ulaw_8000";
66+
if (isRawMulaw && result.sampleRate === 8_000) {
6867
return result.audioBuffer;
6968
}
7069
const isPcm =

0 commit comments

Comments
 (0)