And*_*v93 9 android voice-recognition android-intent android-mediaplayer android-audiomanager
我正在开发应用程序,它将记录用户的声音并将文件保存在SD卡上,然后允许用户再次收听音频.
我能够允许用户使用RecognizerIntent录制他的声音,但我无法弄清楚如何保存音频文件并允许用户听到音频.如果有人可以帮助我,我将不胜感激.我在下面显示了我的代码:
// Setting up the onClickListener for Audio Button
attachVoice = (Button) findViewById(R.id.AttachVoice_questionandanswer);
attachVoice.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Please Speak");
startActivityForResult(voiceIntent, VOICE_REQUEST);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == VOICE_REQUEST && resultCode == RESULT_OK){
}
Run Code Online (Sandbox Code Playgroud)
有一个如何使用Android开发者文档中的MediaRecorder进行音频捕获的示例.
我建议将文件保存在SD卡上,然后让您的图库代码检查SD卡以查看要显示的文件.您可以使用Environment.getExternalStorageDirectory()方法获取SD卡的目录.最好将文件保存在SD卡根目录的子目录中.
确保为应用程序提供所需的权限.至少它需要RECORD_AUDIO和WRITE_EXTERNAL_STORAGE.
你还必须看到这些教程:
http://www.androiddevblog.net/android/android-audio-recording-part-1
http://www.androiddevblog.net/android/android-audio-recording-part-2
| 归档时间: |
|
| 查看次数: |
25355 次 |
| 最近记录: |