【问题标题】:voice recognition and recording语音识别和录音
【发布时间】:2013-11-01 11:47:44
【问题描述】:

我在尝试设计一个可以同时录制语音并将语音转换为文本的应用程序时遇到了这个错误。我已将 Google API 用于语音识别部分,将 audioRecorder 对象用于录制目的。它没有成功,因此我转向使用 onBufferReceived() 来检索过程中的字节(当用户说话时)。 Google API 代码现在位于我的代码的 onResults() 部分,它可以在没有 UI 的情况下进行语音识别。

这是代码

class listener implements RecognitionListener          
    {

        public void onBufferReceived(byte[] buffer)
        {
            bufferBytes = buffer;
      // capturing the buffer into bufferBytes static variable as the user speaks
            try {

                bos = new BufferedOutputStream(fos);
                bos.write(buffer);

            } catch (Exception e) {
                e.printStackTrace();
            }
            finally{
                if(bos != null){
                    try{
                        bos.flush();
                        bos.close();
                    }catch(Exception e){}
                }
            }

        }
        public void onEndOfSpeech()
        {
            speakButton.setText(getString(R.string.Speak));
            Log.d(TAG, "onEndofSpeech");
        }
        public void onError(int error)
        {
            Log.d(TAG,  "error " +  error);
            mSendText.setVisibility(View.VISIBLE);
            mSendText.setText("error retriving text, please once check your Data Connection ");
        }
        public void onResults(Bundle results)                   
        {
            String str = new String();
            Log.d(TAG, "onResults " + results);
            ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            for (int i = 0; i < data.size(); i++)
            {
                Log.d(TAG, "result " + data.get(i));
                str += data.get(i);
            }
            mSendText.setVisibility(View.VISIBLE);
            mSendText.setText(data.get(0)+"");      
        }
    }

【问题讨论】:

    标签: android voice-recognition voice-recording


    【解决方案1】:

    根据comment on this similar post,最新版本的 Google 搜索应用不会调用 onBufferReceived。

    这也是我的经验,因此如果您想存储语音数据并“翻译”它,则必须使用其他语音识别提供商。

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      相关资源
      最近更新 更多