我正在尝试在网页中用Javascript实现对麦克风的访问,
同时使用navigator.getUserMedia({audio: true})
或navigator.mediaDevices.getUserMedia({audio:true})
(并实施对供应商前缀的检查:
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
)
为响应页面上按钮的单击事件而调用
似乎在IOS Safari中不起作用。(在桌面Chrome中工作正常)。
然而,这里的这些家伙似乎让它工作 - 它适用于我的iPhone上的Safari。
他们做了什么不同?
在此处输入图像描述我们可以在输入文本框中键盘麦克风,并在用户停止询问时以编程方式触发某些功能
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">