你好,我试图为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语音识别,至少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/