语音识别-SAPI v5.1 SpeechRecognitionEngine的帮助总是用C#给出相同的错误结果
本文关键字:结果 错误 v5 -SAPI SpeechRecognitionEngine 帮助 语音识别 | 更新日期: 2023-09-27 17:58:10
我在玩这个SAPI v5.1库。所以我测试了一个WAV样本文件。(从这里下载)。不管怎样,那个文件里的声音很清晰,很容易。它只包含一个单词,即第三个单词。现在,当我运行以下代码时,我会得到数字8或"8"。如果我去掉它,我得到7。如果我试图随机化列表,我会得到不同的结果,等等。我真的很困惑,开始认为SAPI库中的SpeachRecognition根本不起作用。。。
不管怎样,,这就是我要做的
private void button1_Click(object sender, EventArgs e)
{
//Add choices to grammar.
Choices mychoices = new Choices();
mychoices.Add("one");
mychoices.Add("two");
mychoices.Add("three");
mychoices.Add("four");
mychoices.Add("five");
mychoices.Add("six");
mychoices.Add("seven");
mychoices.Add("eight");
mychoices.Add("nine");
mychoices.Add("zero");
mychoices.Add("1");
mychoices.Add("2");
mychoices.Add("3");
mychoices.Add("4");
mychoices.Add("5");
mychoices.Add("6");
mychoices.Add("7");
mychoices.Add("8");
mychoices.Add("9");
mychoices.Add("0");
Grammar myGrammar = new Grammar(new GrammarBuilder(mychoices));
//Create the engine.
SpeechRecognitionEngine reco = new SpeechRecognitionEngine();
//Read audio stream from wav file.
reco.SetInputToWaveFile("3.wav");
reco.LoadGrammar(myGrammar);
//Get the recognized value.
reco.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(reco_SpeechRecognized);
reco.RecognizeAsync(RecognizeMode.Multiple);
}
void reco_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show(e.Result.Text);
}
您是如何创建WAV文件的?看起来它的比特率很高。识别器只支持某些格式。尝试:
- 每个样本8位
- 单声道单声道
- 每秒22050个样本
- PCM编码
您有大约3秒的音频,文件大小为520;KB。对于支持的格式来说,这似乎太大了。
您可以使用RecognizerInfo类为您的识别器查找支持的音频格式(SupportedAudioFormats)-RecognizerInfo.SupportedAudioFormat属性。
更新:
你的音频文件有点乱。噪音很大。它也是不受支持的格式。Audacity将其报告为立体声,44.1;kHz和32位浮点。我在开始和结束时静音,重新采样到22.050;kHz,删除立体声音轨,然后导出为未压缩的8位无符号WAV。然后它就可以正常工作了。
在我的Windows7机器上,我的默认识别器只支持以下音频格式:
0:
Encodingformat = Pcm
BitsPerSample = 8
BlockAlign = 1
ChannelCount = 1
SamplesPerSecond = 16000
1:
Encodingformat = Pcm
BitsPerSample = 16
BlockAlign = 2
ChannelCount = 1
SamplesPerSecond = 16000
2:
Encodingformat = Pcm
BitsPerSample = 8
BlockAlign = 1
ChannelCount = 1
SamplesPerSecond = 22050
3:
Encodingformat = Pcm
BitsPerSample = 16
BlockAlign = 2
ChannelCount = 1
SamplesPerSecond = 22050
4:
Encodingformat = ALaw
BitsPerSample = 8
BlockAlign = 1
ChannelCount = 1
SamplesPerSecond = 22050
5:
Encodingformat = ULaw
BitsPerSample = 8
BlockAlign = 1
ChannelCount = 1
SamplesPerSecond = 22050
您还应该从语法中删除数字选项。现在,识别器返回两个备用项:"三"answers"3"。这可能不是你想要的。您可以在语法中使用语义结果值来返回单词"三"的数字3。