我正在使用C#中的“ System.Speech.Recognition”和“ System.Speech.Synthesis”库来创建小型语音合成Windows应用程序。
该应用程序可以很好地处理语法中输入的单词,可以识别但无法识别其他单词。 (例如“ zapssss Hello zapssss”,实际上这不是一个适当的短语)。需要此部分的帮助。我是C#的新手。
代码部分如下:-
public string[] get_data_list()
{
int counter = 0;
string line;
string[] data_list = new string[8];
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\\Users\\usr\\Desktop\\Voice Recognition\\Voice Recognition\\data_dict.txt");
while ((line = file.ReadLine()) != null)
{
data_list[counter] = line;
System.Console.WriteLine(data_list[counter]);
counter++;
}
file.Close();
Console.WriteLine("Hello");
Console.WriteLine(data_list);
return data_list;
}
private void Form1_Load(object sender, EventArgs e)
{
Choices commands = new Choices();
string[] voice_dict = get_data_list();
foreach (string arrItem in voice_dict)
{
Console.WriteLine(arrItem);
}
commands.Add(voice_dict);
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += recEngine_SpeechRecognized;
}
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
System.Console.WriteLine("Entered Event");
string[] voice_dict = get_data_list();
string msg;
string user_recorded_voice = e.Result.Text;
string voice_check_flag = check_voice_available(user_recorded_voice, voice_dict);
switch (voice_check_flag)
{
case "not found":
System.Console.WriteLine("Match Not Found for " + user_recorded_voice);
msg = ("\nText " + user_recorded_voice + " Not Recognized");
text_box.Text += msg;
synth.SpeakAsync(msg);
break;
default:
Console.WriteLine("\nMessage recieved " + voice_check_flag);
text_box.Text += voice_check_flag;
synth.SpeakAsync(voice_check_flag);
break;
}
}
答案 0 :(得分:1)