| | |
| | | PPTArr.value = res |
| | | PPTArr.value[0].isActive = true |
| | | selectPPT.value = PPTArr.value[0] |
| | | const htmlContent = PPTArr.value[0].pptRemark; |
| | | // 创建一个临时的 DOM 元素 |
| | | const tempDiv = document.createElement('div'); |
| | | tempDiv.innerHTML = htmlContent; |
| | | // 获取纯文本内容 |
| | | selectPPT.value.pptRemark = tempDiv.textContent; |
| | | console.log('selectPPT.value', selectPPT.value) |
| | | showLeftList.value = true |
| | | clearInterval(schedulePPTTimer.value) |
| | |
| | | child.isActive = false |
| | | } |
| | | }) |
| | | console.log(item) |
| | | const htmlContent = item.pptRemark; |
| | | // 创建一个临时的 DOM 元素 |
| | | const tempDiv = document.createElement('div'); |
| | | tempDiv.innerHTML = htmlContent; |
| | | // 获取纯文本内容 |
| | | item.pptRemark = tempDiv.textContent; |
| | | selectPPT.value = item |
| | | } |
| | | const selectHost = ref() // 选择的数字人 |
| | |
| | | editorRef.value.insertNode(node); |
| | | editorRef.value.move(1); |
| | | } |
| | | // 定义 createAudio 异步函数 |
| | | const createAudio = async () => { |
| | | // if (!selectTextarea.value || selectTextarea.value.length == 0) { |
| | | // message.warning('请划选至少一个汉字') |
| | | // return false |
| | | // } |
| | | if (!editorRef.value.getText()) { |
| | | message.warning('请输入需要试听文本的内容…') |
| | | return false |
| | | } |
| | | // 获取编辑器 HTML 内容 |
| | | const html = editorRef.value.getText(); |
| | | const params = { |
| | | text: html, |
| | | humanId: humanId |
| | | } |
| | | showAudioPlay1.value = true |
| | | pptTemplateApi |
| | | .createAudio(params) |
| | | .then((res) => { |
| | | if (res && !res.error) { |
| | | console.log(res) |
| | | showAudioPlay1.value = false |
| | | showAudioPlay.value = true |
| | | // 如果返回结果有效且没有错误,初始化Audio |
| | | currentAudio.value = new Audio(res) |
| | | // 添加播放结束事件监听 |
| | | currentAudio.value.addEventListener('ended', () => { |
| | | showAudioPlay.value = false |
| | | currentAudio.value = null |
| | | }) |
| | | // 获取编辑器文本内容 |
| | | const text = editorRef.value.getText(); |
| | | |
| | | currentAudio.value.play() |
| | | // 检查文本是否为空 |
| | | if (!text) { |
| | | message.warning('请输入需要试听文本的内容…'); |
| | | return false; |
| | | } |
| | | |
| | | // 截取文本长度不超过 100 |
| | | const truncatedText = text.length > 100 ? text.substring(0, 100) : text; |
| | | |
| | | // 构建请求参数 |
| | | const params = { |
| | | text: truncatedText, |
| | | humanId: humanId |
| | | }; |
| | | |
| | | try { |
| | | // 显示音频播放加载状态 |
| | | showAudioPlay1.value = true; |
| | | |
| | | // 调用 API 创建音频 |
| | | const res = await pptTemplateApi.createAudio(params); |
| | | |
| | | // 检查响应是否有效且无错误 |
| | | if (res && !res.error) { |
| | | console.log(res); |
| | | // 隐藏加载状态,显示音频播放状态 |
| | | showAudioPlay1.value = false; |
| | | showAudioPlay.value = true; |
| | | |
| | | // 初始化 Audio 对象 |
| | | currentAudio.value = new Audio(res); |
| | | |
| | | // 添加播放结束事件监听器 |
| | | currentAudio.value.addEventListener('ended', () => { |
| | | showAudioPlay.value = false; |
| | | currentAudio.value = null; |
| | | }); |
| | | |
| | | // 播放音频 |
| | | currentAudio.value.play(); |
| | | } else { |
| | | // 如果返回结果为空或有错误,关闭弹出框 |
| | | showAudioPlay1.value = false |
| | | // 响应无效或有错误,隐藏加载状态 |
| | | showAudioPlay1.value = false; |
| | | } |
| | | }) |
| | | .catch((error) => { |
| | | // 捕获请求错误,关闭弹出框 |
| | | console.error('API 请求失败:', error) |
| | | showAudioPlay1.value = false |
| | | }) |
| | | } catch (error) { |
| | | // 捕获请求错误,隐藏加载状态并打印错误信息 |
| | | console.error('API 请求失败:', error); |
| | | showAudioPlay1.value = false; |
| | | } |
| | | }; |
| | | //取消试听 |
| | | const pauseAudio = () => { |
| | | currentAudio.value.pause() |