feat: 对接音频播放

main
shengwen.chen 7 days ago
parent 043dcd1144
commit 7822519a44

@ -22,3 +22,8 @@ npm run lint
### Customize configuration ### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/). See [Configuration Reference](https://cli.vuejs.org/config/).
###设置自动播放
```
chrome://settings/content/sound
```

@ -8,3 +8,7 @@ window.globalMQ = {
MQTT_USERNAME: 'admin', // mqtt连接用户名 MQTT_USERNAME: 'admin', // mqtt连接用户名
MQTT_PASSWORD: 'admin', //mqtt连接密码 MQTT_PASSWORD: 'admin', //mqtt连接密码
}; };
window.audioUrl = {
baseURL: 'http://192.168.2.104:9090',
}

@ -1,28 +1,44 @@
import _axios from '@/utils/_axios'; import _axios from "@/utils/_axios";
import axios from "axios";
// 获取动态表格列头 // 获取动态表格列头
export const getDynamicTableHeader = data => { export const getDynamicTableHeader = (data) => {
return _axios({ return _axios({
url: '/api/DoctorMicroservice/DictReportDataSource/QueryPageList', url: "/api/DoctorMicroservice/DictReportDataSource/QueryPageList",
params: data, params: data,
}); });
}; };
// 获取动态表格数据 // 获取动态表格数据
export const getDynamicTableList = data => { export const getDynamicTableList = (data) => {
return _axios({ return _axios({
method: 'post', method: "post",
url: '/api/DoctorMicroservice/DictReportDataSource/GetHistoryAllData', url: "/api/DoctorMicroservice/DictReportDataSource/GetHistoryAllData",
data, data,
}); });
}; };
// 获取全局变量 // 获取全局变量
export const getGlobeConfig = params => { export const getGlobeConfig = (params) => {
return _axios({ return _axios({
method: 'get', method: "get",
url: '/api/identity/configs/PageList', url: "/api/identity/configs/PageList",
params, params,
}); });
}; };
// 获取音频数据
export const getAudio = (data) => {
return axios.post(
`${window.audioUrl.baseURL}/synthesize`,
{
...data,
},
{
headers: {
"Content-Type": "application/json",
},
responseType: "blob",
}
);
};

@ -92,11 +92,12 @@
<p class="text-[2.59vh]">请勿吸烟请照顾好自己随身携带的物品请耐心等待我们将竭诚为您服务</p> <p class="text-[2.59vh]">请勿吸烟请照顾好自己随身携带的物品请耐心等待我们将竭诚为您服务</p>
</div> </div>
</footer> </footer>
<audio ref="audioRef" class="invisible"></audio>
</section> </section>
</template> </template>
<script> <script>
import { getDynamicTableHeader, getDynamicTableList, getGlobeConfig } from '@/api/publishApi'; import { getDynamicTableHeader, getDynamicTableList, getGlobeConfig, getAudio } from '@/api/publishApi';
import { Carousel, CarouselItem } from 'element-ui'; import { Carousel, CarouselItem } from 'element-ui';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { statusToTxt, textWaitToColor } from '@/utils/common'; import { statusToTxt, textWaitToColor } from '@/utils/common';
@ -244,8 +245,6 @@ export default {
} }
} }
this.popupMsgList.push(data['msg']['notice'].replaceAll('', ',')); this.popupMsgList.push(data['msg']['notice'].replaceAll('', ','));
this.popupMsgList.push(data['msg']['notice'].replaceAll('', ','));
this.popupMsgList.push(data['msg']['notice'].replaceAll('', ','));
} }
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
@ -267,42 +266,32 @@ export default {
this.popupMag = this.popupMsgList[0].replace(/[,]/g, '').split('#'); this.popupMag = this.popupMsgList[0].replace(/[,]/g, '').split('#');
this.showPopup = true; this.showPopup = true;
this.playNum++; this.playNum++;
getAudio({ text: this.popupMsgList[0].replaceAll("#", '') }).then(res => {
const blob = new Blob([res['data']], { type: "audio/wav" });
const audioUrl = URL.createObjectURL(blob);
if (this.synth) { if (this.$refs.audioRef) {
const utterance = new SpeechSynthesisUtterance(this.popupMsgList[0].replace(/#/g, '')); this.$refs.audioRef.src = audioUrl
utterance.rate = 0.6; this.$refs.audioRef.play()
const voices = this.synth.getVoices();
const selectedVoice = voices.find(voice => voice.lang === 'zh-CN');
if (selectedVoice) {
utterance.voice = selectedVoice;
} else {
console.warn('voices not fount');
} }
// onend this.$refs.audioRef.onended = () => {
utterance.onend = function () { if (this.playNum < 3) {
setTimeout(() => { this.playNum++;
if (this.playNum >= 3) { setTimeout(() => {
this.popupMag = []; this.$refs.audioRef.play()
this.showPopup = false; }, 500);
this.playNum = 0; } else {
} this.popupMag = "";
this.showPopup = false;
this.playNum = 0;
this.hasPlay = false; this.hasPlay = false;
this.popupMsgList.shift(); this.popupMsgList.shift();
}, 1000); URL.revokeObjectURL(audioUrl)
}.bind(this); this.$refs.audioRef.onended = null
this.synth.speak(utterance);
//
const checkVoices = () => {
if (this.synth.getVoices().length !== 0) {
clearInterval(voicesCheckInterval);
} }
}; }
})
const voicesCheckInterval = setInterval(checkVoices, 100);
}
} }
}, },
desensitizationText(text) { desensitizationText(text) {
@ -359,8 +348,6 @@ export default {
}); });
// setTimeout(() => { // setTimeout(() => {
// this.popupMsgList.push(',,#,'); // this.popupMsgList.push(',,#,');
// this.popupMsgList.push(',,#,');
// this.popupMsgList.push(',,#,');
// }, 1000); // }, 1000);
}); });
}, },

Loading…
Cancel
Save