diff --git a/packages/api/src/routers/svc/text_to_speech.ts b/packages/api/src/routers/svc/text_to_speech.ts index f80f138ba..8f597c652 100644 --- a/packages/api/src/routers/svc/text_to_speech.ts +++ b/packages/api/src/routers/svc/text_to_speech.ts @@ -36,17 +36,17 @@ export function speechServiceRouter() { } try { - const data: { userId: string; type: string; id: string } = + const data: { userId: string; type: string; id: string; state: string } = JSON.parse(msgStr) - const { userId, type, id } = data + const { userId, type, id, state } = data if (!userId || !type || !id) { logger.info('Invalid data') return res.status(400).send('Bad Request') } - if (type.toUpperCase() !== 'PAGE') { - logger.info('Not a page') - return res.status(200).send('Not a page') + if (type.toUpperCase() !== 'PAGE' || state !== 'SUCCEEDED') { + logger.info('Not a page or not succeeded') + return res.status(200).send('Not a page or not succeeded') } const page = await getPageById(id) @@ -63,6 +63,7 @@ export function speechServiceRouter() { user: { id: userId }, elasticPageId: id, state: SpeechState.INITIALIZED, + voice: 'en-US-JennyNeural', }) await synthesize(page, speech) logger.info('page synthesized') diff --git a/packages/api/src/services/speech.ts b/packages/api/src/services/speech.ts index 19a2df42f..8d390c374 100644 --- a/packages/api/src/services/speech.ts +++ b/packages/api/src/services/speech.ts @@ -1,7 +1,7 @@ import { getRepository } from '../entity/utils' import { Speech, SpeechState } from '../entity/speech' import { searchPages } from '../elastic/pages' -import { Page } from '../elastic/types' +import { Page, PageType } from '../elastic/types' import { SortBy, SortOrder } from '../utils/search' import { synthesizeTextToSpeech } from '../utils/textToSpeech' @@ -21,6 +21,11 @@ export const shouldSynthesize = async ( userId: string, page: Page ): Promise => { + if (page.pageType === PageType.File || !page.content) { + // we don't synthesize files for now + return false + } + if (process.env.TEXT_TO_SPEECH_BETA_TEST) { return true } @@ -52,7 +57,12 @@ export const shouldSynthesize = async ( export const synthesize = async (page: Page, speech: Speech): Promise => { try { - console.log('synthesizing', speech.id) + if (page.pageType === PageType.File || !page.content) { + // we don't synthesize files for now + return + } + + console.log('Start synthesizing', { pageId: page.id, speechId: speech.id }) const startTime = Date.now() const speechOutput = await synthesizeTextToSpeech({ id: speech.id,