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 {
const client = new CartesiaClient({ apiKey: api_key });
const sampleRate = 48000;
const mp3 = await client.tts.bytes({
const mp3Stream = await client.tts.bytes({
modelId: model_id,
transcript: text,
voice: {
@@ -1363,8 +1363,16 @@ const synthCartesia = async(logger, {
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 {
audioContent: Buffer.from(mp3),
audioContent: audioBuffer,
extension: 'mp3',
sampleRate
};

View File

@@ -716,7 +716,7 @@ test('Cartesia speech synth tests', async(t) => {
text,
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) {
console.error(JSON.stringify(err));