【问题标题】:Microphone access in Javascript in Mobile SafariMobile Safari 中 Javascript 中的麦克风访问
【发布时间】:2019-05-23 21:53:41
【问题描述】:

我正在尝试在 Javascript 中,在网页中实现对麦克风的访问,

同时使用navigator.getUserMedia({audio: true})navigator.mediaDevices.getUserMedia({audio:true})

(并实施对供应商前缀的检查:

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;)

响应页面上按钮的点击事件调用

似乎在 IOS Safari 中不起作用。 (在桌面 Chrome 中工作正常)。

然而these guys 这里似乎可以正常工作 - 它可以在我 iPhone 上的 Safari 上工作。

他们有什么不同?

【问题讨论】:

  • 有些浏览器只允许您在用户交互后访问它。您是否启动麦克风以响应交互?
  • 是的。我会更新我的问题...
  • 看起来他们唯一有意义的事情就是navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
  • 我也这样做:)
  • 在您向我们展示您如何调用 API 之前,很难知道他们在做什么不同。

标签: javascript ios safari microphone getusermedia


【解决方案1】:

enter image description here我们可以在输入文本框中输入麦克风,并在用户停止询问时以编程方式触发某些功能

var prevTextboxWords = "";
    var textboxWords = "";
    var textRepeatTimes = 0;
    var prevTextCheck = "";
    var textCheck = "";
    var textCheckNumber = 0;
    var x = 0;
    var speechTimeOutLimit = 16;
    var iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
    if (iOS) {
        iosVoice();

        function iosVoice() {
            setTimeout(function() {
                textCheck = $("#record").val();
                var numberOfWordsSpoken = textCheck.split(" ").length;
                if (numberOfWordsSpoken < 3) speechTimeOutLimit = 16;
                else if (numberOfWordsSpoken < 6) speechTimeOutLimit = 12;
                else speechTimeOutLimit = 7;
                if (textCheck != "" && textCheck == prevTextCheck) {
                    textCheckNumber++
                } else {
                    textCheckNumber = 0
                }
                if (textCheck.length < 4) textCheckNumber = 0;
                if (textCheckNumber > speechTimeOutLimit) {
                    textCheckNumber = 0;
                    $("#record").val("");
                    prevTextCheck = "";
                    textCheck = textCheck.toLowerCase();

                    console.log(textCheck + "HIT");


                    //some function with text textCheck

                   
                    

    
                    textCheck = ""
                }
                prevTextCheck = textCheck;
                coroverIosVoice()
            }, 200)
        }
    }
&lt;input type="text" id="record"&gt;

【讨论】:

    猜你喜欢
    • 2010-09-16
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多