Browse Source

添加语音输出ai结果

yangg 7 tháng trước cách đây
mục cha
commit
c22ee2bb9f

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.html


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/css/chunk-e649c406.60ebae77.css


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/app.8747595c.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-e03d00b0.b8b12764.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/chunk-e649c406.93f7f1ad.js


+ 28 - 11
src/views/login/aiIndex.vue

@@ -100,6 +100,7 @@
                 <i class="el-icon-upload2"></i>
               </button>
             </div>
+           <!--  <button @click="playAudio" class="btn">播放音频</button> -->
             <button @click="sendMessage" class="btn">发送</button>
           </div>
         </div>
@@ -204,6 +205,15 @@ export default {
     this.init();
   },
   methods: {
+    /* 播放音频 */
+    playAudio(audioBase64) {
+      console.log(audioBase64);
+      // 创建音频元素
+      const audio = new Audio(audioBase64); // 播放音频
+      audio.play().catch((error) => {
+        console.error("Error playing audio:", error);
+      });
+    },
     async handleFileUpload(event) {
       const files = Array.from(event.target.files);
 
@@ -402,9 +412,9 @@ export default {
         }
       }
       const chatId = this.getUuid();
-      const wsUrl = `${process.env.VUE_APP_BASE_API}/chatbot/multimodal`;
+      const wsUrl = `${"http://192.168.66.187:8082"}/chatbot/multimodal`; //process.env.VUE_APP_BASE_API
       let message = this.userInput.trim();
-      
+
       const imageUrls = this.uploadFiles
         .filter((file) => file.type.startsWith("image/"))
         .map((file) => file.url);
@@ -441,23 +451,25 @@ export default {
 
         try {
           const response = await axios({
-            method: 'post',
+            method: "post",
             url: wsUrl,
             data: {
               message: message,
               chat_config_id: "17",
               user_id: this.phone,
               session_id: this.session_id || "",
-              source: 'pc',
+              source: "pc",
               image_urls: imageUrls,
-              history_limit: 10
-            }
+              //history_limit: 10
+            },
           });
 
           this.session_id = response.data.data.session_id;
-          
+
           if (response.data.code !== 200) {
-            throw new Error(`HTTP error! status: ${response.status}, message: ${response.data.message}`);
+            throw new Error(
+              `HTTP error! status: ${response.status}, message: ${response.data.message}`
+            );
           }
 
           thinkingController.abort();
@@ -470,16 +482,21 @@ export default {
             console.log("ID Object:", idObject);
             await this.getMinioUrls(idObject);
           }
-
+          // 如果有音频,播放音频
+          if (
+            response.data.data.audio_info &&
+            response.data.data.audio_info.audio_base64
+          ) {
+            this.playAudio(response.data.data.audio_info.audio_base64);
+          }
           this.handleResponse(response.data, botMessage);
-          
         } catch (error) {
           console.error("Error sending message:", error);
           thinkingController.abort();
           await thinkingPromise;
           botMessage.done = true;
           botMessage.message = "抱歉,发生了错误,请稍后再试。";
-          
+
           if (error.response) {
             console.error("Response data:", error.response.data);
             console.error("Response status:", error.response.status);

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác