This commit is contained in:
杨航
2025-11-10 16:56:23 +08:00
parent 021b12ac87
commit d35f5acd92
2 changed files with 57 additions and 6 deletions
+15
View File
@@ -169,6 +169,21 @@ export function downloadVoiceFile(url) {
});
});
}
// 获取音频 通用参数
export function downloadVoiceParams(url) {
const token = getToken();
const header = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
};
if (token)
header['summary'] = token
let baseUrl = get_base_url(url);
return {
url: `${baseUrl}${url}`,
header,
timeout: 180000,
}
}
export function getAudioByText(data) {
+42 -6
View File
@@ -220,6 +220,7 @@
import VideoPreview from '@/components/image-preview/video-preview.vue';
import {
downloadVoiceFile,
downloadVoiceParams,
uploadVoiceFile,
getAudioByText
} from '@/api/common.js';
@@ -439,16 +440,22 @@
// pauseVoice();
console.log('onUnload')
talkVoiceObj.value?.destroy()
if(downloadFnc.value) downloadFnc.value?.abord()
downloadFnc.value = null
});
onHide(() => {
console.log('onHide')
voiceLoading.value = false;
if(downloadFnc.value) downloadFnc.value?.abord()
downloadFnc.value = null
});
let prevTime = -1;
let pauseTime = -1;
const startPlay = ref(false)
const voiceIsPlaying = ref(false)
talkVoiceObj.value.onEnded(() => {
console.log('onEnded');
voiceIsPlaying.value = false
if(props.activeVoiceId){
emit('changePlay', '');
}
@@ -459,6 +466,7 @@
talkVoiceObj.value.onStop(() => {
console.log('onStop');
voiceLoading.value = false;
voiceIsPlaying.value = false
if(props.activeVoiceId){
emit('changePlay', '');
}
@@ -467,19 +475,23 @@
talkVoiceObj.value.src = '';
});
talkVoiceObj.value.onPause(() => {
voiceIsPlaying.value = false
voiceLoading.value = false;
prevTime = talkVoiceObj.value.currentTime;
pauseTime = prevTime
if(downloadFnc.value) downloadFnc.value?.abord()
downloadFnc.value = null
});
talkVoiceObj.value.onPlay(() => {
console.log('onPlay');
prevTime = talkVoiceObj.value.currentTime;
pauseTime = prevTime
startPlay.value = true
voiceIsPlaying.value = true
setTimeout(()=> {
startPlay.value= false
},300)
// emit('changePlay', unref(dataInfo)?.id);
emit('changePlay', unref(dataInfo)?.id);
});
talkVoiceObj.value.onTimeUpdate(() => {
@@ -526,6 +538,7 @@
playVoice();
}
};
const downloadFnc = ref(null)
const playVoice = (readType = 'pgth') => {
let _content = showContent.value;
if (!_content) {
@@ -597,8 +610,10 @@
talkVoiceObj.value.play();
} else {
storageStore.setGettingVoiceId(unref(dataInfo)?.id);
downloadVoiceFile(_url)
.then((res) => {
let _paramsObj = downloadVoiceParams(_url)
downloadFnc.value = uni.downloadFile({
..._paramsObj,
success(res) {
if (res?.data) {
common.msg(res.data.message);
return;
@@ -611,10 +626,31 @@
talkVoiceObj.value.play();
storageStore.setStorage('audio', _url + _params.teachNo, itemVoice.value);
}
})
.catch((err) => {
},
complete() {
voiceLoading.value = false;
});
downloadFnc.value = null
},
});
// downloadVoiceFile(_url)
// .then((res) => {
// if (res?.data) {
// common.msg(res.data.message);
// return;
// }
// voiceLoading.value = false;
// if()
// itemVoice.value = res.tempFilePath;
// talkVoiceObj.value.src = res.tempFilePath;
// // 判斷是否在當前頁面
// if(unref(isGettingId) === unref(dataInfo)?.id){
// talkVoiceObj.value.play();
// storageStore.setStorage('audio', _url + _params.teachNo, itemVoice.value);
// }
// })
// .catch((err) => {
// voiceLoading.value = false;
// });
}
});