我正在努力在 Nuxt.js 2 项目中使用 SpeechRecognition API 在用户录音期间实现语音检测。该功能在桌面 Chrome 上完美运行,并且我已确认我的网站正在使用 HTTPS。我还验证了声音录制正确。然而,当我尝试在移动设备上调试代码时,我注意到“onsoundstart”事件没有被触发,这与我在桌面上观察到的情况不同。任何人都可以提供有关如何解决此问题的见解或建议吗?我的结果一直为空(textTranscript);
startRecording() {
this.durationSpeak = this.questionData?.duration_speaking;
navigator.mediaDevices
.getUserMedia({ audio: true })
.then((stream) => {
this.stream = stream;
this.recorder = RecordRTC(stream, {
type: "audio",
mimeType: "audio/mp3",
});
this.recorder.startRecording();
const SpeechRecognition = window.speechRecognition || window.webkitSpeechRecognition;
this.recognization = new SpeechRecognition();
this.recognization.continuous = true;
this.recognization.interimResults = false;
this.recognization.lang = "en-US";
this.recognization.addEventListener("result", (e) => {
const result = Array.from(e.results)
.map((result) => result[0])
.map((result) => result.transcript)
.join("");
this.$emit('updateUserAns', {
index: this.currentPage - 1,
question_id: this.questionData?.id,
textTranscript: result,
});
});
this.recognization.start();
})
.catch((error) => {
// this.$sentry.captureException(error);
console.error("Error getting media stream:", error);
});
this.countDownSpeak();
},
您找到解决这个问题的方法了吗?我也面临同样的问题