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.
Related
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.
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.
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.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
MediaRecorder: setCamera() - error camera is not aviable
I am making an application that allows a user to record audio and save it somewhere in the SD card. I am using a MediaRecorder to do record the audio.
I am reusing some of the code from the androiddevblog website as it was recommended by another user on stackoverflow to check those tutorials.
My problem is whenever I click the button to record audio I get an error saying "Your Application has been forced to stop". I have posted my code for the recording feature below.
EDIT: I solved my original problem. Now when I add recorder.stop() to my code I get an illegalStateException. I have updated the code below as well(The only changes are in the startRecorder method). Any ideas ?
I am aware that nothing will get recorded based on my code. I want to first make sure the file gets created and saved.
public class MyRecorderActivity extends Activity{
private Button audio;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questionandanswer);
....
....
audio = (Button) findViewById(R.id.audio_recordactivity);
audio.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startRecording();
}
});
}
private String getFilename(){
String filepath = Environment.getExternalStorageDirectory().getPath();
File file = new File(filepath,AUDIO_RECORDER_FOLDER);
if(!file.exists()){
file.mkdirs();
}
return (file.getAbsolutePath() + "/");
}
private void startRecording(){
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.stop();
recorder.reset();
recorder.release();
}
}
I solved my problem. I forgot to add the permissions!
I'm developing an android application that records sound using Mediarecorder class
The following is a part from my code:
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
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
try {
recorder.setOutputFile(path);
} catch (IllegalStateException e) {
e.printStackTrace();
}
recorder.prepare();
recorder.start();
}
when the recorder stops , i played it using mediaplayer class but the result sound is very thick and slow .. what could be the problem?
As per the MediaRecorder documentation the sampling rate for AMRNB is 8kHZ and you are setting this to a different value. I suspect this as the issue.
Can you comment these lines and check if that works for you:
//recorder.setAudioEncodingBitRate(16);
//recorder.setAudioSamplingRate(44100);