我让google speech v2 API在一周前工作得非常好并且它返回结果没有问题,但今天使用相同的.flac文件测试它仍然返回“{\”result \“:[]}”no无论我尝试什么。想知道是否 A)其他人有这个问题或 B)任何人都可以解决我的问题 我的代码谢谢!
public static String gvoice ()
{
//set the input file name
FileStream fileStream = File.OpenRead(@"test1.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;
//this points to the google speech API (key goes at end after &key=)
_HWR_SpeechToText =
(HttpWebRequest)HttpWebRequest.Create(
"https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=" + key);
_HWR_SpeechToText.Credentials = CredentialCache.DefaultCredentials;
_HWR_SpeechToText.Method = "POST";
//sets kMhz and file type (flac)
_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());
string result = SR_Response.ReadToEnd();
return result;
}
else
{
return "error";
}
}
答案 0 :(得分:1)
声音文件的要求已更改。它应该是16000速率的 MONO Flac文件
答案 1 :(得分:0)
A)其他人遇到此问题
当然,谷歌对API施加了使用限制,这使得它不如你想象的那么实用。
或B)任何人都有我的问题的解决方案我的代码在下面谢谢!
使用其他API,其中有很多。