From 9428345c3d475baf5be6f01b072f10152c2d3851 Mon Sep 17 00:00:00 2001 From: fsy Date: Thu, 20 Mar 2025 17:55:40 +0800 Subject: [PATCH] test --- README.md | 6 +---- src/components/HelloWorld.vue | 43 ----------------------------------- src/services/agora.js | 42 +++++++++++++++++++++++++++------- src/services/api.js | 8 +++---- src/stores/chat.js | 6 ++++- vite.config.js | 2 +- 6 files changed, 45 insertions(+), 62 deletions(-) delete mode 100644 src/components/HelloWorld.vue diff --git a/README.md b/README.md index 1511959..b896a08 100644 --- a/README.md +++ b/README.md @@ -1,5 +1 @@ -# Vue 3 + Vite - -This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 ` - - - - diff --git a/src/services/agora.js b/src/services/agora.js index 2fe5cdc..0005ce2 100644 --- a/src/services/agora.js +++ b/src/services/agora.js @@ -11,8 +11,8 @@ class AgoraService { this.vadEnabled = true; // 加入同一RTC频道 this.appid = '01a1debc964a4c6a8df1de2a6ce7aa4d'; - this.token = '007eJxTYEibc7f9w4Ebac5HtT9ej/CL7KzPrGb+GZmn6/G+kLVp8XsFBgPDRMOU1KRkSzOTRJNks0SLlDQg3yjRLDnVPDHRJGV67630hkBGhhvth1kZGSAQxBdhSM7PK0vMBJLF+Tmp8YZGRmZGJgwMAIF3KEg='; - this.channel = 'convaiconsole_122624'; + this.token = '007eJxTYChiW7ib6cSzPW7fP2xqFVvPqf854sNXniin39cd3pu931SlwGBgmGiYkpqUbGlmkmiSbJZokZIG5BslmiWnmicmmqRcenA7vSGQkaFhbQArIwMEgvgiDMn5eWWJmUCyOD8nNd7QwtDAxJyBAQDAkSkW'; + this.channel = 'convaiconsole_181047'; // VAD参数调整,检测语音段落 this.vadParams = { @@ -46,7 +46,12 @@ class AgoraService { this.client.on('user-published', async (user, mediaType) => { await this.client.subscribe(user, mediaType); if (mediaType === 'audio') { - user.audioTrack.play(); + // 确保不播放本地用户的音频(避免回声) + if (user.uid !== this.uid) { + user.audioTrack.play(); + } else { + console.log("Prevented local audio playback"); + } this.remoteUsers[user.uid] = user; } }); @@ -86,7 +91,6 @@ class AgoraService { try { // Join the channel this.uid = await this.client.join(this.appid, this.channel, this.token, uid); - console.log("successful! this.uid is ", this.uid); this.isJoined = true; @@ -104,11 +108,22 @@ class AgoraService { try{ // Create and publish local audio track this.localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack({ - AEC: true, - AGC: true, - ANS: true + AEC: true, // 回声消除 + AGC: true, // 自动增益控制 + ANS: true, // 噪声抑制 + encoderConfig: { + sampleRate: 48000, + stereo: false, + bitrate: 128 // 比特率 + } }); + // 禁用本地音频监听,防止在耳机中听到自己的声音 + this.localAudioTrack.play = function() { + console.log("Local audio playback disabled"); + return; + }; + // Enable VAD (Voice Activity Detection) if (this.vadEnabled && this.localAudioTrack.setVADMode) { this.localAudioTrack.setVADMode(true, this.vadParams); @@ -120,6 +135,8 @@ class AgoraService { } // Publish local audio track + console.log("this.localAudioTrack:",this.localAudioTrack); + await this.client.publish([this.localAudioTrack]); return true; }catch(error){ @@ -227,10 +244,19 @@ class AgoraService { * 设置VAD回调 */ setupVADCallback() { - if (!this.localAudioTrack) return; + // if (!this.localAudioTrack) return; + + if (!this.localAudioTrack) { + return; + } + if (typeof this.localAudioTrack.setVADMode !== 'function') { + console.error("当前 Agora SDK 版本不支持 VAD 功能");} // 设置VAD回调 this.localAudioTrack.on('vad', (result) => { + + console.log("VAD 事件触发,result.state:", result.state, "result:", result); + if (!this.inConversation) return; if (result.state === 'speech_start') { diff --git a/src/services/api.js b/src/services/api.js index 2e2fa34..6515a0e 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -35,10 +35,10 @@ class ApiService { const response = await this.client.post( `${this.baseUrl}/projects/${this.projectId}/join/`, { - "name": "convaiconsole_122624", + "name": "convaiconsole_181047", "properties": { - "channel": "convaiconsole_122624", - "agent_rtc_uid": "29501", + "channel": "convaiconsole_181047", + "agent_rtc_uid": "28794", "remote_rtc_uids": [ "*" ], @@ -93,7 +93,7 @@ class ApiService { "enable_metrics": true, "audio_scenario": "default" }, - "token": "007eJxTYEibc7f9w4Ebac5HtT9ej/CL7KzPrGb+GZmn6/G+kLVp8XsFBgPDRMOU1KRkSzOTRJNks0SLlDQg3yjRLDnVPDHRJGV67630hkBGhhvth1kZGSAQxBdhSM7PK0vMBJLF+Tmp8YZGRmZGJgwMAIF3KEg=", + "token": "007eJxTYChiW7ib6cSzPW7fP2xqFVvPqf854sNXniin39cd3pu931SlwGBgmGiYkpqUbGlmkmiSbJZokZIG5BslmiWnmicmmqRcenA7vSGQkaFhbQArIwMEgvgiDMn5eWWJmUCyOD8nNd7QwtDAxJyBAQDAkSkW", "advanced_features": { "enable_aivad": false } diff --git a/src/stores/chat.js b/src/stores/chat.js index 42c0552..6bf89e1 100644 --- a/src/stores/chat.js +++ b/src/stores/chat.js @@ -206,10 +206,11 @@ export const useChatStore = defineStore('chat', { try { this.isProcessing = true; + console.log("user send content:",content); // Add user message to the list this.addMessage({ id: Date.now(), - content, + content: content, sender: 'user', timestamp: new Date().toISOString(), }); @@ -217,6 +218,9 @@ export const useChatStore = defineStore('chat', { // Send message to API const response = await apiService.sendMessage(content); + // 检查response返回的内容 + console.log("AI response:",response); + // Add AI response to the list if (response && response.content) { this.addMessage({ diff --git a/vite.config.js b/vite.config.js index 06e3500..cc5e9c3 100644 --- a/vite.config.js +++ b/vite.config.js @@ -13,7 +13,7 @@ export default defineConfig({ server: { host: '0.0.0.0', port: 3000, - open: true, + open: false, cors:true, proxy:{ '/create-api':{