【问题标题】:AudioContext.createMediaStreamSource alternative for iOS?iOS 的 AudioContext.createMediaStreamSource 替代方案?
【发布时间】: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


【解决方案1】:

在 ios web 上没有办法做到这一点。你需要一个原生应用,因为 Apple 不支持 safari 中的音频输入。

【讨论】:

  • 很遗憾,直到 Apple Safari 团队唤醒音频输入,是的。
【解决方案2】:

你有没有尝试使用

document.addEventListener('deviceready', function () {
  // Just for iOS devices.
  if (window.device.platform === 'iOS') {
     cordova.plugins.iosrtc.registerGlobals();
  }
});

【讨论】:

    【解决方案3】:

    您很久以前就问过这个问题,但遗憾的是,Safari Mobile 仍然不支持 createMediaStreamSource(以后会支持吗?)。

    如前所述,插件是实现此目的的唯一方法,实际上有一个 Cordova/Phonegap 插件可以做到这一点。 cordova-plugin-audioinput 让您可以使用 Web 音频 API 或通过提供原始音频数据块的回调访问麦克风的声音,它支持 iOS 和 Android。

    由于我不想两次发布相同的答案,因此我将在 stackoverflow 上为您指出以下答案,您还可以在其中找到代码示例:https://stackoverflow.com/a/38464815/6609803

    我是该插件的创建者,感谢任何反馈。

    【讨论】:

      【解决方案4】:
      猜你喜欢
      • 2019-12-10
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多