你好,我正在尝试为 C# windows 应用程序找到免费且有用的语音识别。我试过System.Speech.Recognition; 但是如果没有预先录制短语或单词并且我想使用DictationGrammar有时我必须说 20 次相同的短语或单词,但 20 次我的识别结果是错误的。所以我并不是说它不能很好地工作,但它不适用于我的情况。因此,如果我能以某种方式使其更好地工作,请在这里需要您的帮助:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Speech;
using System.Speech.Recognition;
public class Program
{
public static void Main()
{
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
Grammar dictationGrammar = new DictationGrammar();
recognizer.LoadGrammar(dictationGrammar);
try
{
recognizer.SetInputToDefaultAudioDevice();
RecognitionResult result = recognizer.Recognize();
Console.WriteLine (result.Text);
}
catch (InvalidOperationException exception)
{
Console.WriteLine (String.Format("Could not recognize input from default aduio device. Is a microphone or sound card available?\r\n{0} - {1}.", exception.Source, exception.Message));
}
finally
{
recognizer.UnloadAllGrammars();
}
Console.Read();
}
}
我在使用 Python 进行Google Speech Recognition之前尝试过,它至少正确率为 95%,足以说,这对我来说已经足够了,但显然如果我没有密钥,它就不能免费使用:
System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at GoogleRequest.Program.Main(String[] args) in C:\FOLDER\02_WORKFILE\Program.cs:line 36
说 API 密钥仅用于 Chromium 开发,而不是在此列表中提问https://www.chromium.org/developers/how-tos/api-keys也许还有其他一些使用方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
namespace GoogleRequest
{
class Program
{
static void Main(string[] args)
{
try
{
FileStream fileStream = File.OpenRead("good-morning-google.flac");
MemoryStream memoryStream = new MemoryStream();
memoryStream.SetLength(fileStream.Length);
fileStream.Read(memoryStream.GetBuffer(), 0, (int)fileStream.Length);
byte[] BA_AudioFile = memoryStream.GetBuffer();
HttpWebRequest _HWR_SpeechToText = null;
_HWR_SpeechToText =
(HttpWebRequest)HttpWebRequest.Create(
"https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=YOUR_API_KEY_HERE");
_HWR_SpeechToText.Credentials = CredentialCache.DefaultCredentials;
_HWR_SpeechToText.Method = "POST";
_HWR_SpeechToText.ContentType = "audio/x-flac; rate=44100";
_HWR_SpeechToText.ContentLength = BA_AudioFile.Length;
Stream stream = _HWR_SpeechToText.GetRequestStream();
stream.Write(BA_AudioFile, 0, BA_AudioFile.Length);
stream.Close();
HttpWebResponse HWR_Response = (HttpWebResponse)_HWR_SpeechToText.GetResponse();
if (HWR_Response.StatusCode == HttpStatusCode.OK)
{
StreamReader SR_Response = new StreamReader(HWR_Response.GetResponseStream());
Console.WriteLine(SR_Response.ReadToEnd());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
}
}
我也尝试使用 Bing Speech API,但似乎它仅用于这里的 XAML 应用程序msdn.microsoft.com/en-us/library/dn434606.aspx和msdn.microsoft.com/en-us/library/dn467592.aspx
然后我找到了这个工具列表,但似乎没有什么是免费的http://www.dmoz.org/Computers/Speech_Technology/Toolkits/