1

デスクトップアプリ経由でYandex Speech APIを使用して、wavファイルを認識するリクエストをテキストに設定しようとしています。

ドキュメントからのリクエストの例:

POST /asr_xml?uuid=01ae13cb744628b58fb536d496daa1e6&key=developers-simple- key&topic=maps HTTP/1.1
Content-Type: audio/x-speex
User-Agent: Dalvik/1.2.0 (Linux; U; Android 2.2.2; LG-P990 Build/FRG83G)
Host: asr.yandex.net
Transfer-Encoding: chunked

7d0
...
chunked body

そこで、開発者フォーラムに登録し、API キーを取得して簡単なコードを書きます。

public string RecognizeSpeech(byte[] bytes, String uuid, String apiKey, string topic = "queries", string lang = "ru-RU")
    {
        try
        {
            var uri = string.Format("https://asr.yandex.net/asr_xml?" +
            "uuid={0}" +
            "&key={1}" +
            "&topic={2}" +
            "&lang={3}", uuid, apiKey, topic, lang);

            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "POST";
            request.ContentType = "audio/x-wav";//"audio/x-pcm;bit=16;rate=16000";
            request.ContentLength = bytes.Length;


            using (var stream = request.GetRequestStream())
            {
                stream.Write(bytes, 0, bytes.Length);// exception here
            }

            var response = request.GetResponse();

            var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            return reader.ReadToEnd();
        }
        catch (Exception ex)
        {
          ...
        }
        return "";
    }

audio/x-wav または audio/x-pcm;bit=16;rate=16000 を使用しようとしましたが、次のエラーが発生しました。

Unable to write data to the transport connection: remote host forcibly ripped existing connection.

(Google翻訳を使用)

byte[] バイト - は:

var audioBytes = File.ReadAllBytes(@"file.wav");

ロシア語に関するPSドキュメント

4

1 に答える 1