简体   繁体   English

使用 Cordova 和 JavaScript 从安卓麦克风获取音频数据(不带 getUserMedia)

[英]Obtaining audio data from android microphone using Cordova and JavaScript (without getUserMedia)

I need to obtain frequency/pitch data from the microphone of an android device on the fly using JavaScript.我需要使用 JavaScript 从 Android 设备的麦克风动态获取频率/音高数据。

I have done this for desktop/laptop browsers with getUserMedia and Web Audio API, but these are not supported on the vast majority of Android devices.我已经使用 getUserMedia 和 Web Audio API 为桌面/笔记本电脑浏览器完成了这项工作,但绝大多数 Android 设备都不支持这些。

I have tried using the cordova-plugin-media-capture however this opens an audio recorder which the user can then save or discard, and after saving you can use cordova-plugin-file to obtain the data as shown here: https://stackoverflow.com/a/32097634/5674976 but I need it not to open the audio recorder, and instead perhaps just a record button, and once it is recording to provide the audio data immediately (so that it can detect the frequency data in real-time).我曾尝试使用cordova-plugin-media-capture 但是这会打开一个录音机,然后用户可以保存或丢弃该录音机,保存后您可以使用cordova-plugin-file 获取数据,如下所示: https:// stackoverflow.com/a/32097634/5674976但我不需要它来打开录音机,而可能只是一个录音按钮,一旦录音立即提供音频数据(以便它可以实时检测频率数据-时间)。

I have seen recording functionality in place eg WhatsApp, Facebook Messenger etc. and so as a last resort - since I do not know Java - would it be possible to create a plugin using Java for Cordova?我已经看到了录音功能,例如 WhatsApp、Facebook Messenger 等,所以作为最后的手段 - 因为我不知道 Java - 是否可以使用 Java 为 Cordova 创建一个插件?

edit: I have also looked at cordova-plugin-media https://github.com/apache/cordova-plugin-media which seems to provide amplitude data and current position data.编辑:我还查看了cordova-plugin-media https://github.com/apache/cordova-plugin-media ,它似乎提供了幅度数据和当前位置数据。 I'm thinking I could figure out frequency by looking at the amplitude over time, or am I being naive?我想我可以通过观察一段时间内的振幅来计算频率,还是我太天真了?

I managed to record audio and also analyze the frequency without either getUserMedia or Web Audio API for Android.我设法录制了音频并分析了频率,而没有 getUserMedia 或 Android 的 Web Audio API。

Firstly I installed the cordova-plugin-audioinput plugin, which outputs a stream of audio samples (from the microphone), with custom configurations such as buffer size and sample rate.首先,我安装了cordova-plugin-audioinput插件,它输出音频样本流(来自麦克风),具有自定义配置,例如缓冲区大小和采样率。 You can then use this data to detect specific frequencies.然后,您可以使用此数据来检测特定频率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 WebAudio API 从 getChannelData 方法获取麦克风 PCM 数据不起作用 - Obtaining microphone PCM data from getChannelData method using WebAudio API doesn't work 在不实际使用麦克风的情况下测试音频输入 - Testing Audio Input without actually using microphone JavaScript GetUserMedia 在没有 HTTPS 的情况下使用带有本地主机的 Chrome - JavaScript GetUserMedia using Chrome with localhost without HTTPS 分析来自麦克风Javascript的音频输入 - Analyze audio input from microphone Javascript (Javascript) 来自媒体流的麦克风和音频不同步 - (Javascript) Microphone and audio from mediastream are out of sync 使用navigator.getUserMedia(Javascript)访问移动麦克风 - Access mobile microphone with navigator.getUserMedia (Javascript) 您可以使用Cordova 2.9.0从JavaScript运行Android MediaPlayer播放音频设备吗? - Can you run Android MediaPlayer from JavaScript using Cordova 2.9.0 to play audio devices? 在不使用媒体插件的情况下在Android Cordova Project中播放音频 - Playing audio in Android Cordova Project without using the media plugin 如何在Android上使用带有Cordova的getUserMedia? - How to use getUserMedia with Cordova on Android? 从麦克风获取音频数据作为阵列 - Getting audio data as array from microphone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM