From 04b6dba74c7051dcc0947b08a4f70b595672e3f2 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Fri, 07 Jan 2022 11:34:00 +0800
Subject: [PATCH] +文字转语音细节

---
 src/store/modules/mobile.js |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/store/modules/mobile.js b/src/store/modules/mobile.js
index 341e11c..db87ade 100644
--- a/src/store/modules/mobile.js
+++ b/src/store/modules/mobile.js
@@ -47,6 +47,7 @@
     tilesetLayer: null, //瀑布流
 
     audioData: null, //语音
+    audioState: false, //语音状态
   },
   mutations: {
     MSET_VIEWER(state, viewer) {
@@ -298,13 +299,12 @@
       // })
       commit("MSET_POPUPDOM", popupsDom);
     },
-    closeMobileWindowsDom({ state, commit }) {
+    closeMobileWindowsDom({ state, commit, dispatch }) {
       if (!state.MobileWindowsHide && state.popupsDom) {
         state.popupsDom.closeOur();
         commit("MSET_MOBILEWINDOWSHIDE", true);
         if (state.audioData) {
-          state.audioData = null;
-          window.speechSynthesis.cancel();
+          dispatch("MSET_GETAUDIOBEGIN", "notOpen");
         }
       } //cancel
     },
@@ -490,13 +490,23 @@
       });
     },
     MSET_GETAUDIO({ state, commit, dispatch }, val) {
-      if (state.audioData) {
-        state.audioData = null;
+      state.audioData = new window.SpeechSynthesisUtterance();
+      state.audioData.text = val;
+      state.audioData.onstart = function (e) {
+        state.audioState = true;
+      };
+      state.audioData.onend = function (event) {
+        state.audioState = false;
+      };
+    },
+    MSET_GETAUDIOBEGIN({ state, commit, dispatch }, val) {
+      if (state.audioState) {
         window.speechSynthesis.cancel();
+        state.audioState = false;
       } else {
-        state.audioData = new window.SpeechSynthesisUtterance();
-        state.audioData.text = val;
-        window.speechSynthesis.speak(state.audioData);
+        if (val != "notOpen") {
+          window.speechSynthesis.speak(state.audioData);
+        }
       }
     },
   },

--
Gitblit v1.9.3