user3086759
user3086759

Reputation:

How to record sound in Android app

I'm developing an Android application, a part of this app is a simple xylophone, what i must do is the implementation of a function, that records the xylophone sounds when the user press a button.

When a user press a button, like do, re mi, etc the sounds is played using a mp3 saved in raw folder...

1) Is it possible do this ? 2) Can someone explain how i can "capture" the sound and record it in sd card? 3) Is it possible implements "record" "play" "stop" "reproduce" function ?

Upvotes: 1

Views: 9631

Answers (4)

Prachi Kumari
Prachi Kumari

Reputation: 41

You can record audio by using this code:

private void startRecording() {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(mFileName);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e(LOG_TAG, "prepare() failed");
        }

        mRecorder.start();
    }

I am searching for how to record audio with earphone, not from speakers please share link in the comment If anyone have Idea about it.

Upvotes: 3

QArea
QArea

Reputation: 4981

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(PATH_NAME);
recorder.prepare();
recorder.start(); // Recording is now started
...
recorder.stop();
recorder.reset(); // You can reuse the object by going back to setAudioSource() step
recorder.release(); // Now the object cannot be reused

Upvotes: -1

Hartmut Pfitzinger
Hartmut Pfitzinger

Reputation: 2306

Without root, Android can't record internally (or say 'digitally') what is coming out of the speaker or the headphones. The reason might be copyright issues, so that it is not possible to produce digital copies of what is played back over the Android device.

Of course, you can record it with the internal microphone(s) if the signal is loud enough, but the loss of quality is significant. Additionally, you have background noise and the tapping noise of the finger tips of the user on your xylophone.

The best solution would be that you mix the samples corresponding to the keys programmatically and send the result to the speaker and at the same time into a sound file. Complicated, but optimal.

Upvotes: 1

acid_srvnn
acid_srvnn

Reputation: 693

Yes,you can capture and store audio in sd and later play it . Check out these links .

http://developer.android.com/reference/android/media/MediaRecorder.html

http://www.tutorialspoint.com/android/android_audio_capture.htm

Upvotes: 1

Related Questions