mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Do not break on words and long sentence if exceeds 256 chars
This commit is contained in:
parent
851e264300
commit
3bd6b3d137
1 changed files with 15 additions and 17 deletions
|
|
@ -273,13 +273,12 @@ const textToUtterances = ({
|
|||
let text = textItems.join('')
|
||||
if (!isHtml) {
|
||||
// for title
|
||||
const wordCount = tokenizer.tokenize(text).length
|
||||
return [
|
||||
{
|
||||
idx,
|
||||
text,
|
||||
wordOffset,
|
||||
wordCount,
|
||||
wordCount: tokenizer.tokenize(text).length,
|
||||
voice,
|
||||
},
|
||||
]
|
||||
|
|
@ -302,15 +301,11 @@ const textToUtterances = ({
|
|||
const MAX_CHARS = 256
|
||||
const MAX_LOOKBACK = 80
|
||||
while (text.length > MAX_CHARS) {
|
||||
let lookback = MAX_LOOKBACK
|
||||
let end = MAX_CHARS - lookback
|
||||
while (lookback > 0) {
|
||||
if (text[end] === '.' || text[end] === '!' || text[end] === '?') {
|
||||
break
|
||||
}
|
||||
let end = MAX_CHARS - MAX_LOOKBACK - 1
|
||||
while (end < text.length && !text[end].match(/[.!?]/)) {
|
||||
end++
|
||||
lookback--
|
||||
}
|
||||
|
||||
const utterance = text.substring(0, end + 1)
|
||||
const wordCount = tokenizer.tokenize(utterance).length
|
||||
utterances.push({
|
||||
|
|
@ -324,14 +319,17 @@ const textToUtterances = ({
|
|||
wordOffset += wordCount
|
||||
}
|
||||
|
||||
const wordCount = tokenizer.tokenize(text).length
|
||||
utterances.push({
|
||||
idx,
|
||||
text,
|
||||
wordOffset,
|
||||
wordCount,
|
||||
voice,
|
||||
})
|
||||
if (text.length > 0) {
|
||||
const wordCount = tokenizer.tokenize(text).length
|
||||
utterances.push({
|
||||
idx,
|
||||
text,
|
||||
wordOffset,
|
||||
wordCount,
|
||||
voice,
|
||||
})
|
||||
}
|
||||
|
||||
return utterances
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue