mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-18 19:27:46 +00:00
fixed cartesia collect audio from stream
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user