如何在android中记录和保存内部存储器中的声音文件 [英] How to record and save sound files in internal memory in android

查看:82
本文介绍了如何在android中记录和保存内部存储器中的声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我需要记录用户语音并将其保存到设备的内部存储中,虽然我已经阅读了很多文章,但它们都没有达到要点

所以请帮助我实现这个目标,任何帮助都是适用的。

以下是用于录制用户语音的代码



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

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();
           
        }

推荐答案

好吧我在一点R& D之后解决了我的问题并发布了解决方案在这里它可以帮助像我这样的人....



//获取存储路径

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
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();
	}


这篇关于如何在android中记录和保存内部存储器中的声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆