tags:

views:

341

answers:

3

Hi, i notice in the Android Default Voice Recorder that can sense how loud is your voice and show it to you in UI parameter .

Can i use this from the intent or how can i program a code that sense the loudness of the voice in Android.

A: 

For recording Android android.media.MediaRecorder can be used. All API are listed in this page http://developer.android.com/reference/android/media/MediaRecorder.html. This should solve all your issues. Sample code

 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
 ...
 while(recordingNotOver)
 {
    int lastMaxAmplitude = recorder.getMaxAmplitude();
    // you have the value here in lastMaxAmplitude, do what u want to
 }

 recorder.stop();
 recorder.reset();   // You can reuse the object by going back to setAudioSource() step
 recorder.release(); // Now the object cannot be reused
the100rabh
Thanks , i also i found this opensource project http://code.google.com/p/moonblink/wiki/Audalyzer
Fevos
A: 

Hello, I want to do an application where the user has to speak in the microphone. I want to record what the user is saying and create a file. I want to display a list with all the files I have recorded and when the user presses in one item, then play the file so the user can hear what is said in the file. Do you have any suggestions? I'm new on android and I'm completely lost. Do you have any good tutorial which I can follow? Thanks in advance

Javier
Make this a new question rather than an answer to this question.
ShadowGod
A: 

I put some code.

This is the main class.

    final AudioRecorder recorder = new AudioRecorder("/calls");
    try {
        recorder.start();
        try {
            this.wait(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        recorder.stop();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
}

And the helper class is:

public class AudioRecorder {

  final MediaRecorder recorder = new MediaRecorder();
  final String path;

  public AudioRecorder(String path) {

    this.path = sanitizePath(path);
  }

  private String sanitizePath(String path) {
    if (!path.startsWith("/")) {
      path = "/" + path;
    }
    if (!path.contains(".")) {
      path += ".3gp";
    }

//This is the command I would like to change, because I want to save the audio files in //the internal memory instead of the Sdcard

    return Environment.getDataDirectory().getAbsolutePath() + path;
  }

  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.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    recorder.prepare();
    recorder.start();
  }

  public void stop() throws IOException {
    recorder.stop();
    recorder.release();
  }
}
javier