du
2025-04-14 1cfb7d5c99d1c161035ef48bff14da8c86b142c6
easegen-front/src/views/chooseTemplate/index.vue
@@ -1732,47 +1732,92 @@
  // 截取文本长度不超过 100
  const truncatedText = text.length > 100 ? text.substring(0, 100) : text;
  console.log(audioSelectData.value)
  if (audioSelectData.value == undefined) {
    const params = {
      text: truncatedText,
      humanId: humanId,
      voiceId: 0,
    };
    try {
      // 显示音频播放加载状态
      showAudioPlay1.value = true;
  // 构建请求参数
  const params = {
    text: truncatedText,
    humanId: humanId
  };
      // 调用 API 创建音频
      const res = await pptTemplateApi.createAudio(params);
  try {
    // 显示音频播放加载状态
    showAudioPlay1.value = true;
      // 检查响应是否有效且无错误
      if (res && !res.error) {
        console.log(res);
        // 隐藏加载状态,显示音频播放状态
        showAudioPlay1.value = false;
        showAudioPlay.value = true;
    // 调用 API 创建音频
    const res = await pptTemplateApi.createAudio(params);
        // 初始化 Audio 对象
        currentAudio.value = new Audio(res);
    // 检查响应是否有效且无错误
    if (res && !res.error) {
      console.log(res);
      // 隐藏加载状态,显示音频播放状态
      showAudioPlay1.value = false;
      showAudioPlay.value = true;
        // 添加播放结束事件监听器
        currentAudio.value.addEventListener('ended', () => {
          showAudioPlay.value = false;
          currentAudio.value = null;
        });
      // 初始化 Audio 对象
      currentAudio.value = new Audio(res);
      // 添加播放结束事件监听器
      currentAudio.value.addEventListener('ended', () => {
        showAudioPlay.value = false;
        currentAudio.value = null;
      });
      // 播放音频
      currentAudio.value.play();
    } else {
      // 响应无效或有错误,隐藏加载状态
        // 播放音频
        currentAudio.value.play();
      } else {
        // 响应无效或有错误,隐藏加载状态
        showAudioPlay1.value = false;
      }
    } catch (error) {
      // 捕获请求错误,隐藏加载状态并打印错误信息
      console.error('API 请求失败:', error);
      showAudioPlay1.value = false;
    }
  } catch (error) {
    // 捕获请求错误,隐藏加载状态并打印错误信息
    console.error('API 请求失败:', error);
    showAudioPlay1.value = false;
  }else {
    const params = {
      text: truncatedText,
      humanId: humanId,
      voiceId: audioSelectData.value[0].id,
    };
    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;
      }
    } catch (error) {
      // 捕获请求错误,隐藏加载状态并打印错误信息
      console.error('API 请求失败:', error);
      showAudioPlay1.value = false;
    }
  }
  // 构建请求参数
}
//取消试听
const pauseAudio = () => {