Do not breaking on words and bookmarks

This commit is contained in:
Hongbo Wu 2022-09-26 17:47:40 +08:00
parent 9545d1d532
commit 35f7b0b90b

View file

@ -139,11 +139,12 @@ export const synthesizeTextToSpeech = async (
}
// for ssml
let audioData: Buffer = Buffer.from([])
// split ssml into chunks of 200 characters to stream faster
const ssmlChunks = input.text.match(/.{1,200}/g)
// TODO: not split on words and bookmarks
// split ssml into chunks of 2000 characters to stream faster
// both within limit & without breaking on words and bookmarks
const ssmlChunks = input.text.match(/.{1,2000}(?= |$)(?! mark=)/g)
if (ssmlChunks) {
for (const ssmlChunk of ssmlChunks) {
console.log('ssmlChunk', ssmlChunk)
const ssml = `${startSsml(ssmlOptions)}${ssmlChunk}${endSsml()}`
const result = await speakSsmlAsyncPromise(ssml)
if (result.reason === ResultReason.Canceled) {