我需要一个具有可设置的持续时间属性的语音合成器来指定讲文本所需的时间。System.Speech.Synthesis.SpeechSynthesizer类仅具有Rate属性。
有一个System.Speech.Synthesis.TtsEngine NameSpace,它有一个具有可设置持续时间属性的韵律类。但是,我找不到如何使用TtsEngine或如何将该属性应用于SpeechSynthesizer类的任何示例(如果可能的话)。还是有一个不同的语音合成库,我应该去看看?
发布于 2021-03-11 21:05:45
我想我已经搞清楚了,这要归功于对这个问题的第一次响应的提示。
using System.Speech.Synthesis;
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
void speak_utterance(string utterance_text, int duration_millisec = 0) {
if (duration_millisec <= 0) {
synthesizer.Speak(utterance_text);
}
else {
PromptBuilder builder = new PromptBuilder();
builder.AppendSsmlMarkup("<prosody duration='" + duration_millisec.ToString() + "ms'>" + utterance_text + "</prosody>");
synthesizer.Speak(builder);
}
}我注意到了一些与持续时间和合成器说数字时的意外交互。例如:
string clearance0 = "american one twenty three cleared to land runway one left"
string clearance1= "american 123 cleared to land runway one left"
speak_utterance(clearance0, 10000);
speak_utterance(clearance1, 10000);对于第一个电话,整个演讲都是缓慢的,超过10秒。
在第二次呼叫中,"american 123“是缓慢的,并且像第一次那样被拉出来,但是说话的后半部分是以正常的速度说出来的,总的持续时间是<所需的。因此,我将不得不将数字转换为单词,以获得一致的性能。(或者可能有一个属性会影响合成器处理数字的方式,从而纠正这种情况。如果我发现任何情况,将进行更新。)
https://stackoverflow.com/questions/66575574
复制相似问题