我是C#的新手,我正在使用SpeechSynthesizer读出一些单词。但我需要算一下我说话时说的话数。那有什么办法吗?任何帮助将不胜感激。感谢
答案 0 :(得分: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);
}
答案 1 :(得分:0)
当然,有System.Speech.Synthesizer.SpeakProgress
事件。该事件具有字符数和字符位置(从字符串的开头),可用于计算单词。 (你甚至可能每个单词都有一个事件,尽管我不确定所有语言都是如此。)