【发布时间】:2020-10-22 17:59:22
【问题描述】:
我使用 Cordova 和 Web Audio API 开发了一个应用程序,它允许用户插入耳机,将手机贴在心脏上,并听到自己的心跳。
它通过使用音频过滤器节点来做到这一点。
//Setup userMedia
context = new (window.AudioContext||window.webkitAudioContext);
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
navigator.getUserMedia(
{audio:true},
userMediaSuccess,
function(e) {
alert("error2 " + e.message);
});
function userMediaSuccess(stream)
{
//set microphone as input
input = context.createMediaStreamSource(stream);
//amplify the incoming sounds
volume = context.createGain();
volume.gain.value = 10;
//filter out sounds below 25Hz
lowPass = context.createBiquadFilter();
lowPass.type = 'lowpass';
lowPass.frequency.value = 25;
//filter out sounds above 425Hz
highPass = context.createBiquadFilter();
highPass.type = 'highpass';
highPass.frequency.value = 425;
//apply the filters and amplification to microphone input
input.connect(lowPass);
input.connect(highPass);
input.connect(volume);
//send the result of these filters to the phones speakers
highPass.connect(context.destination);
lowPass.connect(context.destination);
volume.connect(context.destination);
}
当我部署到 Android 时它运行良好,但似乎大多数这些功能在 iOS 移动浏览器上不可用。
我设法使用iosRTC plugin 制作了 getUserMedia 函数,但 createMediaStreamSource 仍然“不是函数”。
所以,我正在寻找可以过滤频率的 Web 音频 API 的替代方案,或者如果有任何我可以使用的插件,那将是完美的。
【问题讨论】:
-
你发现了吗?是否可以在不原生的情况下使用科尔多瓦做到这一点?我刚刚实现了 cordova-plugin-iosrtc 以便能够从麦克风访问实时数据,现在被困在这里......
-
很抱歉回复太晚了。不,如果不去本地化,我找不到解决方案。我最终在本机应用程序中使用了this 引擎,如果这对任何人都有用的话。
标签: ios cordova web-audio-api