From dee94f7c932505fdae54d60c76c1612208d07fab Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 17 Aug 2022 16:03:30 +0800 Subject: [PATCH] Fix a bug for converting text to speech for articles with less than 5000 characters --- packages/api/src/utils/parser.ts | 3 --- packages/api/src/utils/textToSpeech.ts | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/api/src/utils/parser.ts b/packages/api/src/utils/parser.ts index 2e9997e58..a46aed2bc 100644 --- a/packages/api/src/utils/parser.ts +++ b/packages/api/src/utils/parser.ts @@ -285,13 +285,11 @@ export const parsePreparedContent = async ( // Get the top level element? const pageNode = article.dom.firstElementChild as HTMLElement - console.log('pageNode: ', pageNode) const nodesToVisitStack: [HTMLElement] = [pageNode] const visitedNodeList = [] while (nodesToVisitStack.length > 0) { const currentNode = nodesToVisitStack.pop() - console.log('currentNode: ', currentNode?.nodeType) if ( currentNode?.nodeType !== 1 || // Avoiding dynamic elements from being counted as anchor-allowed elements @@ -316,7 +314,6 @@ export const parsePreparedContent = async ( node.setAttribute('data-omnivore-anchor-idx', (index + 1).toString()) }) - console.log('article content:', article.dom.outerHTML) article.content = article.dom.outerHTML } diff --git a/packages/api/src/utils/textToSpeech.ts b/packages/api/src/utils/textToSpeech.ts index b8249c14e..ae2101240 100644 --- a/packages/api/src/utils/textToSpeech.ts +++ b/packages/api/src/utils/textToSpeech.ts @@ -132,9 +132,9 @@ export const synthesizeTextToSpeech = async ( // slice the text into chunks of 5,000 characters let currentTextChunk = '' const textChunks = input.text.split('\n') - for (const textChunk of textChunks) { - currentTextChunk += textChunk + '\n' - if (currentTextChunk.length < 5000) { + for (let i = 0; i < textChunks.length; i++) { + currentTextChunk += textChunks[i] + '\n' + if (currentTextChunk.length < 5000 && i < textChunks.length - 1) { continue } logger.debug(`synthesizing ${currentTextChunk}`)