Add tests

This commit is contained in:
Hongbo Wu
2022-08-11 17:37:35 +08:00
parent bca0f5ed59
commit dd332f5ee6
2 changed files with 25 additions and 2 deletions

View File

@ -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
}
}

View File

@ -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')
})
})
})