在提出这个问题之前,我检查了所有与此问题相关的stackoverflow其他线程没有任何成功,所以请不要回答其他线程的链接,:)
我想保存/记录谷歌识别服务用于语音操作的音频(使用RecognizerIntent或SpeechRecognizer).
我经历了很多想法:
我几乎绝望,但我只是注意到Google Keep应用程序正在做我需要做的事情!我使用logcat稍微调试了keep应用程序,app也调用了"RecognizerIntent.ACTION_RECOGNIZE_SPEECH"(就像我们开发人员一样)来触发语音到文本.但是,如何继续保存音频?它可以成为隐藏的api吗?是谷歌"作弊":)?
谢谢您的帮助
最好的祝福
我正在开发一个功能,当按下按钮时,它将启动语音识别,同时记录用户说的内容.代码如下:
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 ×2