2014-02-24 35 views

回答

0

當然,有System.Speech.Synthesizer.SpeakProgress事件。該事件具有字符計數和字符位置(從字符串的開始),您可以使用它來計算單詞。 (您甚至可能會得到每個單詞的事件,但我不確定所有語言都是如此。)

1

您可以使用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); 
      } 
相關問題