在Mobile Safari中使用Javascript进行麦克风访问

时间:2018-12-24 23:54:57

标签: javascript ios safari microphone getusermedia

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

同时使用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上运行。

他们在做什么不同?

1 个答案:

答案 0 :(得分:0)

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)
        }
    }
<input type="text" id="record">