Commit 8c27b368 by 李宁

1

1 parent 7a9045b5
......@@ -346,7 +346,7 @@
<script src="js/util.js?1212"></script>
<script src="js/vue.min.js"></script>
<script src="js/vant.min.js"></script>
<script src="js/demo.js?0202110"></script>
<script src="js/demo.js?04431233311"></script>
</body>
</html>
\ No newline at end of file
......@@ -261,6 +261,7 @@ function getProcess(){
setTimeout(()=>{
$("#mp3Source").attr('src', voiceUrl)
$("#mp3Source")[0].play()
//promptAndMute()
},350)
}
audioSet(false)
......@@ -1034,7 +1035,15 @@ async function init(){
await this.room.localParticipant.setCameraEnabled(true)
util.toast('摄像头开启成功')
await this.room.localParticipant.setMicrophoneEnabled(true)
await this.room.localParticipant.setMicrophoneEnabled(true,{
echoCancellation : true,
noiseSuppression : true,
autoGainControl : true,
// 关键:把“播放”通道排除掉,避免浏览器混音
channelCount : 1,
sampleRate : 48000,
})
util.toast('麦克风开启成功')
// await room.localParticipant.enableCameraAndMicrophone()
......@@ -1060,6 +1069,36 @@ async function init(){
$('#livekit-dummy-audio-el').remove();
},1000)
}
//华为杂音处理代码
function playPrompt(buffer) {
const offCtx = new OfflineAudioContext(1, buffer.sampleRate * 0.02, buffer.sampleRate);
const src = offCtx.createBufferSource();
src.buffer = buffer;
src.connect(offCtx.destination);
src.start();
offCtx.startRendering().then(() => {
// 真正播放
const src2 = audioCtx.createBufferSource();
src2.buffer = buffer;
src2.connect(gainNode);
src2.start();
});
}
function promptAndMute(buffer) {
// 1. 正确获取麦克风轨道(使用 LivekitClient 命名空间)
const micPub = room.localParticipant.getTrackPublication(LivekitClient.Track.Source.Microphone);
const micTrack = micPub?.track;
// 2. 瞬时静音 → 播放 → 恢复
if (micTrack) micTrack.mediaStreamTrack.enabled = false;
playPrompt(buffer);
setTimeout(() => {
if (micTrack) micTrack.mediaStreamTrack.enabled = true;
}, 380);
}
//华为杂音处理代码
function handleLocalTrackPublished(publication, participant) {
console.log(`本地轨道已发布: ${publication.trackName || publication.source}`);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!