Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing an application where i need to record user voice and save it into internal storage of the device,though i have gone-through many article but none of them are to the point
so please help me to achieve this,any help is appriciated.
below is the code i am using for recording user voice

C#
private void startRecording() throws IllegalStateException, IOException{
            releaseRecorder();

            if(fileWithinMyDir.exists()){
                fileWithinMyDir.delete();
                }

            recorder = new MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setOutputFile(OUTPUT_FILE);--->//Here how can i give the path for sound files
            recorder.prepare();
            recorder.start();
           
        }
Posted

1 solution

ok i have myself solved my problem after a little R&D and posting the solution here so that it could help somebody like me....

//getting path for storage
XML
File audioFile = context.getCacheDir();
        OUTPUT_FILE =audioFile.getPath()+"/"+"myAudioFile.3gp";

//Function for Recoding Voice
	private void startRecording() throws IllegalStateException, IOException{ 
		
		recorder = new MediaRecorder();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
		recorder.setOutputFile(OUTPUT_FILE);
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        try {
        	recorder.prepare();
        } catch (IOException e) {
            Log.e("development", "prepare() failed");
        }

        recorder.start();
	}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900