|
@@ -237,15 +237,14 @@ const getConversation = async (id) => {
|
|
|
// =========== 【语音录入】相关 ===========
|
|
// =========== 【语音录入】相关 ===========
|
|
|
// 初始化语音识别
|
|
// 初始化语音识别
|
|
|
const initSpeechRecognition = () => {
|
|
const initSpeechRecognition = () => {
|
|
|
- const SpeechRecognition =
|
|
|
|
|
- window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
|
|
|
|
|
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
|
if (!SpeechRecognition) {
|
|
if (!SpeechRecognition) {
|
|
|
alert("当前浏览器不支持语音输入功能");
|
|
alert("当前浏览器不支持语音输入功能");
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const instance = new SpeechRecognition();
|
|
const instance = new SpeechRecognition();
|
|
|
- instance.lang = "zh-CN";
|
|
|
|
|
|
|
+ instance.lang = 'zh-CN';
|
|
|
instance.interimResults = false;
|
|
instance.interimResults = false;
|
|
|
|
|
|
|
|
instance.onresult = (event) => {
|
|
instance.onresult = (event) => {
|
|
@@ -262,7 +261,7 @@ const initSpeechRecognition = () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
instance.onerror = (event) => {
|
|
instance.onerror = (event) => {
|
|
|
- console.error("语音识别错误:", event.error);
|
|
|
|
|
|
|
+ console.error('语音识别错误:', event.error);
|
|
|
clearInterval(countdownTimer.value); // 出错时清除定时器
|
|
clearInterval(countdownTimer.value); // 出错时清除定时器
|
|
|
isRecording.value = false;
|
|
isRecording.value = false;
|
|
|
alert("语音输入失败,请重试");
|
|
alert("语音输入失败,请重试");
|
|
@@ -291,8 +290,7 @@ const toggleSpeechInput = () => {
|
|
|
recognition.value = initSpeechRecognition();
|
|
recognition.value = initSpeechRecognition();
|
|
|
if (!recognition.value) return;
|
|
if (!recognition.value) return;
|
|
|
|
|
|
|
|
- navigator.mediaDevices
|
|
|
|
|
- .getUserMedia({ audio: true })
|
|
|
|
|
|
|
+ navigator.mediaDevices.getUserMedia({ audio: true })
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
recognition.value.start();
|
|
recognition.value.start();
|
|
|
isRecording.value = true;
|
|
isRecording.value = true;
|