test
This commit is contained in:
@@ -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') {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user