so from my understanding is that the mediarecorder saves audio samples and binds them with a timeStamp to be able to seek through the audio file later (by the help of a prgressbar):
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(fileName);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
recorder.start();
My question
Is there any way to get these timestamps of audio samples real time while recording a voice?
please I need your help.
In android is it possible to record voice call during incoming/outgoing calls without open the speaker of mobile. I had seen a application in the android market. It does not correctly record other side voice without opening the speaker because it uses mic for recording purpose. May it be done by some other techniques?
final MediaRecorder callrecorder = new MediaRecorder();
callrecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
callrecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
callrecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
callrecorder.setOutputFile(recordPath);
callrecorder.prepare();
callrecorder.start();
Setting the audio source to MIC worked for me..
CallRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
But not all devices provide the hardware support for call recording. Refer this [link]: http://forum.xda-developers.com/showthread.php?t=926498.
The outcome was that in some phones both the caller and callee's voice got recorded whereas in others only the speaker's voice was recorded.
Android phones (to my knowledge) have an application processor and a modem processor. When the phone is in a voice call, audio data is routed (unless there is a HW change) from the modem processor to the audio hardware directly. The application processor is blissfully unaware of the audio data, but only knows of the call status.
So, in short you will not be able to record the audio data without the appropriate HW support.
You can check with both audio source MediaRecorder.AudioSource.VOICE_DOWNLINK & MediaRecorder.AudioSource.VOICE_UPLINK at time.
This solution worked for me.
Callrecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK);
You can use MediaRecorder class as follows:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Log.d(TAGS, "In M" + "In M");
Toast.makeText(this, "6.0", Toast.LENGTH_SHORT).show();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.d(TAGS, "NNNN" + "NNNN");
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
Log.d(TAGS, "N_MR1" + "N_MR1");
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.d(TAGS, "O" + "O");
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else {
Log.d(TAGS, "ELSE" + "ELSE ");
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
}
You need use MediaRecorder class as follows,
recorder = new MediaRecorder();
int audioSource = MediaRecorder.AudioSource.VOICE_CALL;
recorder.setAudioSource(audioSource);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
final String filePath = Environment.getExternalStorageDirectory() + "/record.3gpp";
final File file = new File(filePath);
file.getParentFile().mkdirs();
recorder.setOutputFile(filePath);
recorder.prepare();
recorder.start(); // Recording is now started
Can anyone please explain how to store the recorded Audio files in a separate folder?
I am using default recorder for recording audio files
Intent = new Intent (MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, 2);
and I am getting the absolute audio path:
absolutepath audiopath is : /mnt/sdcard/recording1225555579.3gpp
You can try by specifying the path yourself.
private void beginrec() throws IllegalStateException, IOException{
ditchMediaRecorder();
recorder=new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/sdcard/voice/"); //like this
recorder.prepare();
recorder.start();
}
Hi
I am making an Android app for recording a audio for 5-10 sec and store that in Database.
For audio recording i follow this http://xhampa.pastebin.com/Yr2hie6q
But it is not working properly. What to do ?
I can not record the Audio on my G1 mobile.
Any suggestion welcome.
For your audio recording, try this code:
MediaRecorder recorder;
public void startRecording() throws IOException
{
SimpleDateFormat timeStampFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH.mm.ss");
String fileName = "audio_" + timeStampFormat.format(new Date())
+ ".mp4";
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/sdcard/"+fileName);
recorder.prepare();
recorder.start();
}
protected void stopRecording() {
recorder.stop();
recorder.release();
}
You can find your file on your sdcard.
I found the code to record audio, but I always get:
The method setOutputFile(FileDescriptor) in the type MediaRecorder is not applicable for the arguments (Uri)
So how would I need to describe the filepath that it works?
// Prepare recorder source and type
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
// File to which audio should be recorded
File outputFile = getFileStreamPath("output.amr");
Uri target = Uri.parse(outputFile.getAbsolutePath());
recorder.setOutputFile(target);
// Get ready!
recorder.prepare();
// Start recording
recorder.start();
// Stop and tidy up
recorder.stop();
recorder.release();
You're trying to pass in an Uri as parameter to the method which doesn't expect that.
Just replace recorder.setOutputFile(target) with:
recorder.setOutputFile(outputFile.getAbsolutePath());
That should work since string parameter is allowed.