相关疑难解决方法(0)

从语音识别意图中记录/保存音频

在提出这个问题之前,我检查了所有与此问题相关的stackoverflow其他线程没有任何成功,所以请不要回答其他线程的链接,:)

我想保存/记录谷歌识别服务用于语音操作的音频(使用RecognizerIntent或SpeechRecognizer).

我经历了很多想法:

  1. 来自RecognitionListener的onBufferReceived:我知道,这不起作用,只是测试它看看会发生什么,而onBufferReceived永远不会被调用(使用JB 4.3在galaxy nexus上测试)
  2. 使用媒体录像机:不工作.它突破了语音识别.麦克风只允许一个操作
  3. 试图找到识别服务在执行语音之前保存临时音频文件到文本api复制它的地方,但没有成功

我几乎绝望,但我只是注意到Google Keep应用程序正在做我需要做的事情!我使用logcat稍微调试了keep应用程序,app也调用了"RecognizerIntent.ACTION_RECOGNIZE_SPEECH"(就像我们开发人员一样)来触发语音到文本.但是,如何继续保存音频?它可以成为隐藏的api吗?是谷歌"作弊":)?

谢谢您的帮助

最好的祝福

android speech-recognition speech-to-text

24
推荐指数
2
解决办法
2万
查看次数

语音录制时,语音识别无法正常工作

我正在开发一个功能,当按下按钮时,它将启动语音识别,同时记录用户说的内容.代码如下:

    button_start.setOnTouchListener( new View.OnTouchListener() 
    {
        @Override
        public boolean onTouch(View arg0, MotionEvent event) 
        {   
                if (pressed == false)
                {
                    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
                    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
                    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh-HK");
                    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1); 
                    sr.startListening(intent);
                    Log.i("111111","11111111");
                    pressed = true;
                }

                recordAudio();

            }

            if((event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL))
            {                   
                stopRecording();
            }
            return false;
        }
    });             
}

   public void recordAudio()
   {
      isRecording = true;   
      try 
      {
          mediaRecorder = new MediaRecorder();
          mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          mediaRecorder.setOutputFile(audioFilePath);
          mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
          mediaRecorder.prepare();
      } 
      catch (Exception e) 
      {
          e.printStackTrace();
      }
      mediaRecorder.start();            
   }    

   public void stopRecording()
   {            
       if (isRecording) …
Run Code Online (Sandbox Code Playgroud)

android voice-recording voice-recognition mediarecorder

8
推荐指数
1
解决办法
1937
查看次数