Created
May 12, 2014 13:51
-
-
Save tabbakka-developer/75e639434b66e6c62e18 to your computer and use it in GitHub Desktop.
Google Speech To Text C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace GoogleSpeechToTextLib | |
| { | |
| public class GoogleVoice | |
| { | |
| public static string ACCESS_GOOGLE_SPEECH_KEY = "AIzaSyDC8nM1S0cLpXvRc8TXrDoey-tqQsoBGnM"; | |
| public static string TEST_NEW_PATH_2014_PART = | |
| "https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key="; | |
| public static string NOT_MY_KEY = "AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4"; | |
| public static String GoogleSpeechRequest(String flacName, int sampleRate) | |
| { | |
| PATH = TEST_NEW_PATH_2014_PART + ACCESS_GOOGLE_SPEECH_KEY; | |
| HttpWebRequest request =(HttpWebRequest) HttpWebRequest.Create(PATH); | |
| request.Method = "POST"; | |
| byte[] byteArray = File.ReadAllBytes(flacName); | |
| sampleRate = 44100; | |
| request.ContentType = "audio/x-flac; rate=" + sampleRate.ToString(); | |
| request.ContentLength = byteArray.Length; | |
| Stream sendStream = request.GetRequestStream(); | |
| sendStream.Write(byteArray,0,byteArray.Length); | |
| sendStream.Close(); | |
| string responseFromServer; | |
| HttpWebResponse response = (HttpWebResponse) request.GetResponse(); | |
| var reader = new StreamReader(response.GetResponseStream()); | |
| responseFromServer = reader.ReadToEnd(); | |
| reader.Close(); | |
| response.Close(); | |
| return responseFromServer; | |
| } | |
| } | |
| } |
I am getting this error " Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host." on following line " sendStream.Write(byteArray, 0, byteArray.Length);"
is this working at your end?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i get ("result : [] )
I don't get the second line, how did you get the second line? (i used the same code)