簡體   English   中英

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

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

大約一周前,我使Google Speech v2 API正常運行,並且返回的結果沒有問題,但是今天使用相同的.flac文件對其進行測試,無論我做什么,它都始終返回“ {\\“ result \\”:[]}“嘗試。 想知道是否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";
        }


    }

聲音文件的要求已更改。 它應該是速率為16000的MONO Flac文件

A)其他人有這個問題

當然,Google對API施加了使用限制,這使其實用性超出了您的想象。

或B)任何人都可以解決我的問題,謝謝!

使用其他API,其中有很多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM