Dictaphone android

I want to create a voice recorder application in Android 3.0. The script, when I click the record button, should start recording, and when I click the stop button, it should stop recording.

After recording the voice, I want to play the recorded sound when I press the play button. and he should stop playing when I click the stop playing button. I tried the code for voice recording. but it saves the file in 3gpp format. therefore, it cannot be played on ma. so I tried changing the outputformat to "AMR_NB". but it crashes when I press the stop button. can anyone provide the code, otherwise plz will help me make it work by editing my code. This is my helper class ...

 public class AudioRecorder { final MediaRecorder recorder = new MediaRecorder(); final String path; /** * Creates a new audio recording at the given path (relative to root of SD card). */ public AudioRecorder(String path) { this.path = sanitizePath(path); } private String sanitizePath(String path) { if (!path.startsWith("/")) { path = "/" + path; } if (!path.contains(".")) { path += ".3gp"; } return Environment.getExternalStorageDirectory().getAbsolutePath() + 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 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.AMR_NB); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); recorder.start(); } /** * Stops a recording that has been previously started. */ public void stop() throws IOException { recorder.stop(); recorder.release(); } } 

and this is my activity class

 public class audiorecording extends Activity { private Button start; private Button stop; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); start=(Button)findViewById(R.id.start); stop=(Button)findViewById(R.id.stop); final AudioRecorder recorder = new AudioRecorder("/audiometer/temp"); start.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { recorder.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }) ; //….wait a while stop.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { recorder.stop(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }) ; } } 
+4
source share
2 answers

You can use setOutputFormat (int output_format)

Sets the format of the output file created during recording. Call it after setAudioSource () / setVideoSource (), but before preparing (). It is always recommended that you use the 3GP format when using the H.263 video encoder and AMR audio encoder. Using the MPEG-4 container format may confuse some desktop players.


Audalyzer Audio Analyzer for Android

This is a simple audio analysis for Android. It displays the sound of the microphone in a waveform display, as a frequency spectrum, and as a dB meter. dB relative to the maximum input level of your device.


Android MediaRecorder

A common case of using MediaRecorder to record audio works as follows:

 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 
+2
source

Put android.permission.RECORD_AUDIO

 android.permission.WRITE_EXTERNAL_STORAGE 

in the manifest? ...

+2
source

All Articles