我是 C# 新手,我正在使用 SpeechSynthesizer 读出一些单词。但我需要数一数我说话时说了多少字。有什么办法吗??任何帮助将不胜感激。谢谢
问问题
446 次
2 回答
2
您可以System.Speech.Synthesizer.SpeakProgress
为此使用事件。看下面的代码,
int WordCount = 0;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.SpeakProgress += new EventHandler<System.Speech.Synthesis.SpeakProgressEventArgs>(synthesizer_SpeakProgress);
synthesizer.SpeakAsync("Hello How Are You?");
}
void synthesizer_SpeakProgress(object sender, System.Speech.Synthesis.SpeakProgressEventArgs e)
{
WordCount++;
//To Write word count
Console.WriteLine(WordCount.toString());
//To Write each word and its character postion to the console.
Console.WriteLine("CharPos: {0} CharCount: {1} AudioPos: {2} \"{3}\"", e.CharacterPosition, e.CharacterCount, e.AudioPosition, e.Text);
}
于 2016-12-22T06:40:49.527 回答
0
当然,有System.Speech.Synthesizer.SpeakProgress
活动。该事件有一个字符计数和字符位置(从字符串的开头开始),您可以使用它们来计算字数。(您甚至可能每个单词都会得到一个事件,尽管我不确定这是否适用于所有语言。)
于 2014-02-25T06:57:04.447 回答