diff --git a/src/subpackage/device/pages/audio_manage/audio_manage.vue b/src/subpackage/device/pages/audio_manage/audio_manage.vue index aec4a80..26c3939 100644 --- a/src/subpackage/device/pages/audio_manage/audio_manage.vue +++ b/src/subpackage/device/pages/audio_manage/audio_manage.vue @@ -64,9 +64,9 @@ - 请说话 + {{getVoiceTxt(voicePadConfig.step)}} + :class="voicePadConfig.step==2||voicePadConfig.step==4?'voice_img_playing':''"> 按住说话 @@ -121,6 +121,11 @@ return i => { return `../../static/images/i_voice_${i}.png` } + }, + getVoiceTxt() { + return i => { + return [,'请按住说话','录音中...','录音已完成','播放中...'][i] + } }, }, @@ -139,7 +144,7 @@ deviceList: [], voicePadConfig: { showVoicePad: false, - step: 1, // 0,文字转语音 1 未录音, 2 录音中, 3 录音结束 + step: 1, // 0 文字转语音, 1 未录音, 2 录音中, 3 录音结束, 4 播放录音中, txt: "", voicePath: "", voiceUrl: "", @@ -147,24 +152,38 @@ } }, onLoad(options) { - let self = this; - recorderManager.onStop(function(res) { - console.log('recorder stop' + JSON.stringify(res)); - self.voicePadConfig.voicePath = res.tempFilePath; - }); - - let _pageInfo = showArr[`s${options.sid}`] || {}; - this.pageInfo = _pageInfo; - uni.setNavigationBarTitle({ - title: _pageInfo.name - }); - - this.getDeviceList({ - stadium_id: this.curStoreInfo.id, - hardware_type: _pageInfo.hardware_type - }) + this.initAudio(); + this.initPage(options); }, - methods: { + methods: { + //初始化音频 + initAudio(){ + let self = this; + recorderManager.onStop(function(res) { + console.log('recorder stop' + JSON.stringify(res)); + self.voicePadConfig.voicePath = res.tempFilePath; + }); + innerAudioContext.onPlay(function(res) { + console.log('play voice onPlay' + JSON.stringify(res)); + if(self.voicePadConfig.step==3)self.voicePadConfig.step = 4 + }); + innerAudioContext.onEnded(function(res) { + console.log('play voice onEnded' + JSON.stringify(res)); + if(self.voicePadConfig.step == 4)self.voicePadConfig.step = 3 + }); + }, + initPage(options){ + let _pageInfo = showArr[`s${options.sid}`] || {}; + this.pageInfo = _pageInfo; + uni.setNavigationBarTitle({ + title: _pageInfo.name + }); + + this.getDeviceList({ + stadium_id: this.curStoreInfo.id, + hardware_type: _pageInfo.hardware_type + }) + }, longPressHandle(e) { console.log("长按开始..."); this.voicePadConfig.step = 2 @@ -203,6 +222,7 @@ let _url = ""; //需上传给后台的语音地址 if(this.voicePadConfig.step==0){ let txt = this.voicePadConfig.txt + if(!txt)return util.showNone("请先输入您要说的话后重试") _url = `${deviceApi.ORIGIN}/ouxuanac/tts/textToVoice.wav?text=${txt}&voice_type=4&speed=-1&volume=10`; } //已录音 @@ -242,9 +262,11 @@ }, //试听/播放 语音/录音 async listenVoice() { + let self = this if(this.voicePadConfig.step==0){ //需要将语音下载到本地,然后播放 let txt = this.voicePadConfig.txt; + if(!txt)return util.showNone("请先输入您要说的话后重试") let url =`${deviceApi.ORIGIN}/ouxuanac/tts/textToVoice.wav?text=${txt}&voice_type=4&speed=-1&volume=10`; let updated_url = await this.getDownloadUrl(url) innerAudioContext.src = updated_url diff --git a/src/subpackage/device/static/images/i_voice_4.png b/src/subpackage/device/static/images/i_voice_4.png new file mode 100644 index 0000000..fce66a6 Binary files /dev/null and b/src/subpackage/device/static/images/i_voice_4.png differ