社区中心
一个论坛类别,用于讨论Microsoft Q&A 网站本身,包括反馈、bug、建议和社区计划。
我想使用Speech SDK 文字转化语音的合成端事件 WordBoundary,按照文档说明,对应的属性是
SpeechServiceResponse_RequestWordBoundary(常量值 44)。
只有把它设成 true(或调用 speechConfig.requestWordLevelTimestamps(),它在合成侧内部其实就是帮你 set 了 RequestWordBoundary),服务端才会在音频流里随路推送 SynthesisWordBoundary 事件;
问题:我在浏览器端HMTL代码中设置了上述属性,但是,合成服务不会回传任何词级时间戳,控制台也就看不到 synthesisWordBoundary 打印。
代码如下:
try {
// 2. 初始化Azure Speech配置
const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(speechKey, speechRegion);
speechConfig.requestWordLevelTimestamps();
speechConfig.speechSynthesisVoiceName = voiceName;
speechConfig.speechSynthesisOutputFormat = SpeechSDK.SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm; // 输出WAV格式
// 关键:显式请求边界事件
speechConfig.setProperty(SpeechSDK.PropertyId.SpeechServiceResponse_RequestWordBoundary,'true');
speechConfig.setProperty(SpeechSDK.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps,'true');
// 3. 创建语音合成器(支持获取字级别时间戳)
const synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, null);
console.log('PropertyId 对象', SpeechSDK.PropertyId);
// 监听合成进度事件
synthesizer.synthesizing = (s, e) => {
console.log('Synthesizing event:', e);
};
// 监听合成开始事件
synthesizer.visemeReceived = (s, e) => {
console.log('Viseme received:', e);
};
// 4. 注册事件监听(获取字幕时间戳、合成结果)
// 监听字级别时间戳事件(用于生成WebVTT)
synthesizer.synthesisWordBoundary = (s, e) => {
console.log(`[${e.audioOffset / 10000} ms] "${e.text}" `);
这里控制台没有关于字级别时间戳事件的打印。只有合成进度事件,合成开始事件和合成结束事件的打印。