Get realistic voice id from user personalization table

This commit is contained in:
Hongbo Wu 2022-11-08 10:21:27 +08:00
parent 2e47b0879c
commit 1af5af0e97

View file

@ -13,6 +13,7 @@ import { shouldSynthesize } from '../services/speech'
import { readPushSubscription } from '../datalayer/pubsub'
import { AppDataSource } from '../server'
import { enqueueTextToSpeech } from '../utils/createTask'
import { UserPersonalization } from '../entity/user_personalization'
const logger = buildLogger('app.dispatch')
@ -56,12 +57,15 @@ export function textToSpeechRouter() {
// checks if this page needs to be synthesized automatically
if (await shouldSynthesize(userId, page)) {
logger.info('page needs to be synthesized')
const userPersonalization = await getRepository(
UserPersonalization
).findOneBy({ user: { id: userId } })
// initialize state
const speech = await getRepository(Speech).save({
user: { id: userId },
elasticPageId: id,
state: SpeechState.INITIALIZED,
voice: 'en-US-JennyNeural',
voice: userPersonalization?.speechVoice || 'Harrison',
})
// enqueue a task to convert text to speech
const taskName = await enqueueTextToSpeech({
@ -70,6 +74,7 @@ export function textToSpeechRouter() {
text: page.content,
voice: speech.voice,
priority: 'low',
isUltraRealisticVoice: true,
})
logger.info('Start Text to speech task', { taskName })
return res.status(202).send('Text to speech task started')