我对使用麦克风的应用程序有疑问。在我看来,问题在于getUserMedia()。关键是,它在Firefox上工作正常,但Chrome不会提示用户使用麦克风的可能性。我认为我的代码中存在一个错误,它使得getUserMedia()无法在Chrome上运行。有什么想法吗?
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
window.URL = window.URL || window.webkitURL;
audioContext = new AudioContext();
} catch (e) {
updateStatus("Error"); }
if (navigator.getUserMedia) navigator.getUserMedia({ audio: true }, startUserMedia, function(e) {
updateStatus("Error");
});
else updateStatus("Error");
function startUserMedia(stream) {
var input = audioContext.createMediaStreamSource(stream);
window.firefox_audio_hack = input;
var audioRecorderConfig = {errorCallback: function(x) {updateStatus("Error " + x);}};
recorder = new AudioRecorder(input, audioRecorderConfig);
// If a recognizer is ready, we pass it to the recorder
if (recognizer) recorder.consumers = [recognizer];
recorderReady = true;
updateUI();
updateStatus("Error");
};