本文介绍了在Android中获取麦克风音频。 AudioContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(由于某种原因,我无法得到这个问题的答案...)



您好。我需要访问android麦克风。我使用以下网址在网络中制作了调谐器应用程序: 。工作很好。



然而,当我使用intelXDK和cordova插件构建应用程序到Android时,我无法获得任何麦克风输入。我不确定是否需要使用此功能:。看起来像在android中获取audioContext的正确方法。此外,它会在安装应用程式时显示警告,说需要授权。可能是正确的路径,不是?



无论如何,有人可以帮我这个吗?任何想法为什么,尽管我得到日志说输入启用我不能得到任何音频? (麦克风正在工作ofc)

解决方案

我是cordova-plugin-audioinput的创建者,Cordova插件,到来自麦克风的原始音频数据。在不修改PitchDetect库的情况下,不能将其与audioinput插件一起使用。 PitchDetect库依赖于getUserMedia API,这在旧版Android网络视图(< 5.0)上不受支持,并且在任何iOS网络视图中都不受支持。另一方面,cordova-plugin-audio输入是专门为在iOS和旧版Android网络视图上启用麦克风访问而创建的。



可以解决Android上的特定问题:



英特尔XDK支持使用Crosswalk webview构建Android应用,可以使用较新版本的Blink支持Web Audio API和getUserMedia API的开放源代码版本。



要在您的版本上启用Crosswalk,请转到 Build英特尔XDK中的Android设置屏幕,并确保已选中优化with Crosswalk复选框。有关使用Crosswalk与英特尔XDK的详细信息:。



我相信应用程式也需要取得权限访问麦克风,请在英特尔XDK版本配置的添加权限字段中输入 android.permission.RECORD_AUDIO p>

与PitchDetect一起使用cordova-plugin-audio输入



手,想要与PitchDetect库一起使用cordova-plugin-audioInput(例如,如果您希望您的应用程序也在iOS中工作,但不支持getUserMedia API),则必须进行一些修改;具体来说,您需要更改PitchDetect的 toggleLiveInput 函数,以便它不依赖getUserMedia,而是启动(停止)audioinput插件,并将audioinput插件连接到PitchDetect分析器:

  audioinput.start({
streamToWebAudio:true,
audioContext:audioContext //确保audioinput插件使用与PitchDetect库相同的audioContext
});
analyzer = audioContext.createAnalyser();
analyser.fftSize = 2048;
audioinput.connect(analyzer);
updatePitch();

请注意,上述示例仍然依赖于Web Audio API, Android版本; Android 5+应该可以正常工作。有关不同浏览器上的Web Audio API支持的详细信息:。



我希望这有助于运气!


(For some reason I can't get an answer to this problem...)

Hello. I need to access android microphone. I made a tuner app in the web using this: https://github.com/cwilso/PitchDetect. Works just fine.

However when I build the app to android using intelXDK and cordova plugins I can't get any mic input. I am not sure if I need to use this: https://github.com/edimuj/cordova-plugin-audioinput. Seems like the right way to get the audioContext in android. Plus it shows a warning when installing the app saying that it needs to give authorization. Probably it is the right path, no?

Anyway can someone help me with this? Any idea why, despite I get logs saying that input is enabled I can't get any audio? (microphone is working ofc)

解决方案

I'm the creator of cordova-plugin-audioinput, a Cordova plugin which gives you access to the raw audio data from the microphone. Without modifying the PitchDetect library, you cannot use it together with the audioinput plugin. The PitchDetect library, relies on the getUserMedia API, which isn't supported on older Android webviews (<5.0), and is not supported at all on any of the iOS webviews. The cordova-plugin-audioinput, on the other hand, was specifically created to enable microphone access on both iOS and on older Android webviews.

A quick way that could solve your specific problem on Android:

The Intel XDK supports building Android apps with the Crosswalk webview, which enables you to use a newer version of Blink (The open-source version of Chrome), that supports both the Web Audio API and the getUserMedia API.

To enable Crosswalk on your builds, go to the Build Settings screen for Android in the Intel XDK and ensure that the "Optimize with Crosswalk" checkbox is checked. For more information about using Crosswalk with the Intel XDK: https://software.intel.com/en-us/xdk/blog/what-is-crosswalk.

I believe that the app also will need permission to access the microphone, so enter "android.permission.RECORD_AUDIO" in the "Add permission" field of the Intel XDK build configuration.

Using cordova-plugin-audioinput together with PitchDetect

If you, on the other hand, want to use the cordova-plugin-audioinput together with the PitchDetect library (for example if you want your app to also work in iOS, which doesn't support the getUserMedia API), you must do some modifications; specifically, you would need to change the toggleLiveInput function of PitchDetect, so that it doesn't rely on getUserMedia, but instead starts (and stops) the audioinput plugin and connects the audioinput plugin to the PitchDetect analyser:

audioinput.start({
    streamToWebAudio: true,
    audioContext: audioContext // To ensure that the audioinput plugin uses the same audioContext as the PitchDetect library
});
analyser = audioContext.createAnalyser();
analyser.fftSize = 2048;
audioinput.connect(analyser);
updatePitch();

Please note that the above example does still rely on the Web Audio API, which has limited support on older Android versions; Android 5+ should work fine though. For more information about Web Audio API support on different browsers: http://caniuse.com/#feat=audio-api.

I hope this helps and good luck!

这篇关于在Android中获取麦克风音频。 AudioContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 08:58