Browse Source

finish voice file async download

voice
zmt 4 years ago
parent
commit
5d799539b9
  1. 39
      src/subpackage/device/pages/audio_manage/audio_manage.vue

39
src/subpackage/device/pages/audio_manage/audio_manage.vue

@ -58,8 +58,8 @@
<view class="v_box" v-if="voicePadConfig.step==0"> <view class="v_box" v-if="voicePadConfig.step==0">
<textarea value="" v-model="voicePadConfig.txt" placeholder="请输您要说的话,输入标点符号,智能语音效果更好哦!" /> <textarea value="" v-model="voicePadConfig.txt" placeholder="请输您要说的话,输入标点符号,智能语音效果更好哦!" />
<view class="v_btns"> <view class="v_btns">
<view class="voice_btn btn_white" @click="sendVoice(voicePadConfig.txt)">发送</view>
<view class="voice_btn btn_green" @click="listenVoice(voicePadConfig.txt)">试听</view>
<view class="voice_btn btn_white" @click="sendVoice()">发送</view>
<view class="voice_btn btn_green" @click="listenVoice()">试听</view>
</view> </view>
</view> </view>
<!-- 录音 --> <!-- 录音 -->
@ -97,7 +97,7 @@
isOpen: true, isOpen: true,
isClose: true, isClose: true,
openIcon: '/subpackage/device/static/images/i_txt.png', openIcon: '/subpackage/device/static/images/i_txt.png',
closeIcon: '/subpackage/device/static/images/i_voice.png',
closeIcon: '/subpackage/device/static/images/i_voice_1.png',
openName: '文转音', openName: '文转音',
closeName: '语音', closeName: '语音',
hardware_type: 'AudioPlayer', hardware_type: 'AudioPlayer',
@ -140,7 +140,7 @@
pageInfo: {}, pageInfo: {},
deviceList: [], deviceList: [],
voicePadConfig: { voicePadConfig: {
showVoicePad: true,
showVoicePad: false,
step: 1, // 0, 1 , 2 , 3 step: 1, // 0, 1 , 2 , 3
txt: "", txt: "",
voicePath: "", voicePath: "",
@ -210,16 +210,15 @@
} }
// //
if(this.voicePadConfig.step==3){ if(this.voicePadConfig.step==3){
console.log("88888",that.voicePadConfig.voicePath);
console.log("本地录音path:",that.voicePadConfig.voicePath);
let e = await deviceServer.uploadFile({ let e = await deviceServer.uploadFile({
url: deviceApi.uploadAudio, url: deviceApi.uploadAudio,
filePath: that.voicePadConfig.voicePath filePath: that.voicePadConfig.voicePath
}); });
let _res = util.jsonPar(e.data); let _res = util.jsonPar(e.data);
if (_res.code == 0) { if (_res.code == 0) {
console.log(123, _res)
that.voicePadConfig.voiceUrl = _res.data.url that.voicePadConfig.voiceUrl = _res.data.url
console.log("上传成功:", that.voicePadConfig.voiceUrl);
console.log("上传成功后path:", that.voicePadConfig.voiceUrl);
_url = _res.data.url // _url = _res.data.url //
} else { } else {
console.error('上传录音失败--->', _res); console.error('上传录音失败--->', _res);
@ -244,10 +243,8 @@
}) })
}, },
// TODO
/// / TODO
async listenVoice() { async listenVoice() {
let txt = this.voicePadConfig.txt
console.log('播放录音', txt);
if(this.voicePadConfig.step==0){ if(this.voicePadConfig.step==0){
//, //,
let url =`${deviceApi.ORIGIN}/ouxuanac/tts/textToVoice.wav?text=${txt}&voice_type=4&speed=-1&volume=10`; let url =`${deviceApi.ORIGIN}/ouxuanac/tts/textToVoice.wav?text=${txt}&voice_type=4&speed=-1&volume=10`;
@ -257,15 +254,33 @@
if(this.voicePadConfig.step==3){ if(this.voicePadConfig.step==3){
innerAudioContext.src = this.voicePadConfig.voicePath; innerAudioContext.src = this.voicePadConfig.voicePath;
} }
console.log('播放录音文件:', innerAudioContext.src);
if(innerAudioContext.src)innerAudioContext.play(); if(innerAudioContext.src)innerAudioContext.play();
}, },
//TODO //TODO
getDownloadUrl(url) { getDownloadUrl(url) {
console.log('下载录音'); console.log('下载录音');
util.showLoad()
return new Promise((rs,rj)=>{ return new Promise((rs,rj)=>{
uni.downloadFile({
url: url, //e
success: (res) => {
if (res.statusCode === 200) {
console.log('下载成功',res);
util.hideLoad()
rs(res.tempFilePath)
}
},
fail: (e) => {
console.log('文字转录音文件下载失败',res);
util.hideLoad()
rj(e)
},
complete: (e) => {
util.hideLoad()
},
});
}) })
return "下载录音"
}, },
getDeviceList({ getDeviceList({

Loading…
Cancel
Save