安卓:录音和保存音频 [英] Android: Voice Recording and saving audio

查看:265
本文介绍了安卓:录音和保存音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的应用程序,它会记录用户的声音,并保存在SD卡上的文件,然后让用户再次收听音频。

我能够让用户记录使用RecognizerIntent他的声音,但我不知道如何保存音频文件,并允许用户听到的声音。我想AP preciate,如果有人可以帮助我。我已经显示我的code如下:

  //设置的onClickListener音频按钮
    attachVoice =(按钮)findViewById(R.id.AttachVoice_questionandanswer);
    attachVoice.setOnClickListener(新OnClickListener(){
        公共无效的onClick(视图v){
        意图voiceIntent =新的意图(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT,请讲);
        startActivityForResult(voiceIntent,VOICE_REQUEST);
        }
    });

保护无效onActivityResult(INT申请code,INT结果code,意图数据){


  如果(要求code == VOICE_REQUEST和放大器;&安培;结果code == RESULT_OK){




}
 

解决方案

还有就是如何在的 Android的开发者文档。

我会建议节省SD卡中的文件,然后让您的画廊code。检查SD卡,看看哪些文件显示。您可以使用获得SD卡的目录中的<一个href="http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29"相对=nofollow> Environment.getExternalStorageDirectory()方法。这将是最好的保存在SD卡根目录下的子目录文件。

请确保你给你的应用程序权限它会需要。至少,它需要 RECORD_AUDIO 和<一href="http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE"相对=nofollow> WRITE_EXTERNAL_STORAG​​E 。

另外,你必须看到这些教程:

http://www.androiddevblog.net/android/android-音频录音的部分-1

http://www.androiddevblog.net/android/android-音频录音的部分-2

I am working on application that will record the voice of the user and save the file on the SD card and then allow the user to listen to the audio again.

I am able to allow the user to record his voice using the RecognizerIntent, but I cant figure out how to save the audio file and allow the user to hear the audio. I would appreciate it if someone could help me out. I have displayed my code below:

    // 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){




}

解决方案

There is an example of how to do audio capture using MediaRecorder in the Android Developer Documentation.

I would recommend saving the files on the SD Card and then have your gallery code check the SD card to see which files to display. You can get the directory of the SD Card using the Environment.getExternalStorageDirectory() method. It would be best to save your files in a subdirectory of the SD Card root directory.

Make sure you give your applications the Permissions it will need. At the very least it will need RECORD_AUDIO and WRITE_EXTERNAL_STORAGE.

Also you have to see these tutorials:

http://www.androiddevblog.net/android/android-audio-recording-part-1

http://www.androiddevblog.net/android/android-audio-recording-part-2

这篇关于安卓:录音和保存音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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