mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Stop counting the words in SSML tags
This commit is contained in:
parent
f1b379b96e
commit
d9dc701de8
1 changed files with 12 additions and 11 deletions
|
|
@ -13,7 +13,7 @@ export interface TextToSpeechInput {
|
|||
text: string
|
||||
voice?: string
|
||||
language?: string
|
||||
textType?: 'html' | 'ssml' | 'utterance'
|
||||
textType?: 'html' | 'utterance'
|
||||
rate?: number
|
||||
complimentaryVoice?: string
|
||||
audioStream?: NodeJS.ReadWriteStream
|
||||
|
|
@ -51,6 +51,7 @@ export const synthesizeTextToSpeech = async (
|
|||
const synthesizer = new SpeechSynthesizer(speechConfig)
|
||||
const speechMarks: SpeechMark[] = []
|
||||
let timeOffset = 0
|
||||
let wordOffset = 0
|
||||
|
||||
synthesizer.synthesizing = function (s, e) {
|
||||
// convert arrayBuffer to stream and write to stream
|
||||
|
|
@ -93,7 +94,7 @@ export const synthesizeTextToSpeech = async (
|
|||
speechMarks.push({
|
||||
word: e.text,
|
||||
time: (timeOffset + e.audioOffset) / 10000,
|
||||
start: e.textOffset,
|
||||
start: wordOffset + e.textOffset,
|
||||
length: e.wordLength,
|
||||
type: 'word',
|
||||
})
|
||||
|
|
@ -142,15 +143,19 @@ export const synthesizeTextToSpeech = async (
|
|||
const result = await speakSsmlAsyncPromise(ssml)
|
||||
timeOffset = timeOffset + result.audioDuration
|
||||
}
|
||||
} else {
|
||||
// assemble ssml
|
||||
const ssml = `${startSsml(null, ssmlOptions)}${input.text}${endSsml()}`
|
||||
const result = await speakSsmlAsyncPromise(ssml)
|
||||
return {
|
||||
audioData: Buffer.from(result.audioData),
|
||||
speechMarks,
|
||||
}
|
||||
}
|
||||
// for utterance
|
||||
const start = startSsml(ssmlOptions)
|
||||
wordOffset = -start.length
|
||||
const ssml = `${start}${input.text}${endSsml()}`
|
||||
const result = await speakSsmlAsyncPromise(ssml)
|
||||
return {
|
||||
audioData: Buffer.from(result.audioData),
|
||||
speechMarks,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('synthesis error', error)
|
||||
throw error
|
||||
|
|
@ -160,8 +165,4 @@ export const synthesizeTextToSpeech = async (
|
|||
synthesizer.close()
|
||||
console.debug('synthesizer closed')
|
||||
}
|
||||
|
||||
return {
|
||||
speechMarks,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue