저는 C#에서 새로운 기능을 제공하며 SpeechSynthesizer를 사용하여 일부 단어를 읽습니다. 그러나 나는 말하고있는 동안 내가 말한 단어의 수를 세어야한다. 거기에 어떤 방법이 있습니까 ?? 어떤 도움을 주시면 감사하겠습니다. 감사합니다.SpeechSynthesizer에서 음성 단어 수를 얻는 방법
0
A
답변
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);
}