捕获音频发送到谷歌的语音识别服务器 [英] Capturing audio sent to Google's speech recognition server

查看:301
本文介绍了捕获音频发送到谷歌的语音识别服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由谷歌服务器来识别语音,我使用SpeechRecognizer类与RecognitionListener组合在斯蒂芬的<一个建议href="http://stackoverflow.com/questions/5913773/speech-to-text-on-android/5915010#5915010">answer来这个问题。此外,我试图捕捉音频信号被确认通过onBufferReceived()回调从RecognitionListener这样的:

to recognize speech by Google server, I use SpeechRecognizer class in combination with RecognitionListener as suggested in Stephan's answer to this question . In addition, I try to capture the audio signal being recognized by using onBufferReceived() callback from RecognitionListener like:

byte[] sig = new byte[500000] ;
int sigPos = 0 ;
...
public void onBufferReceived(byte[] buffer) {
  System.arraycopy(buffer, 0, sig, sigPos, buffer.length) ;
  sigPos += buffer.length ;
}
...

这似乎工作正常,当SpeechRecognizer失败连接到谷歌服务器上,当音频的块不被复制到上述 SIG 阵列,以及HTTP除连接超时异常。 SpeechRecognizer最终连接到谷歌的服务器和识别结果表示已收到了完整的音频信号;只有 SIG 阵列缺少一些音频块(S)。

This seems working fine, except when SpeechRecognizer fails connecting to the Google server, when a chunk of audio is not copied into the above-mentioned sig array, and an HTTP connection time-out exception is thrown. SpeechRecognizer eventually connects to the Google server and recognition results indicate that a complete audio signal was received; only the sig array is missing some audio chunk(s).

是否有人遇到同样的问题?任何提示的解决办法吗?谢谢!

Does anybody experience the same problem? Any hint for solution? Thank you!

推荐答案

我往往会说这可能是不一致的识别服务的行为,甚至是一个在你使用Android版本的bug。然而,文档指出,它不能保证本方法被称为因此它适合所述规范。我注意到,到目前为止如下(在Android 2.3.4):我得到的字节,而录音,但如果有例如了socketTimeout 尝试重新发送数据要经过一段时间的服务器,但没有调用 onBufferReceived 再次为相同的数据。用于测试的code是一样的对视了一眼,你已经在你的帖子链接。

I tend to say this might be a inconsistency in the behavior of the recognition service, maybe even a bug in the Android version you use. However, the documentation states, that it is not guaranteed that this method is called so it would fit into the specification. What I noticed so far is the following (on Android 2.3.4): I get the bytes while recording, but if there is for example a SocketTimeout it tries to resend the data to the server after some time, but without calling onBufferReceived again for the same data. The code used to test that was the same as the one you have linked in your posting.

为什么你认为一些块是从你的方法接收到的音频丢失?如果是只有几大块缺失,它甚至可能的情况下,该识别工作,尽管这些块不翼而飞。

Why do you think some chunks are missing from the audio you received in the method? If it were only a few chunks missing, it might even be the case, that the recognition worked although those chunks were missing.

这篇关于捕获音频发送到谷歌的语音识别服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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