我尝试通过桌面应用程序使用 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.
(用谷歌翻译)
byte[] bytes- 是:
var audioBytes = File.ReadAllBytes(@"file.wav");
俄语PS文档