Utilisation de l’API Google Speech

Quel est le code pour implémenter l’API Google Speech dans mon application basée sur C #? J’ai découvert qu’il était possible de créer un fichier audio et je l’ai envoyé à http://slides.html5rocks.com/#speech-input et le recevoir sous forme de texte. Pourriez-vous s’il vous plaît expliquer comment faire cela ou me fournir le code si vous l’avez déjà essayé? Été coincé ici depuis un moment

Très appréciée.

Code jusqu’ici:

SpeechRecognitionEngine rec = new SpeechRecognitionEngine(); SpeechSynthesizer dummy = new SpeechSynthesizer(); public Form1() { InitializeComponent(); Choices searching = new Choices("Porsche"); GrammarBuilder searchService = new GrammarBuilder("Search"); searchService.Append(searching); // Create a Grammar object from the GrammarBuilder and load it to the recognizer. Grammar googleGrammar = new Grammar(searchService); ; rec.RequestRecognizerUpdate(); rec.LoadGrammar(googleGrammar); // Add a handler for the speech recognized event. rec.SpeechRecognized += new EventHandler(_recognizer_SpeechRecognized); // Configure the input to the speech recognizer. rec.SetInputToDefaultAudioDevice(); // Start asynchronous, continuous speech recognition. rec.RecognizeAsync(RecognizeMode.Multiple); } private void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { try { FileStream FS_Audiofile = new FileStream("temp.flac", FileMode.Open, FileAccess.Read); BinaryReader BR_Audiofile = new BinaryReader(FS_Audiofile); byte[] BA_AudioFile = BR_Audiofile.ReadBytes((Int32)FS_Audiofile.Length); FS_Audiofile.Close(); BR_Audiofile.Close(); HttpWebRequest _HWR_SpeechToText = null; _HWR_SpeechToText = (HttpWebRequest)WebRequest.Create("http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=de-DE&maxresults=1&pfilter=0"); _HWR_SpeechToText.Method = "POST"; _HWR_SpeechToText.ContentType = "audio/x-flac; rate=44100"; _HWR_SpeechToText.ContentLength = BA_AudioFile.Length; _HWR_SpeechToText.GetRequestStream().Write(BA_AudioFile, 0, BA_AudioFile.Length); HttpWebResponse HWR_Response = (HttpWebResponse)_HWR_SpeechToText.GetResponse(); if (HWR_Response.StatusCode == HttpStatusCode.OK) { StreamReader SR_Response = new StreamReader(HWR_Response.GetResponseStream()); textBox1.Text = SR_Response.ToSsortingng(); } } catch (Exception ex) { } } 

Cela ne renvoie aucune valeur de Google.

Ce qui suit fonctionne en boucle tant que le fichier envoyé n’est pas trop long … moins de 5 secondes.

curl -X POST -H “Content-Type: audio / x-flac; rate = 16000″ \ -T seg_1.flac ” https://www.google.com/speech-api/v1/recognize ? \ xjerr = 1 & client = speech2text & maxresults = 1 & lang = en-US & key = … 48593 ”

{“status”: 0, “id”: “”, “hypotheses”: [{“énoncé”: “maintenant c’était le passe-temps favori”, “confidence”: 0.95148802}]}}

Donc, encodez en speechX ou flac

inclure un paramètre avec votre taux d’échantillonnage de l’enregistrement

inclure votre clé

garder le fichier de courte durée (vous devrez diviser les fichiers avant l’access à l’API)

Le stream de fichiers FS_Audiofile que vous envoyez à Google est vide, c’est pourquoi vous ne recevez rien en retour.

Vous manquez cet appel:

 recognizedAudio.WriteToAudioStream(FS_Audiofile);