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 cd04d846
authored
Dec 02, 2025
by
李宁
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
8c27b368
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
3 deletions
huaian/demo.html
huaian/js/demo.js
huaian/demo.html
View file @
cd04d84
...
...
@@ -8,6 +8,12 @@
<title>
江苏移动
</title>
<link
rel=
"stylesheet"
href=
"https://xpo.oss-cn-beijing.aliyuncs.com/huaian/css/vant.css"
/>
<link
rel=
"stylesheet"
href=
"css/demo.css?676000076"
>
<style>
.box
{
margin-bottom
:
15px
;
font-size
:
.3rem
;
width
:
2rem
;}
label
{
display
:
inline-block
;
width
:
100px
;
font-weight
:
bold
;}
select
{
width
:
2rem
}
</style>
</head>
<body>
...
...
@@ -72,8 +78,18 @@
</div>
</div>
<div
class=
"swDown"
id=
"tipDiv"
>
<div
class=
"buttDiv"
>
<div
class=
"swDown"
id=
"tipDiv"
style=
"display: flex;"
>
<div
class=
"box"
>
<label>
麦克风
</label>
<select
id=
"micSelect"
></select>
</div>
<div
class=
"box"
>
<label>
扬声器
</label>
<select
id=
"spkSelect"
></select>
</div>
<div
class=
"buttDiv"
style=
"flex-grow: 1;"
>
<div
class=
"one none clickButt"
id=
"readButt"
key=
"ok"
>
准备好了
</div>
<div
class=
"one none clickButt"
id=
"nextQuestion"
key=
"nextStep"
>
下一个问题
</div>
...
...
@@ -346,7 +362,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?
04431233311
"
></script>
<script
src=
"js/demo.js?
99
"
></script>
</body>
</html>
\ No newline at end of file
huaian/js/demo.js
View file @
cd04d84
...
...
@@ -1068,9 +1068,87 @@ async function init(){
setTimeout
(()
=>
{
$
(
'#livekit-dummy-audio-el'
).
remove
();
},
1000
)
setTimeout
(
async
()
=>
{
const
{
mics
,
spks
}
=
await
getAudioDevices
();
renderSelect
(
$
(
'#micSelect'
),
mics
,
'mic'
);
renderSelect
(
$
(
'#spkSelect'
),
spks
,
'spk'
);
// 事件绑定
$
(
'#micSelect'
).
on
(
'change'
,
e
=>
changeMic
(
e
.
target
.
value
)
);
$
(
'#spkSelect'
).
on
(
'change'
,
e
=>
changeSpk
(
e
.
target
.
value
)
);
$
(
'#refreshBtn'
).
on
(
'click'
,
init
);
},
2000
)
}
//华为杂音处理代码
/* ========== 工具函数 ========== */
// 获取全部音频设备
async
function
getAudioDevices
(){
// 必须提前拿到一次用户媒体,否则 label 为空
if
(
!
navigator
.
mediaDevices
||
!
navigator
.
mediaDevices
.
enumerateDevices
){
alert
(
'浏览器不支持 enumerateDevices'
);
return
;
}
await
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
true
});
const
devices
=
await
navigator
.
mediaDevices
.
enumerateDevices
();
devices
.
forEach
((
item
,
index
)
=>
{
if
(
!
item
.
label
){
item
.
label
=
item
.
kind
+
index
}
})
console
.
log
(
'麦克风和音频轨道输出'
)
console
.
log
(
devices
)
console
.
log
(
'麦克风和音频轨道输出'
)
return
{
mics
:
devices
.
filter
(
d
=>
d
.
kind
===
'audioinput'
),
spks
:
devices
.
filter
(
d
=>
d
.
kind
===
'audiooutput'
)
};
}
// 切换麦克风
async
function
changeMic
(
deviceId
){
// 先停掉旧轨道
if
(
window
.
currentMicStream
){
window
.
currentMicStream
.
getTracks
().
forEach
(
t
=>
t
.
stop
());
}
// 新轨道
const
stream
=
await
navigator
.
mediaDevices
.
getUserMedia
({
audio
:{
deviceId
:
deviceId
?{
exact
:
deviceId
}:
undefined
}
});
window
.
currentMicStream
=
stream
;
console
.
log
(
'已切换到麦克风:'
,
deviceId
||
'default'
);
}
// 切换扬声器(WebAudio)
async
function
changeSpk
(
deviceId
){
if
(
!
window
.
audioCtx
){
window
.
audioCtx
=
new
(
window
.
AudioContext
||
window
.
webkitAudioContext
)();
}
const
ctx
=
window
.
audioCtx
;
// Chrome/Edge 110+ 才支持 setSinkId
if
(
typeof
ctx
.
setSinkId
===
'function'
){
await
ctx
.
setSinkId
(
deviceId
);
console
.
log
(
'已切换到扬声器:'
,
deviceId
||
'default'
);
}
else
{
console
.
warn
(
'浏览器不支持 WebAudio setSinkId,切换未生效'
);
}
}
/* ========== UI 渲染 ========== */
function
renderSelect
(
$select
,
devices
,
type
){
$select
.
empty
();
devices
.
forEach
(
d
=>
{
$select
.
append
(
`<option value="
${
d
.
deviceId
}
">
${
d
.
label
||
'未知设备'
}
</option>`
);
});
// 默认选中第一项(系统默认)
$select
.
prop
(
'selectedIndex'
,
0
);
}
function
playPrompt
(
buffer
)
{
const
offCtx
=
new
OfflineAudioContext
(
1
,
buffer
.
sampleRate
*
0.02
,
buffer
.
sampleRate
);
const
src
=
offCtx
.
createBufferSource
();
...
...
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