Fix a bug for converting text to speech for articles with less than 5000 characters

This commit is contained in:
Hongbo Wu 2022-08-17 16:03:30 +08:00
parent 19b13d164d
commit dee94f7c93
2 changed files with 3 additions and 6 deletions

View file

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

View file

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