AudioRecord 不适用于 Motorola Milestone

发布于 2024-08-31 14:15:06 字数 1854 浏览 4 评论 0 原文

我仅在摩托罗拉 Milestone 上遇到此问题。代码:

// init recorder
recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC,
    8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT, 8000);

recordInstance.startRecording();

//more code here

recordInstance.stop();

我拥有的错误信息(暂时无法找到更多信息,因为我自己没有调试的里程碑):

Uncaught handler: thread main exiting due to uncaught exception
java.lang.IllegalStateException: stop() called on an uninitialized AudioRecord.
at android.media.AudioRecord.stop(AudioRecord.java:51 6)

显然我不是唯一遇到此问题的人。我发现了一些非常相似的线程(没有解决方案):

http://groups .google.com/group/android-developers/browse_thread/thread/6dd24aeb484b2e40 http://web.archive.org/web/20100824043744/http://androidcommunity.com:80/forums/f2/problem-using-audiorecord-in-motorola-milestone-30935/ http://community.developer.motorola.com/t5/Android-App-Development-for/Problem-using-AudioRecord-on-Milestone-device/mp/3889 http://www.fring.com/forums/showthread.php?t= 16194 http://groups.google.com/group/android-开发人员/browse_thread/thread/63be273ba59c635e/1c4a010fd470d328

I'm having this problem only on Motorola Milestone. Code:

// init recorder
recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC,
    8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT, 8000);

recordInstance.startRecording();

//more code here

recordInstance.stop();

The errorinformation I have (can't find more for the moment since I don't have a milestone myself for debugging):

Uncaught handler: thread main exiting due to uncaught exception
java.lang.IllegalStateException: stop() called on an uninitialized AudioRecord.
at android.media.AudioRecord.stop(AudioRecord.java:51 6)

Apparantly I'm not the only one with this problem. Some very similar threads I found (without solution):

http://groups.google.com/group/android-developers/browse_thread/thread/6dd24aeb484b2e40
http://web.archive.org/web/20100824043744/http://androidcommunity.com:80/forums/f2/problem-using-audiorecord-in-motorola-milestone-30935/
http://community.developer.motorola.com/t5/Android-App-Development-for/Problem-using-AudioRecord-on-Milestone-device/m-p/3889
http://www.fring.com/forums/showthread.php?t=16194
http://groups.google.com/group/android-developers/browse_thread/thread/63be273ba59c635e/1c4a010fd470d328

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

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

发布评论

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

评论(4

很糊涂小朋友 2024-09-07 14:15:06

这应该有效:

recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC,
16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, 16000);

只需坚持标准采样率 http://en.wikipedia.org/wiki/采样率#音频。我想知道为什么 Milestone 不支持 8bit 编码录制。这也给了我一个错误 - “无效的音频格式”。

This should work:

recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC,
16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, 16000);

Just stick to the standard sample rates http://en.wikipedia.org/wiki/Sampling_rate#Audio. I wonder why Milestone does not support recording with 8bit encoding. This gives me an error too - "Invalid audio format".

浮生面具三千个 2024-09-07 14:15:06

首先,正如它所说,尝试在停止处放置一个 try catch 块,正如调试消息所说,记录正在进入 IllegalState。

也许如果你能捕获异常,你就能找出问题所在。

Firstly as it says try putting a try catch block over the stop, as the debugs message is saying, the recording is getting into an IllegalState.

Probably if u can catch the exception, you can find out what the problem is.

枫林﹌晚霞¤ 2024-09-07 14:15:06

问题不是参数,问题是摩托罗拉对 Android 的修补的一个错误,如果模式是 IN_CALL,AudioRecord 将无法正确创建自己,如果它的 MODE_NORMAL 应该没问题。

这是因为摩托罗拉代码中的某些内容在 IN_CALL 模式下占用了输入。

The issue is not parameters, the issue is a bug with Motorola's tinkering of Android, the AudioRecord will not create itself properly if the mode is IN_CALL, if its MODE_NORMAL it should be fine.

This is because something in Motorolas code hogs the input when its IN_CALL mode.

野侃 2024-09-07 14:15:06

理论上,hcpl 的代码应该可以工作,因为语音采样为 8kHz,但某些 Android 设备不接受它。

来自 Android 开发者网站的疯狂回答如下:

sampleRateInHz int:以赫兹表示的采样率。 44100Hz是
目前唯一保证适用于所有设备的速率,但是
其他速率(例如 22050、16000 和 11025)可能适用于某些设备。
AudioFormat.SAMPLE_RATE_UNSPECIFIED 表示使用依赖于路由的
值通常是源的采样率。获取采样率()
可用于检索选择的实际采样率。

Theoretically, the hcpl's code should work because the speech sampling is 8kHz but some android devices doesn't accept it.

Completing the mad answer, from the Android Developers website:

sampleRateInHz int: the sample rate expressed in Hertz. 44100Hz is
currently the only rate that is guaranteed to work on all devices, but
other rates such as 22050, 16000, and 11025 may work on some devices.
AudioFormat.SAMPLE_RATE_UNSPECIFIED means to use a route-dependent
value which is usually the sample rate of the source. getSampleRate()
can be used to retrieve the actual sample rate chosen.

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