Speech SDK - 发送原始数据 [英] Speech SDK - Sending Raw Data

查看:75
本文介绍了Speech SDK - 发送原始数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个应用程序,它将从另一个服务接收原始音频数据并将其发送以进行识别。根据Github repo上提供的示例,我编写了以下代码。

I'm trying to create an application that's going to receive raw audio data from another service and send it for recognition. Based on the sample available on the Github repo, I've written the following code.

private static void sendFileData(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { Console.WriteLine("Setting up audio data format."); SpeechAudioFormat audioFormat = SpeechAudioFormat.create16BitPCMFormat(sampleRate); // sampleRate = 8000

asrClient.SendAudioFormat(audioFormat);

asrClient.SendAudioFormat(audioFormat);

int bytesRead = 0;
byte [] buffer = new byte [1024];

try
{
do
{
//将更多音频数据输入字节缓冲区。
bytesRead = fs.Read(buffer,0,buffer.Length);

//将音频数据发送到服务。
asrClient.SendAudio(buffer,bytesRead);
}
while(bytesRead> 0);
}
catch(exception ex)
{
Console.WriteLine(ex.Message);
}
最后
{
//我们已完成发送音频。最终识别结果将在OnResponseReceived事件调用中到达。
asrClient.EndAudio();
}
}
}

int bytesRead = 0; byte[] buffer = new byte[1024]; try { do { // Get more Audio data into byte buffer. bytesRead = fs.Read(buffer, 0, buffer.Length); // Send audio data to service. asrClient.SendAudio(buffer, bytesRead); } while (bytesRead > 0); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { // We are done sending audio. Final recognition results will arrive in OnResponseReceived event call. asrClient.EndAudio(); } } }

唯一的区别是我设置音频格式,因为它不是WAVE文件。但是,我收到的识别结果是完全错误的(我之前在REST API上测试过这个文件,它按预期工作)。此外,如果我使用相同的
代码并发送WAVE文件,我会得到正确的结果。设置音频格式时我做错了吗?是否有针对此类情况的示例代码?

The only difference is that I'm setting up the audio format, since it's not a WAVE file. However, the recognition results I receive are completely wrong (I've tested this file on the REST API before, and it worked as intended). Moreover, if I use this same code and send a WAVE file instead, I get the right result. Am I doing something wrong when setting the audio format? Is there any sample code for this kind of situation?

提前致谢!




推荐答案

我们支持16BitPCM音频格式并产生相同的结果。您确定创建的音频格式与wav文件质量相同吗?

We do support 16BitPCM Audio format and produce same result. Have you made sure the audio format created is of same quality as wav file?

谢谢

Priya,演讲PM

Priya, Speech PM


这篇关于Speech SDK - 发送原始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆