diff --git a/packages/text-to-speech/src/index.ts b/packages/text-to-speech/src/index.ts index 07233a0c8..9a9c93c31 100644 --- a/packages/text-to-speech/src/index.ts +++ b/packages/text-to-speech/src/index.ts @@ -170,9 +170,12 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( ...utteranceInput, textType: 'utterance', } - const { audioStream, speechMarks } = await synthesizeTextToSpeech(input) + const { audioData, speechMarks } = await synthesizeTextToSpeech(input) + if (!audioData) { + return res.status(500).send({ errorCode: 'SYNTHESIZER_ERROR' }) + } res.send({ - audioData: audioStream.read().toString('hex'), + audioData: audioData.toString('hex'), speechMarks, }) } catch (e) { diff --git a/packages/text-to-speech/src/textToSpeech.ts b/packages/text-to-speech/src/textToSpeech.ts index db39e77b8..fa406d3b8 100644 --- a/packages/text-to-speech/src/textToSpeech.ts +++ b/packages/text-to-speech/src/textToSpeech.ts @@ -21,7 +21,7 @@ export interface TextToSpeechInput { } export interface TextToSpeechOutput { - audioStream: NodeJS.ReadWriteStream + audioData?: Buffer speechMarks: SpeechMark[] } @@ -146,7 +146,11 @@ export const synthesizeTextToSpeech = async ( } else { // assemble ssml const ssml = `${startSsml(null, ssmlOptions)}${input.text}${endSsml()}` - await speakSsmlAsyncPromise(ssml) + const result = await speakSsmlAsyncPromise(ssml) + return { + audioData: Buffer.from(result.audioData), + speechMarks, + } } } catch (error) { console.error('synthesis error', error) @@ -159,7 +163,6 @@ export const synthesizeTextToSpeech = async ( } return { - audioStream, speechMarks, } }