.NET 文本转语音音量
我正在使用 System.Speech.Synthesis 参考来处理一个简单的文本到语音应用程序。我想向应用程序添加一个滑块控件并用它控制语音的音量。为了设置我正在使用的音量:
speech.Volume = 100;
我是否需要使用某种事件处理程序来更新此值?顺便说一下,我使用 C#(请不要使用 VB.NET 代码)将其创建为 WPF 应用程序。
I am working with a simple Text to Speech application using the System.Speech.Synthesis reference. I would like to add a slider control to the application and control the volume of the speech with it. In order to set the volume I'm using:
speech.Volume = 100;
Do I need to use some kind of event handler in order to update this value? By the way I'm creating this as a WPF application with C# (please not VB.NET code).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建
slider_ValueChanged
事件并设置Speech.volume = (int)sliderID.value;
create event of
slider_ValueChanged
and setSpeech.volume = (int)sliderID.value;
添加两个滑块,
sliderVolume
用于音量控制,sliderRate
用于速率控制。然后在 SpeakProgress 事件中,为speech
分配新的音量和速率,并使用characterPosition
创建原始阅读内容的子字符串。然后使用这个新的子字符串重新开始说话。请参阅以下代码。Add two sliders,
sliderVolume
for Volume control andsliderRate
for Rate control. Then in SpeakProgress event, assign new volume and rate tospeech
and by usingcharacterPosition
make a sub-string of original reading content. Then restart speak using this new sub-string. See the following code.当 Slider 控件的值发生变化时,它就会引发一个
ValueChanged
事件。如果您处理此事件,您可以通过检查Value
属性来更新您的语音音量。The Slider control raises an event
ValueChanged
whenever its value changes. If you handle this event you could update your speech volume from there by checking theValue
property.似乎没有内置的方法可以做到这一点。处理 SpeakProgress 事件将使您能够访问CharacterPosition 属性。这将为您提供提示中最后一个单词的开头位置。如果您在下一个空白字符上执行子字符串并将其作为新提示传递,则将从此时开始说出提示的其余部分。如果您愿意,您可以计算读取提示需要多长时间,并使用 AudioPosition 属性获取提示已运行多长时间的 TimeSpan 对象。
There does not appear to be a built-in way of doing this. Handling the SpeakProgress event will give you access to the CharacterPosition property. This gives you position in the prompt at the start of the last word read. If you do a substring on the next white-space character and pass this as a new prompt, the rest of the prompt will be spoken from this point. If you're up to it, you can calculate how long a prompt will take to be read and use the AudioPosition property to get a TimeSpan object for how long the prompt has been running.