【发布时间】:2016-03-11 10:12:51
【问题描述】:
我正在实现 C# 代码,我试图在其中转录超过 100 mb 的音频,但它不允许我开发需要可以在 C# 中发送超过 100 mb 音频的程序
在这段代码中,我使用的是网络套接字,但我如何像流式传输音频一样发送
public static void CallWatson()
{
using (var nf = new Notifier())
using (var ws = new WebSocket("wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=""))
{
string startActionjson = "{\"action\": \"start\", \"content-type\": \"audio/wav\", \"continuous\" : true, \"interim_results\": true}";
ws.OnOpen += (sender, e) => ws.Send(startActionjson);
// Set the WebSocket events.
string result = string.Empty;
ws.OnMessage += Ws_OnMessage;
ws.OnError += (sender, e) =>
nf.Notify(
new NotificationMessage
{
Summary = "WebSocket Error",
Body = e.Message,
Icon = "notification-message-im"
});
ws.OnClose += (sender, e) =>
nf.Notify(
new NotificationMessage
{
Summary = String.Format("WebSocket Close ({0})", e.Code),
Body = e.Reason,
Icon = "notification-message-im"
});
ws.Connect();
//ws.SendAsync(startActionjson, b =>
//{
// if (b == true)
// {
// //send the audio as binary
// string filePath = "E:\\test33.wav";
// byte[] bytes = System.IO.File.ReadAllBytes(filePath);
// ws.SendAsync(bytes, b1 =>
// {
// if (b1)
// ws.Close();
// });
// // result+=result+ws.
// }
//});
// Connect to the server asynchronously.
//ws.ConnectAsync ();
//Console.WriteLine("\nType 'exit' to exit.\n");
string filePath = "E:\\Test3.wav";
byte[] bytes = System.IO.File.ReadAllBytes(filePath);
while (true)
{
Thread.Sleep(3000);
ws.SendAsync(bytes, b1 =>
{
if (b1)
ws.Close();
});
}
//for (int i = 0; i < bytes.Length; i += 1000000)
//{
// Thread.Sleep(1000);
// byte[] buffer = new byte[1000000];
// Buffer.BlockCopy(bytes, i, buffer, 0, 128);
// // ws.Send(buffer);
// ws.SendAsync(buffer, b1 =>
// {
// if (b1)
// ws.Close();
// });
//}
}
}
private static void Ws_OnMessage(object sender, MessageEventArgs e)
{
string s = e.Data;
}
【问题讨论】:
-
请至少分享您的代码。
-
您尝试了什么 - 请发布代码!您具体收到了什么错误?
-
我atteched代码......也帮助我正确纠正结果
标签: c# asp.net speech-to-text ibm-watson