From 321895844f2ae3d2f9e816c8343ae17955d41ab7 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 5 Oct 2022 17:41:18 +0800 Subject: [PATCH] Revert back change on wordOffset --- packages/text-to-speech/src/textToSpeech.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/text-to-speech/src/textToSpeech.ts b/packages/text-to-speech/src/textToSpeech.ts index cd4114c00..d68789d29 100644 --- a/packages/text-to-speech/src/textToSpeech.ts +++ b/packages/text-to-speech/src/textToSpeech.ts @@ -52,6 +52,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 @@ -89,7 +90,7 @@ export const synthesizeTextToSpeech = async ( speechMarks.push({ word: e.text, time: (timeOffset + e.audioOffset) / 10000, - start: e.textOffset, + start: wordOffset + e.textOffset, length: e.text.length, type: 'word', }) @@ -139,6 +140,7 @@ export const synthesizeTextToSpeech = async ( } // for ssml const startSsmlTag = startSsml(ssmlOptions) + wordOffset -= startSsmlTag.length const text = _.escape(input.text) const ssml = `${startSsmlTag}${text}${endSsml()}` const result = await speakSsmlAsyncPromise(ssml)