/** * 录音工具类 *  * @author rendongwei *  */public class RecordUtil {    private static final int SAMPLE_RATE_IN_HZ = 8000;    private MediaRecorder recorder = new MediaRecorder();    // 录音的路径    private String mPath;    public RecordUtil(String path) {        mPath = path;    }    /**     * 开始录音     *      * @throws IOException     */    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                    + ".");        }        File directory = new File(mPath).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.RAW_AMR);        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);        recorder.setAudioSamplingRate(SAMPLE_RATE_IN_HZ);        recorder.setOutputFile(mPath);        recorder.prepare();        recorder.start();    }    /**     * 结束录音     *      * @throws IOException     */    public void stop() throws IOException {        recorder.stop();        recorder.release();    }    /**     * 获取录音时间     *      * @return     */    public double getAmplitude() {        if (recorder != null) {            return (recorder.getMaxAmplitude());        }        return 0;    }}

更多相关文章

  1. 安卓各文件存储路径汇总(Android file path)
  2. Android Bluetooth 文件接收路径修改方法
  3. android获取各种系统路径的方法
  4. 关于android中的各种路径对应的方法
  5. Delphi处理Android的路径信息
  6. Android根据文件路径加载指定文件
  7. android获取路径
  8. [Android] 更改关联的源码路径
  9. Android kill app Process 结束进程代码

随机推荐

  1. Android:view常用属性和操作方法
  2. Android图形绘制
  3. usb连接的PTP模式,同时显示内置、外置SD卡
  4. Android初级教程理论知识(第八章网络编程
  5. Android Studio 学习笔记(1)
  6. Android Paint的使用详解
  7. android学习记录(四)管理里中基本组键
  8. Android--MapView.第一个简单的MapView
  9. [Android]http请求
  10. Android(安卓)ueventd解析