UNPKG

minix-template

Version:

minix template

166 lines (164 loc) 3.47 kB
/* * @Description: * @Autor: tangsj * @Date: 2022-05-12 11:34:29 * @LastEditTime: 2022-05-23 16:41:05 */ import router from '@system.router' import prompt from '@system.prompt' export default { data: { speechList:[ { name:'prepareSpeech', // url:'pages/base/canlUse/index', describe:'初始化语音函数' }, { name:'startTextToSpeech', // url:'pages/base/log/index', describe:'开始文字转语音' }, { name:'stopTextToSpeech', // url:'pages/base/canlUse/index', describe:'停止文字转语音' }, { name:'startSpeechToText', // url:'pages/base/log/index', describe:'从麦克风采集语音识别转文字' }, { name:'stopSpeechToText', // url:'pages/base/log/index', describe:'停止语音转文字' } ] }, goRouter(url){ router.push({ uri: url, }) }, /** * @description: 初始化语音函数 * @param {*} * @return {*} */ prepareSpeech(){ this.$app.$def.bridge.aiSpeechModuleWrapper() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 开始文字转语音 * @param {*} * @return {*} */ startTextToSpeech(){ const params = { text: '文本内容', url: './', } this.$app.$def.bridge.startTextToSpeech(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 停止文字转语音 * @param {*} * @return {*} */ stopTextToSpeech(){ this.$app.$def.bridge.stopTextToSpeech() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 从麦克风采集语音识别转文字 * @param {*} * @return {*} */ startSpeechToText(){ this.$app.$def.bridge.startSpeechToText() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 从麦克风采集语音识别转文字 * @param {*} * @return {*} */ stopSpeechToText(){ this.$app.$def.bridge.stopSpeechToText() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, testBridge(name){ switch(name){ case 'prepareSpeech': this.prepareSpeech() break; case 'startTextToSpeech': this.startTextToSpeech() break; case 'stopTextToSpeech': this.stopTextToSpeech() break; case 'startSpeechToText': this.startSpeechToText() break; case 'stopSpeechToText': this.stopSpeechToText() break; default: break; } } }