Browse Source

[完善]更换语音播报声音

beijing
邵佳豪 1 year ago
parent
commit
81ce2ca43f
  1. 29
      src/app/pages/home/home.component.ts
  2. BIN
      src/assets/sound/warning.mp3

29
src/app/pages/home/home.component.ts

@ -363,17 +363,18 @@ export class HomeComponent implements OnInit {
messageId = [];
receiptOfNotification(userNotification) {
if (this.isWarningVoice) {
if (!window.speechSynthesis) {
this.message.create("warning", `该游览器不支持语音播报`);
} else {
let speakMsg = new SpeechSynthesisUtterance(
"请注意,收到一条新的预警信息,请及时处理!"
);
speakMsg.lang = "zh-CN";
speakMsg.rate = 1;
speakMsg.pitch = 1.5;
window.speechSynthesis.speak(speakMsg);
}
// if (!window.speechSynthesis) {
// this.message.create("warning", `该游览器不支持语音播报`);
// } else {
// let speakMsg = new SpeechSynthesisUtterance(
// "请注意,收到一条新的预警信息,请及时处理!"
// );
// speakMsg.lang = "zh-CN";
// speakMsg.rate = 1;
// speakMsg.pitch = 1.5;
// window.speechSynthesis.speak(speakMsg);
// }
this.Sound();
}
if (this.isWarningWindow) {
let obj = {
@ -388,7 +389,11 @@ export class HomeComponent implements OnInit {
this.messageId.push(obj);
}
}
Sound() {
var mp3Url = "../../../assets/sound/warning.mp3";
var player = new Audio(mp3Url);
player.play(); //播放 mp3这个音频对象
}
modalData;
look(item) {
console.log("推送信息", item);

BIN
src/assets/sound/warning.mp3

Binary file not shown.
Loading…
Cancel
Save