API клиента googlr речи возвращает пустой результат - PullRequest
0 голосов
/ 31 августа 2018

Я пытаюсь реализовать преобразование речи в текст с помощью клиентской библиотеки Google речь в .net. Я пытался работать с библиотекой с помощью файла .raw (который нормально работает на медиаплеерах, но API Google возвращает пустой результат.

Может кто-нибудь сказать мне, если я что-то упустил. Вот мой код

private string GetSpeechToText()
    {
        string result = string.Empty;

        try
        {
            SpeechClient speechClient = SpeechClient.Create();

            RecognitionConfig config = new RecognitionConfig()
            {
                Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
                SampleRateHertz = 16000,
                LanguageCode = "en-US",
            };

            RecognizeResponse response = speechClient.Recognize(config,
                RecognitionAudio.FromFile(fileName));

            foreach (var responseResult in response.Results)
            {
                foreach (var alternative in responseResult.Alternatives)
                {
                    result += alternative.Transcript;
                }
            }
        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex.Message);
            return result;
        }

        return result;
    }
...