AudioRecorder.getMinBufferSize() 返回 -2

发布于 12-10 18:19 字数 441 浏览 1 评论 0原文

当我在 AudioRecorder 类中运行 getMinBufferSize() 方法时,该方法总是返回 -2。即使我更改采样率、编码方法和通道号。我已经尝试了所有可能的组合,但它仍然返回-2。我知道 RecordAudio 具有权限。如果我注释掉 getMinBufferSize 行,并将 minBuffer 设为 4096,音频录音机将初始化并录制。仅当我将采样率设置为 8000 并且录音听起来像垃圾时,这才有效。如果我完全改变采样率,程序将强制关闭。

编辑:

bufferSize = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,ENCODING_PCM_16BIT);

我在模拟器、Droid Eris、Droid 1 和 Droid 2 Global 上运行它

When ever I run the getMinBufferSize() method in the AudioRecorder Class, the method always returns -2. Even when I change the sample rate, the encoding method, and the channel number. I have tried every combination possible, but it still returns -2. I know that the permissions are there for RecordAudio. If I comment out the line for the getMinBufferSize, and make the minBuffer 4096, the Audio recorder will initialize and record. This will only work when I have the sample rate set to 8000, and the recordings sound like trash. If I change the sample rate at all, the program will force close.

Edit:

bufferSize = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,ENCODING_PCM_16BIT);

I am running this on the emulator, a Droid Eris, Droid 1, and Droid 2 Global

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔戏命师2024-12-17 18:19:08

查看 AudioRecord.java 的代码,这里实际上只有 3 种可能性:

  • 您的 channelConfig 无效。
  • 您没有使用 AudioFormat.ENCODING_PCM_16BIT。 (目前不支持 8 位。)
  • 硬件不支持您要求记录的内容。

来源:http://google. com/codesearch/p?hl=en#uX1GffpyOZk/media/java/android/media/AudioRecord.java

另请参阅:为什么 AudioRecord.getMinBufferSize 返回 ERROR_BAD_VALUE (-2)?

Looking at the code for AudioRecord.java, there's really only 3 possibilities here:

  • Your channelConfig is invalid.
  • You're not using AudioFormat.ENCODING_PCM_16BIT. (8 bit's isn't supported right now.)
  • The hardware doesn't support what you're asking it to record.

Source: http://google.com/codesearch/p?hl=en#uX1GffpyOZk/media/java/android/media/AudioRecord.java

See also: Why does AudioRecord.getMinBufferSize return ERROR_BAD_VALUE (-2)?

守不住的情2024-12-17 18:19:08

尝试使用这些参数,因为这些参数是唯一一组可以保证在所有 Android 设备上工作的参数:

AudioRecord.getMinBufferSize(
 44100,
 AudioFormat.CHANNEL_IN_MONO,
 AudioFormat.ENCODING_PCM_16BIT)

如果 44.1KHz 对您来说太大,那么使用 16000 的采样率我从来没有遇到过问题。另外,请记住这是最小录制大小。根据您的应用程序,在使用该值初始化录音机之前,最好将其乘以 2 或 3。

如果您仍然遇到问题,请确保初始化 AudioRecord 对象时使用的音频源是 MediaRecorder.AudioSource.MIC

Try with these arguments, as these are the only set of arguments that are supposedly guaranteed to work on all Android devices:

AudioRecord.getMinBufferSize(
 44100,
 AudioFormat.CHANNEL_IN_MONO,
 AudioFormat.ENCODING_PCM_16BIT)

I've never had a problem using a sample rate of 16000 if 44.1KHz is too large for you. Also, keep in mind that this is the minimum recording size. Depending on your application, it would probably be a good idea to multiply it by 2 or 3 before you use this value to initialize the Audio Recorder.

If you are still having issues, make sure the audio source you initialize the AudioRecord object with is MediaRecorder.AudioSource.MIC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文