Saturday, 25 January 2020

How to get an Audio Stream from Media Recorder in android

I want to make streaming audio recorder in android. I am not sure how to fetch audio stream and how to set buffer size of audio stream.

Below is my media recorder class

public class MyMediaRecorder {

    final MediaRecorder recorder = new MediaRecorder();
    final File path;

    /**
     * Creates a new audio recording at the given path (relative to root of SD
     * card).
     */
    public MyMediaRecorder(File path) {
        this.path = path;
    }



    /**
     * Starts a new recording.
     */
    public void start() throws IOException {
        String state = android.os.Environment.getExternalStorageState();
        if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
            throw new IOException("SD Card is not mounted.  It is " + state
                    + ".");
        }

        // make sure the directory we plan to store the recording in exists


        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setOutputFile(path.getAbsolutePath());
        recorder.prepare();
        recorder.start();
    }

    /**
     * Stops a recording that has been previously started.
     */
    public void stop() throws IOException {
        recorder.stop();
        recorder.release();
    }
}

on start of recording i need to fetch a buffer size and sent it to server parallely record audio. Should I use Audio Record and Audio track instaed of Media Recorder ? Please suggest what should i do



from How to get an Audio Stream from Media Recorder in android

1 comment:

  1. As claimed by Stanford Medical, It is indeed the ONLY reason this country's women get to live 10 years more and weigh 19 kilos less than we do.

    (And by the way, it has absolutely NOTHING to do with genetics or some secret-exercise and EVERYTHING about "how" they are eating.)

    BTW, I said "HOW", not "WHAT"...

    TAP on this link to see if this quick questionnaire can help you discover your true weight loss possibility

    ReplyDelete