-
-
Notifications
You must be signed in to change notification settings - Fork 835
/
Copy pathmicsettings.html
203 lines (183 loc) · 6.77 KB
/
micsettings.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html>
<head>
<title>Audio Device Inspector</title>
<style>
body {
font-family: system-ui;
max-width: 800px;
margin: 20px auto;
padding: 0 20px;
background: #1a1a1a;
color: #e0e0e0;
}
select {
width: 100%;
margin: 10px 0;
padding: 8px;
background: #2d2d2d;
color: #e0e0e0;
border: 1px solid #404040;
border-radius: 4px;
}
button {
background: #2d2d2d;
color: #e0e0e0;
border: 1px solid #404040;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #404040;
}
.device-info {
background: #2d2d2d;
padding: 15px;
border-radius: 5px;
margin: 10px 0;
border: 1px solid #404040;
}
.meter-container {
width: 100%;
height: 30px;
background: #2d2d2d;
position: relative;
border-radius: 3px;
border: 1px solid #404040;
}
.meter-fill {
height: 100%;
width: 0%;
background: #4CAF50;
transition: width 0.1s;
border-radius: 3px;
background: linear-gradient(90deg, #2196F3, #4CAF50);
}
.error {
color: #ff6b6b;
padding: 10px;
background: #2d2d2d;
border-radius: 3px;
border: 1px solid #ff6b6b;
}
h1, h2 { color: #4CAF50; }
</style>
</head>
<body>
<h1>Audio Device Inspector</h1>
<div id="permissionRequest">
<button onclick="requestPermission()">Grant Microphone Access</button>
</div>
<div id="deviceSelector" style="display: none;">
<h2>Select Input Device</h2>
<select id="audioInputs"></select>
<div id="inputInfo" class="device-info"></div>
<h2>Output Device Info</h2>
<div id="outputInfo" class="device-info"></div>
<h2>Audio Meter</h2>
<div class="meter-container">
<div id="meter" class="meter-fill"></div>
</div>
</div>
<script>
let audioContext;
let analyzer;
let mediaStream;
async function requestPermission() {
try {
await navigator.mediaDevices.getUserMedia({ audio: true });
document.getElementById('permissionRequest').style.display = 'none';
document.getElementById('deviceSelector').style.display = 'block';
initializeAudioInspector();
} catch (err) {
showError('Permission denied or audio system error: ' + err.message);
}
}
async function initializeAudioInspector() {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
const audioInputs = devices.filter(device => device.kind === 'audioinput');
const select = document.getElementById('audioInputs');
select.innerHTML = audioInputs.map(device =>
`<option value="${device.deviceId}">${device.label}</option>`
).join('');
select.onchange = connectToDevice;
audioContext = new AudioContext();
await connectToDevice();
} catch (err) {
showError('Failed to initialize audio system: ' + err.message);
}
}
async function connectToDevice() {
if (mediaStream) {
mediaStream.getTracks().forEach(track => track.stop());
}
const deviceId = document.getElementById('audioInputs').value;
try {
mediaStream = await navigator.mediaDevices.getUserMedia({
audio: {
deviceId: deviceId ? { exact: deviceId } : undefined,
echoCancellation: false,
noiseSuppression: false,
autoGainControl: false
}
});
const track = mediaStream.getAudioTracks()[0];
const capabilities = track.getCapabilities();
const settings = track.getSettings();
displayDeviceInfo('inputInfo', settings, capabilities);
displayOutputInfo();
setupAudioMeter();
} catch (err) {
showError('Failed to connect to device: ' + err.message);
}
}
function displayDeviceInfo(elementId, settings, capabilities) {
const info = document.getElementById(elementId);
info.innerHTML = `
<div>Sample Rate: ${settings.sampleRate || 'Unknown'} Hz</div>
<div>Channels: ${settings.channelCount || 'Unknown'}</div>
<div>Latency: ${(settings.latency || 0).toFixed(2)} seconds</div>
<div>Auto Gain: ${settings.autoGainControl ? 'Yes' : 'No'}</div>
<div>Echo Cancellation: ${settings.echoCancellation ? 'Yes' : 'No'}</div>
<div>Noise Suppression: ${settings.noiseSuppression ? 'Yes' : 'No'}</div>
`;
}
function displayOutputInfo() {
const info = document.getElementById('outputInfo');
info.innerHTML = `
<div>Sample Rate: ${audioContext.sampleRate} Hz</div>
<div>Base Latency: ${(audioContext.baseLatency || 0).toFixed(4)} seconds</div>
<div>Output Latency: ${(audioContext.outputLatency || 0).toFixed(4)} seconds</div>
`;
}
function setupAudioMeter() {
if (analyzer) {
analyzer.disconnect();
}
const source = audioContext.createMediaStreamSource(mediaStream);
analyzer = audioContext.createAnalyser();
analyzer.fftSize = 2048;
source.connect(analyzer);
const dataArray = new Uint8Array(analyzer.frequencyBinCount);
const meter = document.getElementById('meter');
function updateMeter() {
analyzer.getByteFrequencyData(dataArray);
const average = dataArray.reduce((a, b) => a + b) / dataArray.length;
const level = Math.min(100, average * 1.5);
meter.style.width = level + '%';
requestAnimationFrame(updateMeter);
}
updateMeter();
}
function showError(message) {
const error = document.createElement('div');
error.className = 'error';
error.textContent = message;
document.body.insertBefore(error, document.body.firstChild);
setTimeout(() => error.remove(), 5000);
}
</script>
</body>
</html>