diff --git a/hybrid/html/ai.html b/hybrid/html/ai.html index 1bc5480..c972693 100755 --- a/hybrid/html/ai.html +++ b/hybrid/html/ai.html @@ -272,14 +272,13 @@ /* * 拿到匹配的文字下标 */ - let QSindex = containsKeywordRegex(params.msg); - console.log(QSindex) + var QSindex = containsKeywordRegex(params.msg); if (QSindex == 0) { const obj = exampleData.filter(item => item.type == "bloodGlucose"); if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近测量的血糖为${obj[0].data_msg}毫摩尔/升` } else { - alert ('当前数据为空'); + speed(`血糖数据为空, 请连接或同步设备数据`) return } } @@ -288,7 +287,7 @@ if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近睡眠时长为${obj[0].data_msg[0].sleepTotalTime}分钟` } else { - alert ('当前数据为空'); + speed(`睡眠数据为空, 请连接或同步设备数据`) return } } @@ -297,7 +296,7 @@ if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近测量的血氧为${obj[0].data_msg}毫摩尔/升` } else { - alert ('当前数据为空'); + speed(`血氧数据为空, 请连接或同步设备数据`) return } } @@ -306,7 +305,7 @@ if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近测量的血压为${obj[0].data_msg.bloodPressureLow}/${obj[0].data_msg.bloodPressureHigh}毫摩尔/升` } else { - alert ('当前数据为空'); + speed(`血压数据为空, 请连接或同步设备数据`) return } } @@ -320,7 +319,7 @@ 高密度脂蛋白为${obj[0].data_msg.cholesterol/100}, 低密度脂蛋白为${obj[0].data_msg.cholesterol/100}, ` } else { - alert ('当前数据为空'); + speed(`血脂数据为空, 请连接或同步设备数据`) return } } @@ -329,7 +328,7 @@ if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近测量的心率为${obj[0].data_msg[0]}, ` } else { - alert ('当前数据为空'); + speed(`心率数据为空, 请连接或同步设备数据`) return } } @@ -338,7 +337,7 @@ if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近测量的体温为${obj[0].data_msg}摄氏度` } else { - alert ('当前数据为空'); + speed(`体温数据为空, 请连接或同步设备数据`) return } } @@ -347,7 +346,7 @@ if (obj[0].data_msg) { Question = `请模仿全科医生的口吻与我对话,我最近心电图测量结果为${obj[0].data_msg.heartRate}次/分` } else { - alert ('当前数据为空'); + speed(`心电图数据为空, 请连接或同步设备数据`) return } } @@ -356,11 +355,10 @@ if (obj[0].data_msg.BMI) { Question = `请模仿全科医生的口吻与我对话,我最近身体成分结果为${obj[0].data_msg.BMI}` } else { - alert ('当前数据为空'); + speed(`身体成分数据为空, 请连接或同步设备数据`) return } } - if (QSindex == 10) { const obj = exampleData.filter(item => item.type == "stepIndex"); if (obj[0].data_msg) { @@ -368,7 +366,7 @@ ${obj[0].data_msg.calorie/10}千卡, ${obj[0].data_msg.distance/1000}公里` } else { - alert ('当前数据为空'); + speed(`运动数据为空, 请连接或同步设备数据`) return } } @@ -598,6 +596,77 @@ modal.style.display = 'none'; dialog.style.display = 'none'; } + + function speed(str) { + fetch("https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1", { + method: 'POST', + headers: { + 'Authorization': 'Bearer ' + token, + 'Ocp-Apim-Subscription-Key': '58e9b39b8f6f48fe8d01f85b727ff737', + 'Content-Type': 'application/ssml+xml', + 'X-Microsoft-OutputFormat': 'audio-24khz-48kbitrate-mono-mp3' + }, + responseType: 'arraybuffer', + body: ` + + + + ${str} + + + + `, + }).then(async(response) => { + const content_bytes = await response.arrayBuffer(); + const blob = new Blob([content_bytes], { type: 'audio/mp3' }); + const blobUrl = URL.createObjectURL(blob); + + // 设置音频源 + audioElement.src = blobUrl; + + // 播放音频 + audioElement.play(); + + // 循环视频 + replayVideoSegment(60, 120); + + // 计算所需时间 + const speakingTime = calculateSpeakingTime(content.data.choices[0].text); + + // 开始倒计时 + var totalTime = speakingTime; + var countdown = setInterval(function() { + // 更新剩余时间 + totalTime --; + if (totalTime <= 0) { + // 停止倒计时 + clearInterval(countdown); + replayVideoSegment(0, 60); + } + }, 1000); + + hideModal() + }).catch(e => { + hideModal(); + }); + + startRec.style.display = 'block'; + runRec.style.display = 'none'; + } + + function throttle(fn, wait) { + let lastTime = 0; // 上一次调用的时间 + + return function (...args) { + const now = Date.now(); // 当前时间 + + // 如果距离上次调用已经超过设定时间,则调用函数 + if (now - lastTime > wait) { + lastTime = now; // 更新上一次调用的时间 + fn.apply(this, args); // 以正确的`this`和参数调用函数 + } + }; + } }; diff --git a/pages/index/index.vue b/pages/index/index.vue index 6598c2d..a20e722 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -1,6 +1,5 @@