我正在尝试使用 ibm-watson 服务和 websocket-sharp 发送语音到文本的音频文件 (.wav)。我正在使用示例 .wav 文件在 asp.net mvc 操作中执行此操作80kb。在学习本教程时 speech-to-text/websockets .
我正在做以下事情
var ws = new WebSocket("wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=" + token);
ws.OnOpen += ws_OnOpen;
ws.OnMessage += ws_OnMessage;
ws.OnClose += ws_OnClose;
ws.OnError += ws_OnError;
ws.Connect();
string startActionjson = "{'action': 'start', 'content-type': 'audio/wav', 'continuous' : true, 'interim_results': true, 'inactivity_timeout': -1,}";
ws.SendAsync(startActionjson, b =>
{
if (b == true)
{
//send the audio as binary
string filePath = "E:\\Test Folders\\Sample\\test003.wav";
byte[] bytes = System.IO.File.ReadAllBytes(filePath);
ws.SendAsync(bytes, b1 =>
{
if(b1)
ws.Close();
});
}
});
发送启动操作后,我的 websocket 的就绪状态保持打开状态,但是一旦执行发送字节的行,我就会在我的 OnMessage 事件中收到以下信息
{
"name": "error",
"error": "Expecting property name: line 1 column 2 (char 1)"
}
并且 readystate 将自身更新为“已关闭”。
我也尝试过发送 FileStream,它在 chrome 和 firefox 上都是这样做的。任何帮助或解决方案的方向都将非常感激。
谢谢
最佳答案
我找到了解决方案,但发送正确的 json 以开始操作时出现问题。我将其更新为以下内容
string startActionjson = "{\"action\": \"start\", \"content-type\": \"audio/wav\", \"continuous\" : true, \"interim_results\": true}";
尽管我尝试了我在 Json Lint 问题中发布的 json这是有效的。奇怪但仍然有效
关于c# - 使用 ibm-watson 服务 C# 的语音转文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34447057/