fixed cartesia collect audio from stream

This commit is contained in:
Hoan HL
2025-11-13 14:10:00 +07:00
parent 8154944252
commit c04ef29f7c
2 changed files with 11 additions and 3 deletions

View File

@@ -1329,7 +1329,7 @@ const synthCartesia = async(logger, {
try { try {
const client = new CartesiaClient({ apiKey: api_key }); const client = new CartesiaClient({ apiKey: api_key });
const sampleRate = 48000; const sampleRate = 48000;
const mp3 = await client.tts.bytes({ const mp3Stream = await client.tts.bytes({
modelId: model_id, modelId: model_id,
transcript: text, transcript: text,
voice: { voice: {
@@ -1363,8 +1363,16 @@ const synthCartesia = async(logger, {
sampleRate sampleRate
}, },
}); });
// bytes() returns a ReadableStream - collect all chunks
const chunks = [];
for await (const chunk of mp3Stream) {
chunks.push(chunk);
}
const audioBuffer = Buffer.concat(chunks);
return { return {
audioContent: Buffer.from(mp3), audioContent: audioBuffer,
extension: 'mp3', extension: 'mp3',
sampleRate sampleRate
}; };

View File

@@ -716,7 +716,7 @@ test('Cartesia speech synth tests', async(t) => {
text, text,
renderForCaching: true renderForCaching: true
}); });
t.ok(!opts.servedFromCache, `successfully playht eleven audio to ${opts.filePath}`); t.ok(!opts.servedFromCache, `successfully cartesia eleven audio to ${opts.filePath}`);
} catch (err) { } catch (err) {
console.error(JSON.stringify(err)); console.error(JSON.stringify(err));