android - 使用MediaRecorder在Android上录制声音

标签 android audio recorder

我正在开发一个使用AudioRecorder类录制声音的android应用程序
以下是我的代码:

  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);
System.out.println("mashi");
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
try {
    recorder.setOutputFile(path);
    System.out.println("ooutput");
} catch (IllegalStateException e) {
    e.printStackTrace();
}
recorder.prepare();
recorder.start();

}

录制的声音很慢很浓!
问题是什么?

最佳答案

将recorder.setAudioSamplingRate(44100)更改为recorder.setAudioSamplingRate(8000);在模拟器中,因为它需要 8000采样率才多于此。

关于android - 使用MediaRecorder在Android上录制声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9966464/

相关文章:

Android studio 按钮没有做任何事情真的很困惑

Android NDK 段错误

audio - 我可以提供给 PCM 缓冲区的最少(可管理)样本量是多少?

flutter - flutter 的文件播放列表

javascript - 如何用javascript在手机网页上录制音频和播放音乐?

android - 同时录制音频和播放音频

android - 无法解析符号 '@style/Widget.Design.CoordinatorLayout'

android - 设备文件资源管理器和数据库修改时间

android - 从 AudioRecord 计算耗时