Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李宁
/
Activity
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8c27b368
authored
Dec 01, 2025
by
李宁
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
7a9045b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
huaian/demo.html
huaian/js/demo.js
huaian/demo.html
View file @
8c27b36
...
...
@@ -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?0
202110
"
></script>
<script
src=
"js/demo.js?0
4431233311
"
></script>
</body>
</html>
\ No newline at end of file
huaian/js/demo.js
View file @
8c27b36
...
...
@@ -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
}
`
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment