Android. How to record the microphone over audio stream?

别等时光非礼了梦想. 提交于 2020-01-25 22:01:09

问题


In my application playing music, the user should say at this time into the microphone. Can you please tell me how to make a record? Music and top path from the microphone. I looked through MediaRecorder, but there is not, in my opinion, an appropriate recording source.


回答1:


For Recording Through Mic

Start and stop recording through Mic....

Start Recording

static MediaRecorder recorder = new MediaRecorder(); 
static String path, filename, time;
static int duration;
     public void startRecording() { 
        try {  
            recorder = new MediaRecorder();  
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);  
            recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);    
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);  
            System.currentTimeMillis();
            filename = ListenCallState.number + "_" + time + ".amr";
            File f = new File(getBaseURL());
            f.mkdirs();

            path = getBaseURL() + filename;
            recorder.setOutputFile(path);
            recorder.prepare();
            recorder.start();

        } catch (Exception {
        }
    }

Stop Recording

public static void stopRecording() {
        recorder.stop();
        recorder.release();
        try {
            MediaPlayer p = new MediaPlayer();
            p.setDataSource(path);
            p.prepare();
            duration = p.getDuration();
        } catch (Exception e) {
        }
 }


来源:https://stackoverflow.com/questions/39292272/android-how-to-record-the-microphone-over-audio-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!