C# 使用Microsoft SpeechRecognitionEngine时,如何提高结果的准确性?
我目前正在开发一个拨号服务项目。其中一个功能是将录制的.wav媒体文件解释为明文。我使用SpeechRecognitionEngine试图解释内容,但我得到了一些不准确的结果,有时甚至是毫无意义的断句 .wav文件是来自两个或多个客户之间电话对话的录制文件,我测试的文件是我与同事进行的非常简单和简短的对话 因此,我的问题是如何提高解释的准确性,以及如何为此改进代码?我知道添加语法将有助于识别某些关键字,但我需要的是一般解释我从用户那里录制的内容 这是我的工作代码:C# 使用Microsoft SpeechRecognitionEngine时,如何提高结果的准确性?,c#,speech-recognition,C#,Speech Recognition,我目前正在开发一个拨号服务项目。其中一个功能是将录制的.wav媒体文件解释为明文。我使用SpeechRecognitionEngine试图解释内容,但我得到了一些不准确的结果,有时甚至是毫无意义的断句 .wav文件是来自两个或多个客户之间电话对话的录制文件,我测试的文件是我与同事进行的非常简单和简短的对话 因此,我的问题是如何提高解释的准确性,以及如何为此改进代码?我知道添加语法将有助于识别某些关键字,但我需要的是一般解释我从用户那里录制的内容 这是我的工作代码: using System; u
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Speech.Recognition;
using System.Speech.AudioFormat;
using System.Web;
namespace VoiceRecognition
{
class Program
{
static bool completed;
static void Main(string[] args)
{
using (
SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(
new System.Globalization.CultureInfo("en-US")))
{
// Create and load a grammar.
Grammar dictation = new DictationGrammar();
dictation.Name = "Dictation Grammar";
recognizer.LoadGrammar(new DictationGrammar());
recognizer.SetInputToWaveFile(@"C:\Projects2\VoiceRecognition2\conf_with_vincent_1.wav");
// Attach event handlers for the results of recognition.
//recognizer.AudioLevelUpdated += new EventHandler<AudioLevelUpdatedEventArgs>(recognizer_AudioLevelUpdated);
//recognizer.AudioStateChanged += new EventHandler<AudioStateChangedEventArgs>(recognizer_AudioStateChanged);
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);
// Perform recognition on the entire file.
Console.WriteLine("Starting asynchronous recognition...");
completed = false;
//recognizer.RecognizeAsync();
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (!completed)
{
Console.ReadLine();
}
Console.WriteLine("Done.");
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Handle the Audio state event.
static void recognizer_AudioStateChanged(object sender, AudioStateChangedEventArgs e)
{
Console.WriteLine("The new audio state is: " + e.AudioState);
}
static void recognizer_AudioLevelUpdated(object sender, AudioLevelUpdatedEventArgs e)
{
Console.WriteLine("The audio level is now: {0}.", e.AudioLevel);
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result != null && e.Result.Text != null)
{
Console.WriteLine(" Recognized text = {0}", e.Result.Text);
}
else
{
Console.WriteLine(" Recognized text not available.");
}
}
// Handle the RecognizeCompleted event.
static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
{
if (e.Error != null)
{
Console.WriteLine(" Error encountered, {0}: {1}",
e.Error.GetType().Name, e.Error.Message);
}
if (e.Cancelled)
{
Console.WriteLine(" Operation cancelled.");
}
if (e.InputStreamEnded)
{
Console.WriteLine(" End of stream encountered.");
}
completed = true;
}
}
}
测试结果为(在控制台中):
实际内容是什么:
-你好,文森特。
-你好,鲍里斯。
-你好吗?
-我很好。
-你今天打算做什么?
-我要看电视,吃晚饭,然后回家。
-谢谢,祝你今天愉快。
-没问题。System.Speech.Recognition启用默认的windows语音识别。它是为单个用户设计的,用户可以通过windows语音识别培训对其进行培训
您可能需要的是Microsoft.Speech.Recognition库,它专为低质量音频设计。它的工作原理几乎相同,但是,它不是为听写而设计的。它更适用于检测来自电话质量音频的命令。如果您想试一试,我在这里找到的最新版本是:这是System.Speech.Recognition.SpeechRecognitionEngine还是Microsoft.Speech.Recognition.SpeechRecognition?使用System.Speech.Recognition;这是名字空间。非常感谢凯兰健!所以它可以检测关键字而不是长时间的对话,对吗?如果是这样的话,我应该如何实现这样一个函数,我还可以使用哪些库来提供更准确的解释?我想使用谷歌语音识别API,但似乎受到限制。这是我第一次尝试做这样的功能,请指教。很高兴能帮忙!不幸的是,我只能帮你这么多。我只知道这一点,因为我使用Windows语音识别为自己制作了一个小的语音项目。我确实找到了另一个可能对您有帮助的堆栈溢出答案:。祝你好运
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
public class SpeechReconizer
{
SpeechRecognitionEngine _speechRecognitionEngine;
public SpeechReconitionResult ReadResult { get; set; }
public SpeechReconizer()
{
Grammar dictation = new DictationGrammar();
dictation.Name = "Dictation Grammar";
_speechRecognitionEngine = new SpeechRecognitionEngine();
_speechRecognitionEngine.SetInputToDefaultAudioDevice();
_speechRecognitionEngine.LoadGrammar(dictation);
_speechRecognitionEngine.InitialSilenceTimeout = TimeSpan.FromSeconds(3);
_speechRecognitionEngine.BabbleTimeout = TimeSpan.FromSeconds(2);
_speechRecognitionEngine.EndSilenceTimeout = TimeSpan.FromSeconds(1);
_speechRecognitionEngine.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.5);
_speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
_speechRecognitionEngine.SpeechRecognized += RecognizerSpeechRecognized;
_speechRecognitionEngine.RecognizeCompleted += RecognizerRecognizeCompleted;
}
public SpeechReconitionResult ReadSpeech(string sourceAudio)
{
ReadResult = new SpeechReconitionResult();
_speechRecognitionEngine.SetInputToWaveFile(sourceAudio);
_speechRecognitionEngine.Recognize();
return ReadResult;
}
private void RecognizerSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result != null && e.Result.Text != null)
{
ReadResult.Success = true;
ReadResult.Text = e.Result.Text;
}
else
{
ReadResult.Text = "Recognized text not available.";
}
}
private void RecognizerRecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
{
if (e.Error != null)
{
ReadResult.Success = false;
ReadResult.ErrorMessage = string.Format("{0}: {1}",
e.Error.GetType().Name, e.Error.Message);
}
if (e.Cancelled)
{
ReadResult.Success = false;
ReadResult.ErrorMessage = "Operation cancelled.";
}
}
}
public class SpeechReconitionResult
{
public string Text { get; set; }
public bool Success { get; set; }
public string ErrorMessage { get; set; }
public bool Complete { get; set; }
}
Starting asynchronous recognition...
Recognized text = Helence and the globe or east
Recognized text = alarmed
Recognized text = and client thanks
Recognized text = what aren't going to do and that they
Recognized text = aren't goint to rule
Recognized text = working to dear E
Recognized text = N
Recognized text = at dinner
Recognized text = and
Recognized text = that going there
Recognized text = and you have a 98 no problem bars
End of stream encountered.