Convert text to OGG file

This commit is contained in:
Hongbo Wu 2022-08-12 11:49:11 +08:00
parent 0419472c2e
commit 4b42d013ca
2 changed files with 6 additions and 6 deletions

View file

@ -26,7 +26,7 @@ export const createAudio = async (
): Promise<Buffer> => {
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,
})

View file

@ -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: '<speak><mark name="readability-page-1"/>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.</speak>',
engine: 'standard',
textType: 'ssml',
}
const output = await createAudioWithSpeechMarks(input)
expect(output.audioUrl).to.be.a('string')