Skip to content

Commit

Permalink
make it output good audio
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Oct 16, 2024
1 parent fbb5796 commit 0ce1b42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 0 additions & 2 deletions examples/src/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ export default defineAgent({
console.log('speaking "Goodbye!"');
stream.pushText('Goodbye!');
stream.flush();
// stream.endInput();
});

for await (const audio of stream) {
console.log(audio);
await source.captureFrame(audio.frame);
}
},
Expand Down
7 changes: 3 additions & 4 deletions plugins/elevenlabs/src/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class SynthesizeStream extends tts.SynthesizeStream {
super();
this.#opts = opts;
this.closed = false;
this.streamURL = `${this.#opts.baseURL}/text-to-speech/${this.#opts.voice.id}/stream-input?model_id=${this.#opts.modelID}&optimize_streaming_latency=${this.#opts.streamingLatency}`;
this.streamURL = `${this.#opts.baseURL}/text-to-speech/${this.#opts.voice.id}/stream-input?model_id=${this.#opts.modelID}&output_format=${this.#opts.encoding}&optimize_streaming_latency=${this.#opts.streamingLatency}&enable_ssml_parsing=${this.#opts.enableSsmlParsing}`;
this.#run();
}

Expand Down Expand Up @@ -234,13 +234,12 @@ export class SynthesizeStream extends tts.SynthesizeStream {
}).then((msg) => {
const json = JSON.parse(msg.toString());
if ('audio' in json) {
console.log(json.audio);
const data = Int16Array.from(Buffer.from(json.audio, 'base64'));
const data = new Int16Array(Buffer.from(json.audio, 'base64').buffer);
const frame = new AudioFrame(
data,
sampleRateFromFormat(this.#opts.encoding),
1,
Math.trunc(data.length / 2),
data.length,
);
this.queue.put({ requestId, segmentId, frame });
}
Expand Down

0 comments on commit 0ce1b42

Please sign in to comment.