From 4b42d013cafd0f597a02c4ac571138bb8568f84d Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 12 Aug 2022 11:49:11 +0800 Subject: [PATCH] Convert text to OGG file --- packages/api/src/utils/textToSpeech.ts | 8 ++++---- packages/api/test/utils/textToSpeech.test.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/api/src/utils/textToSpeech.ts b/packages/api/src/utils/textToSpeech.ts index 34e2e860b..5d3f40eca 100644 --- a/packages/api/src/utils/textToSpeech.ts +++ b/packages/api/src/utils/textToSpeech.ts @@ -26,7 +26,7 @@ export const createAudio = async ( ): Promise => { const { text, voice, textType, engine } = input const params: SynthesizeSpeechInput = { - OutputFormat: 'mp3', + OutputFormat: 'ogg_vorbis', Text: text, TextType: textType || 'text', VoiceId: voice || 'Joanna', @@ -51,7 +51,7 @@ export const createSpeechMarks = async ( TextType: textType || 'text', VoiceId: voice || 'Joanna', Engine: engine || 'neural', - SpeechMarkTypes: ['sentence', 'word'], + SpeechMarkTypes: ['sentence'], } try { const data = await client.synthesizeSpeech(params).promise() @@ -68,11 +68,11 @@ export const createAudioWithSpeechMarks = async ( try { const audio = await createAudio(input) // upload audio to google cloud storage - const filePath = `speech/${input.id}.mp3` + const filePath = `speech/${input.id}.ogg` logger.info('start uploading...', { filePath }) await uploadToBucket(filePath, audio, { - contentType: 'audio/mpeg', + contentType: 'audio/ogg', public: true, }) diff --git a/packages/api/test/utils/textToSpeech.test.ts b/packages/api/test/utils/textToSpeech.test.ts index 62a3e53c2..0dc698c33 100644 --- a/packages/api/test/utils/textToSpeech.test.ts +++ b/packages/api/test/utils/textToSpeech.test.ts @@ -11,9 +11,9 @@ describe('textToSpeech', () => { it('should create an audio file with speech marks', async () => { const input: TextToSpeechInput = { id: generateFakeUuid(), - title: 'Hello World', - text: 'Hello World', + text: 'The rumor mill suggests that Google may be looking to kill off its game streaming platform, Stadia, for good before the end of the year.', engine: 'standard', + textType: 'ssml', } const output = await createAudioWithSpeechMarks(input) expect(output.audioUrl).to.be.a('string')