我尝试实施Microsoft语音识别教程。我没有得到任何错误,但仍然没有认出声音。该代码就像Microsoft语音无法识别语音
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Speech.Recognition;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
//SpeechRecognizer recognizer;
SpeechRecognitionEngine sre;
public Form1()
{
InitializeComponent();
sre = new SpeechRecognitionEngine();
sre.SetInputToWaveFile(@"c:\Test\Colors.wav");
Console.WriteLine("here");
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add(new string[] { "red", "green", "blue" });
Console.WriteLine("here");
// Create a GrammarBuilder object and append the Choices object.
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the Grammar instance and load it into the speech recognition engine.
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
// Start recognition.
sre.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
sre.Recognize();
Console.WriteLine("here");
}
private void Form1_Load(object sender, EventArgs e)
{
}
// Create a simple handler for the SpeechRecognized event.
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("here");
MessageBox.Show("Speech recognized: " + e.Result.Text);
}
}
}
请帮我理清!我不知道为什么它不工作,是新来的C#和Visual Studio
PS:我也得在输出窗口消息像下面这样在运行程序
The thread '<No Name>' (0x674) has exited with code 0 (0x0).
The thread '<No Name>' (0x1ee0) has exited with code 0 (0x0).
The thread '<No Name>' (0xf8) has exited with code 0 (0x0).
The thread '<No Name>' (0x760) has exited with code 0 (0x0).
The thread 'vshost.RunParkingWindow' (0x1184) has exited with code 0 (0x0).
你在使用什么语音库?我添加了对system.speech的引用,并且您的代码识别了我的wav文件。 –
我正在使用Microsoft.speech库...编辑:我检查了错误的文件对不起, – practice2perfect
请不要包括关于在问题标题中使用的语言的信息,除非它没有它没有意义。标签用于此目的。另外,如果你的问题不是直接关于它并且你只是写代码,那么不要在标签中包含IDE标签(Visual Studio)。代码问题很少连接到代码编辑器。 –