feat(mealSurplus): 添加语音告警功能,余量不足时自动语音播报菜品名称

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-08-10 17:44:33 +08:00
co-authored by Claude Opus 4.7
parent d4b532cacb
commit 6b6628b2b6
2 changed files with 813 additions and 695 deletions
File diff suppressed because it is too large Load Diff
@@ -119,16 +119,66 @@ export default {
nutritionList: [], // 营养秤实时数据
unmadeList: [], // 未制作列表
madeList: [], // 已制作列表
speechQueue: [], // 语音播报队列 [{dishName, spoken}]
speaking: false, // 是否正在播报
}
},
created() {
this.getKitchenInfo();
},
methods: {
// 语音播报:Web Speech API 依次播报队列中未播报的菜品
speakWarning() {
if (this.speaking) return;
const unspoken = this.speechQueue.filter(item => !item.spoken);
if (!unspoken.length) return;
this.speaking = true;
let index = 0;
const utterance = new SpeechSynthesisUtterance();
utterance.lang = 'zh-CN';
utterance.rate = 0.9;
utterance.volume = 1;
const playNext = () => {
if (index >= unspoken.length) {
this.speaking = false;
return;
}
const item = unspoken[index];
index++;
utterance.text = `${item.dishName}、余量不足,请注意补餐`;
console.log('[TTS] 开始播报:', utterance.text);
utterance.onend = () => {
item.spoken = true;
console.log('[TTS] 播报完成:', item.dishName);
playNext();
};
utterance.onerror = (e) => {
console.error('[TTS] 播报错误:', e.error);
item.spoken = true;
playNext();
};
speechSynthesis.speak(utterance);
};
playNext();
},
getKitchenInfo() {
var params = {};
var _this = this;
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
let hour = date.getHours();
let minute = date.getMinutes();
let second = date.getSeconds();
const times = "现在是:" + year + "年" + month + "月" + day + "号," + hour + "点" + minute + "分" + second + "秒";
_this.speechQueue.push({dishName: times, spoken: false});
httpRequest("GET", "https://dev.yixiong-tech.com:8081/nutrition/neglect/large-screen/kitchen", params, {
"X-DEVICE-CODE": "XIAOMI-00999",
"authorization": "57ee87183f2a4fa59683ec9ef41c8f5d"
@@ -165,6 +215,14 @@ export default {
}
}
// 余量不足的菜品直接推入播报队列
_this.nutritionList.forEach(function(item) {
if (item.lowStock) {
_this.speechQueue.push({dishName: item.dishName, spoken: false});
}
});
_this.speakWarning();
setTimeout(function() {
_this.getKitchenInfo();
}, 10000);