From 1cfb7d5c99d1c161035ef48bff14da8c86b142c6 Mon Sep 17 00:00:00 2001
From: du <13220750630.163.com>
Date: 星期一, 14 四月 2025 16:36:02 +0800
Subject: [PATCH] 数字人声音

---
 easegen-front/src/views/chooseTemplate/index.vue |  111 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 78 insertions(+), 33 deletions(-)

diff --git a/easegen-front/src/views/chooseTemplate/index.vue b/easegen-front/src/views/chooseTemplate/index.vue
index d3e5132..52b418d 100644
--- a/easegen-front/src/views/chooseTemplate/index.vue
+++ b/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 = () => {

--
Gitblit v1.9.3