简体   繁体   English

C#Google Speech API v2返回空字符串

[英]C# Google Speech api v2 returning empty string

I had the google speech v2 API working perfectly fine about a week ago and it was returning results with no problems however testing it today with the same .flac file keeps returning "{\\"result\\":[]}" no matter what I try. 大约一周前,我使Google Speech v2 API正常运行,并且返回的结果没有问题,但是今天使用相同的.flac文件对其进行测试,无论我做什么,它都始终返回“ {\\“ result \\”:[]}“尝试。 Wondering if A) Anyone else is having this problem or B) Anyone has a solution to my problem my code is below thanks! 想知道是否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";
        }


    }

The requirements for the sound file have changed. 声音文件的要求已更改。 It should be a MONO Flac file at 16000 rate 它应该是速率为16000的MONO Flac文件

A) Anyone else is having this problem A)其他人有这个问题

Sure, Google impose usage limits on the API which makes it less practical than you might think. 当然,Google对API施加了使用限制,这使其实用性超出了您的想象。

or B) Anyone has a solution to my problem my code is below thanks! 或B)任何人都可以解决我的问题,谢谢!

Use other API's, there are many of them. 使用其他API,其中有很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM