[英]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.