mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Split text into chunks of 5000 characters in paragraph
This commit is contained in:
parent
c9d26acb25
commit
83c1930378
2 changed files with 12 additions and 6 deletions
|
|
@ -120,7 +120,7 @@ export function articleRouter() {
|
|||
return res.status(200).send('Page not found')
|
||||
}
|
||||
|
||||
const text = parseHTML(page.content).document.documentElement.textContent
|
||||
const text = parseHTML(page.content).document.documentElement.innerText
|
||||
if (!text) {
|
||||
return res.status(200).send('Page has no text')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,13 +129,19 @@ export const synthesizeTextToSpeech = async (
|
|||
)
|
||||
})
|
||||
}
|
||||
// slice the text into chunks of 1,000 characters
|
||||
const textChunks = input.text.match(/(.|[\r\n]){1,1000}/g) || []
|
||||
// slice the text into chunks of 5,000 characters
|
||||
let currentTextChunk = ''
|
||||
const textChunks = input.text.split('\n')
|
||||
for (const textChunk of textChunks) {
|
||||
logger.debug(`synthesizing ${textChunk}`)
|
||||
const result = await speakTextAsyncPromise(textChunk)
|
||||
currentTextChunk += textChunk + '\n'
|
||||
if (currentTextChunk.length < 5000) {
|
||||
continue
|
||||
}
|
||||
logger.debug(`synthesizing ${currentTextChunk}`)
|
||||
const result = await speakTextAsyncPromise(currentTextChunk)
|
||||
timeOffset = timeOffset + result.audioDuration
|
||||
characterOffset = characterOffset + textChunk.length
|
||||
characterOffset = characterOffset + currentTextChunk.length
|
||||
currentTextChunk = ''
|
||||
}
|
||||
writeStream.end()
|
||||
synthesizer.close()
|
||||
|
|
|
|||
Loading…
Reference in a new issue