Speech Recognition

viktor80

New member
Joined
Aug 18, 2016
Messages
2
Programming Experience
Beginner
hello,

it seemed to me the most appropriate section, but still I'm not sure, if this is a right place to post this question...

I'm trying to find free and useful speech recognition for C# Windows Form Application. I've tried System.Speech.Recognition; but if phrase or word is not pre-recorded and I want use DictationGrammar sometimes I have to say 20 times same phrase or word, but 20 times I have wrong recognition results. So I do not mean that it does not work well, but it doesn't work for my case. So if I can somehow to make it work better, need your help here:

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();
    
        }
    
    }
I have tried before Google Speech Recognition with Python and it was 95% correct at least, more then enough to say, that for me this is enough, but apparently if I do not have a key it is not available for free:

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

Says that API keys are only for Chromium development and not to ask questions on this list https://www.chromium.org/developers/how-tos/api-keys Maybe there is some other way to use it:

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(
                                    "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();
            }
        }
    }

Also I tried to use Bing Speech API, but seems it's only for use in XAML apps here http://msdn.microsoft.com/en-us/library/dn434606.aspx and http://msdn.microsoft.com/en-us/library/dn467592.aspx
then I found this list of tools, but seems like is nothing for free DMOZ - Computers: Speech Technology: Toolkits
 
Back
Top Bottom