I want to create a microphone app on Android that will receive sound through the microphone and play through the speakerphone but I don't know exactly what classes and services I should use.
            Asked
            
        
        
            Active
            
        
            Viewed 598 times
        
    -2
            
            
        - 
                    2start by breaking down your idea in sub-problems. Google the more specific questions ( eg how to use the microphone to record voice in android - https://stackoverflow.com/questions/6564495/how-to-use-the-microphone-on-android) work your project and post specific issues you've face here to get specific answers. – Nikos Hidalgo Oct 17 '19 at 11:00
1 Answers
0
            The core of your answer is to:
A) record and store, as stated here.
MediaRecorder recorder = new MediaRecorder();    
String status = Environment.getExternalStorageState();
if(status.equals("mounted")){
    String path = Environment.getExternalStorageDirectory().toString()+"/YOURFOLDER"; // your custom path
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // notice that this is the audio format, and you might want to change it to [other available audio formats][2]
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    recorder.prepare();
    // To start recording
    recorder.start();
    // To stop recording
    recorder.stop();
    recorder.release();
} else {
    // Handle the situation
}
[Other available audio formats | 2]
B) Get recordings, as stated partially here. You should then show them.
try {
    String path = Environment.getExternalStorageDirectory().toString()+"/YOURFOLDER"; // your custom path
    File directory = new File(path);
    File[] files = directory.listFiles();
} catch {
    // Handle errors (or maybe no files in the directory)
}
C) Play recordings, as stated partially here.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(Environment.getExternalStorageDirectory().toString()+"/YOURFOLDER"+"/yourfilename.formatextension"; // your custom pathare to use the file format and directory you used when saving
mp.prepare();
mp.start();
Hope this answer helps!
 
    
    
        miquelvir
        
- 1,748
- 1
- 7
- 21
