MediaRecorder.AudioSource.VOICE_CALL not working - android

I am going to create a program that recording voice call but MediaRecorder.AudioSource.VOICE_CALL does not work. I think its not support on many phones.
I'm trying with MediaRecorder.AudioSource.MIC but it just records and upload voice. In another word record my voice on microphone!!!
And I'm trying with MediaRecorder.AudioSource.VOICE_COMMUNICATION but it has a bad sound.
Here is my sample code:
recorder = new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setOutputFile(mFileName);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
} catch (IOException e) {
Log.e("LOG", "prepare() failed");
}
recorder.start();
Please help me. Thank you.

Related

How to get the time of each audio sample

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.

Android, MediaRecorder to 3gp container video fails

I am facing a problem recording a video with MediaRecorder. I need to register a video in H264 and save it in a 3gp container with extension mp4. I absolutely need this video format, because then I will open it with a native library that I can't directly modify for my own. I am using the following code, that normally works well. But with another tablet, the video is taken, but the format isn't the same (and the native library stops to work).
Inspecting the video proprieties I saw that the second video has a container "Quicktime" instead of "3gp":
And analysing the video's bytes, I found that the header isn't the 3gp's one.
What's wrong in the code?
recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoSize(320, 240);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recordingPath = getApplicationContext().getFilesDir().getAbsolutePath()
+ "/" + System.currentMillis();
recorder.setOutputFile(recordingPath + ".mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
recorder.setPreviewDisplay(recPreview.getHolder().getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
it seems like the recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); doesn't take effect
Thanks, Nico

Add effects (chaging pitch, frequency) and save audio to sdcard

I am trying to add effect in audio, I have recorded audio using MediaRecorder and added effects using SoundPool class now I am trying to save the effected sound but I found that sound i can't store a sound using SoundPool. Can any one please give a way to move on I am posting my code that records the sound and play it ...
Thanks in advance
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(getFilePath() + getFilename());
try {
mediaRecorder.prepare();
mediaRecorder.start();
setFlagRecording(true);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
and to play sound
soundPool.play(getStreamID(), 1, 1, 0, 0, getFrequency());

Android Media Recorder - Record Audio in Pieces

I have an app that encodes in amr_nb format and output the file in amr. I want the recorded file to be broken into a series of amr files of 2 KB each. Got no clue on how to achieve this.
Here is the function called upon clicking Record Button
private void startRecording() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Here is the method called upon clicking Stop Button,
private void stopRecording() {
if (null != recorder) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
}
http://developer.android.com/reference/android/media/MediaRecorder.html#setMaxFileSize(long)
Then register your listener to MediaRecorder that gets a callback when the max file size is reached, then set up MediaRecorder to record the next file. Be aware there's a (good?) chance this will not produce a series of gapless files.

MediaRecorder not recording audio

I am tried to record audio using MediaRecorder:
MediaRecorder recorder= new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);//
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.setMaxDuration(30*60*1000);
recorder.prepare();
recorder.start();
Code works fine no exception occur at run time, some times file not created on SDCard if file will create then file size is 0KB.
I have also register Error and Info listeners OnInfoListener OnErrorListener in
OnInfoListener public void onInfo(MediaRecorder mr, int what, int extra) returns what=802 and extra=6
I have tried this code on real device but not works.
try this its working for me:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
Here is an excellent reference for MediaRecorder to capture media.
http://developer.android.com/guide/topics/media/audio-capture.html
The sample code used in the tutorial works without any changes.
(Just make sure you added the necessary permissions in the manifest file)
You can try this:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e("start", "prepare() failed");
}
mRecorder.start();
if you getting any error then please paste logcat.

Categories

Resources