|
|
@ -64,9 +64,9 @@ |
|
|
|
</view> |
|
|
|
<!-- 录音 --> |
|
|
|
<view class="v_box" v-else> |
|
|
|
<view class="voice_title">请说话</view> |
|
|
|
<view class="voice_title">{{getVoiceTxt(voicePadConfig.step)}}</view> |
|
|
|
<image class="voice_img" src="../../static/images/i_voice.png" :src="getVoiceIcon(voicePadConfig.step)" |
|
|
|
:class="voicePadConfig.step==2?'voice_img_playing':''"></image> |
|
|
|
:class="voicePadConfig.step==2||voicePadConfig.step==4?'voice_img_playing':''"></image> |
|
|
|
<view class="voice_btn " @longpress="longPressHandle" @touchend="touchEndHandle" |
|
|
|
hover-class="btn_active" v-if="voicePadConfig.step<3">按住说话</view> |
|
|
|
<view class="v_btns" v-else-if="voicePadConfig.step==3"> |
|
|
@ -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 |
|
|
|