diff --git a/packages/api/src/utils/textToSpeech.ts b/packages/api/src/utils/textToSpeech.ts index c348b9c4b..d9cf0af7e 100644 --- a/packages/api/src/utils/textToSpeech.ts +++ b/packages/api/src/utils/textToSpeech.ts @@ -61,7 +61,7 @@ export const createSpeechMarks = async ( } try { const data = await client.synthesizeSpeech(params).promise() - return data.AudioStream as string + return (data.AudioStream as Buffer).toString() } catch (error) { logger.error('Unable to create speech marks', { error }) throw error @@ -90,7 +90,7 @@ export const createAudioWithSpeechMarks = async ( speechMarks, } } catch (error) { - logger.error('Unable to create audio with speech marks', { error }) + logger.error('Unable to create audio with speech marks', error) throw error } } diff --git a/packages/api/test/utils/textToSpeech.test.ts b/packages/api/test/utils/textToSpeech.test.ts new file mode 100644 index 000000000..62a3e53c2 --- /dev/null +++ b/packages/api/test/utils/textToSpeech.test.ts @@ -0,0 +1,23 @@ +import 'mocha' +import { + createAudioWithSpeechMarks, + TextToSpeechInput, +} from '../../src/utils/textToSpeech' +import { expect } from 'chai' +import { generateFakeUuid } from '../util' + +describe('textToSpeech', () => { + describe('createAudioWithSpeechMarks', () => { + it('should create an audio file with speech marks', async () => { + const input: TextToSpeechInput = { + id: generateFakeUuid(), + title: 'Hello World', + text: 'Hello World', + engine: 'standard', + } + const output = await createAudioWithSpeechMarks(input) + expect(output.audioUrl).to.be.a('string') + expect(output.speechMarks).to.be.a('string') + }) + }) +})