From 9d5b298dc075107ae51b71eede362842b8625374 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 14 Feb 2023 18:46:25 +0800 Subject: [PATCH 1/2] Return empty result if no synthesized output from api --- packages/text-to-speech/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/text-to-speech/src/index.ts b/packages/text-to-speech/src/index.ts index f9386a448..6e51e9428 100644 --- a/packages/text-to-speech/src/index.ts +++ b/packages/text-to-speech/src/index.ts @@ -246,7 +246,7 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( try { const utteranceInput = req.body as UtteranceInput if (!utteranceInput.text) { - return res.status(400).send('INVALID_INPUT') + return res.send({ idx: utteranceInput.idx, audioData: '', speechMarks: [] }) } // validate if user has opted in to use ultra realistic voice feature @@ -307,7 +307,7 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( const [exists] = await audioFile.exists() if (exists) { console.debug('Audio file already exists') - ;[audioData] = await audioFile.download() + ;[audioData] = await audioFile.download() const [speechMarksExists] = await speechMarksFile.exists() if (speechMarksExists) { speechMarks = JSON.parse( @@ -326,7 +326,7 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( audioData = output.audioData speechMarks = output.speechMarks if (!audioData || audioData.length === 0) { - return res.status(500).send({ errorCode: 'SYNTHESIZER_ERROR' }) + return res.send({ idx: utteranceInput.idx, audioData: '', speechMarks: [] }) } console.debug('saving audio file') From 5bde7f0344257aba91767cb0f2d1d992db3cf7d8 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 15 Feb 2023 23:49:05 +0800 Subject: [PATCH 2/2] Lint --- packages/text-to-speech/src/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/text-to-speech/src/index.ts b/packages/text-to-speech/src/index.ts index 6e51e9428..821611ffb 100644 --- a/packages/text-to-speech/src/index.ts +++ b/packages/text-to-speech/src/index.ts @@ -246,7 +246,11 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( try { const utteranceInput = req.body as UtteranceInput if (!utteranceInput.text) { - return res.send({ idx: utteranceInput.idx, audioData: '', speechMarks: [] }) + return res.send({ + idx: utteranceInput.idx, + audioData: '', + speechMarks: [], + }) } // validate if user has opted in to use ultra realistic voice feature @@ -307,7 +311,7 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( const [exists] = await audioFile.exists() if (exists) { console.debug('Audio file already exists') - ;[audioData] = await audioFile.download() + ;[audioData] = await audioFile.download() const [speechMarksExists] = await speechMarksFile.exists() if (speechMarksExists) { speechMarks = JSON.parse( @@ -326,7 +330,11 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( audioData = output.audioData speechMarks = output.speechMarks if (!audioData || audioData.length === 0) { - return res.send({ idx: utteranceInput.idx, audioData: '', speechMarks: [] }) + return res.send({ + idx: utteranceInput.idx, + audioData: '', + speechMarks: [], + }) } console.debug('saving audio file')