语音识别

维克多80

新成员
已加入
2016年8月18日
留言内容
2
编程经验
Beginner
你好,

在我看来,这是最合适的部分,但我仍然不确定,这是否是发布此问题的合适地点...

我正在尝试为C#Windows Form Application寻找免费且有用的语音识别。我试过了 System.Speech.Recognition; 但是如果短语或单词没有预先录制,我想使用 听写语法 有时我不得不说20次相同的词组或单词,但是20次我的识别结果却不正确。因此,我并不是说它不能很好地工作,但它不适用于我的情况。因此,如果我能以某种方式使它更好地工作,请在这里需要您的帮助:

C#:
  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();
    
        }
    
    }
我以前尝试过 Google语音识别 使用Python,至少95%正确,对我来说这足够了,但是显然,如果我没有密钥,它就不是免费提供的:

C#:
    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开发,而不要在此列表中提问 //www.chromium.org/developers/how-tos/api-keys 也许还有其他使用方式:

C#:
   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(
                                    "//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();
            }
        }
    }

我也尝试使用 必应语音API,但似乎仅用于此处的XAML应用 http://msdn.microsoft.com/en-us/library/dn434606.aspxhttp://msdn.microsoft.com/en-us/library/dn467592.aspx
然后我找到了这个工具列表,但是好像没有什么免费的 DMOZ-计算机:语音技术:工具箱
 
最佳 底部