简体   繁体   中英

Microphone access in Javascript in Mobile Safari

I'm trying to implement access to the microphone in Javascript, in a webpage,

using both navigator.getUserMedia({audio: true}) or navigator.mediaDevices.getUserMedia({audio:true})

(and implementing a check for vendor prefixes:

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

which is called in response to a click event of a button on the page

doesn't seem to work in IOS Safari. (Works ok in desktop Chrome).

However , these guys here seem to get it working - it works on Safari on my iPhone.

What are they doing different?

enter image description here we can you keypad microphone in input textbox and programmatically trigger some function when user stops asking

 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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM