我有这个代码。这在 Windows 和 Android 上运行良好,但我无法听清我所说的所有单词。我只能说几句话。当我检查文档时,我发现这个 API 在 Safari 上也可以工作。那是什么问题?为什么这个 MediaRecorder API 在 iOS 上不起作用?
function startRecording() {
hideSpinner();
hideRating();
hideRatingSets();
navigator.mediaDevices.getUserMedia({ audio: true })
.then(function (stream) {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
analyser = audioContext.createAnalyser();
analyser.fftSize = 256;
var source = audioContext.createMediaStreamSource(stream);
source.connect(analyser);
dataArray = new Float32Array(analyser.fftSize);
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = function (event) {
if (event.data.size > 0) {
audioChunks.push(event.data);
// Update the wave view
drawWave();
}
};
mediaRecorder.onstop = function () {
var audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
// Save the audio data to a variable for later use
savedAudioData = audioBlob;
// Save the audio or do further processing
//console.log('Audio saved:', audioUrl);
transcribeAudio(audioBlob);
// Clear audioChunks after processing
audioChunks = [];
};
// Start the mediaRecorder
mediaRecorder.start();
})
.catch(function (error) {
console.error('Error accessing microphone:', error);
});
}
我想知道为什么它在 iOS 上不起作用
自 Safari 版本 14.1 起支持 MediaRecorder API:https://caniuse.com/mediarecorder