Developer
Developer

Reputation: 1813

Recording sounds on android using MediaRecorder

I'm developing an android application that records sound using AudioRecorder class The following is 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);
System.out.println("mashi");
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
try {
    recorder.setOutputFile(path);
    System.out.println("ooutput");
} catch (IllegalStateException e) {
    e.printStackTrace();
}
recorder.prepare();
recorder.start();

}

The recorded voice is very slow and thick !! what is the problem?

Upvotes: 0

Views: 916

Answers (1)

Rahul Baradia
Rahul Baradia

Reputation: 11961

change recorder.setAudioSamplingRate(44100) to recorder.setAudioSamplingRate(8000); coz in emulator it takes 8000 sampling rate not more then this..

Upvotes: 1

Related Questions