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cf
 
 
7af88f5
 
 
 
 
 
6e694cf
 
 
 
 
 
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Microphone Checker | Teste seu Microfone</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .waveform {
            height: 80px;
            background: linear-gradient(90deg, #3b82f6, #8b5cf6);
            position: relative;
            overflow: hidden;
        }
        
        .waveform::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 40 Q 25 10, 50 40 T 100 40 T 150 40 T 200 40' stroke='%23ffffff10' fill='none' stroke-width='2'/%3E%3C/svg%3E");
            opacity: 0.3;
        }
        
        .audio-level {
            height: 100%;
            width: 0;
            background-color: rgba(255, 255, 255, 0.2);
            transition: width 0.05s ease-out;
        }
        
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        
        .pulse {
            animation: pulse 2s infinite;
        }
        
        .volume-slider {
            -webkit-appearance: none;
            width: 100%;
            height: 8px;
            border-radius: 4px;
            background: #e2e8f0;
            outline: none;
        }
        
        .volume-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: #3b82f6;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .volume-slider::-webkit-slider-thumb:hover {
            background: #2563eb;
            transform: scale(1.1);
        }
    </style>
</head>
<body class="bg-gradient-to-br from-blue-50 to-purple-50 min-h-screen">
    <div class="container mx-auto px-4 py-12">
        <div class="max-w-3xl mx-auto">
            <!-- Header -->
            <div class="text-center mb-12">
                <h1 class="text-4xl font-bold text-gray-800 mb-2">Microphone Checker</h1>
                <p class="text-lg text-gray-600">Verifique e teste seus dispositivos de microfone</p>
            </div>
            
            <!-- Main Card -->
            <div class="bg-white rounded-xl shadow-xl overflow-hidden transition-all duration-300 hover:shadow-2xl">
                <!-- Status Section -->
                <div class="p-8 border-b border-gray-100">
                    <div class="flex items-center justify-between">
                        <div>
                            <h2 class="text-2xl font-semibold text-gray-800">Status do Microfone</h2>
                            <p class="text-gray-500" id="status-text">Verificando dispositivos...</p>
                        </div>
                        <div id="status-icon" class="text-4xl text-gray-400">
                            <i class="fas fa-microphone-slash"></i>
                        </div>
                    </div>
                </div>
                
                <!-- Device Selection -->
                <div class="p-8 border-b border-gray-100" id="device-section" style="display: none;">
                    <h3 class="text-lg font-medium text-gray-700 mb-4">Selecione seu microfone</h3>
                    <select id="device-select" class="w-full p-3 border border-gray-200 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                        <option value="">Carregando dispositivos...</option>
                    </select>
                </div>
                
                <!-- Visualizer -->
                <div class="waveform" id="visualizer">
                    <div class="audio-level" id="audio-level"></div>
                </div>
                
                <!-- Controls -->
                <div class="p-8">
                    <div class="flex flex-col sm:flex-row gap-4 mb-6">
                        <button id="test-btn" class="flex-1 bg-blue-600 hover:bg-blue-700 text-white font-medium py-3 px-6 rounded-lg transition-all flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                            <i class="fas fa-play"></i> Testar Microfone
                        </button>
                        <button id="stop-btn" class="flex-1 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-3 px-6 rounded-lg transition-all flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                            <i class="fas fa-stop"></i> Parar Teste
                        </button>
                    </div>
                    
                    <!-- Monitor Section -->
                    <div class="bg-purple-50 border border-purple-100 rounded-lg p-4 mb-6" id="monitor-section" style="display: none;">
                        <div class="flex items-center justify-between mb-3">
                            <h3 class="font-medium text-purple-800 flex items-center gap-2">
                                <i class="fas fa-headphones"></i> Monitorar Áudio
                            </h3>
                            <div class="flex items-center gap-2">
                                <span id="volume-value" class="text-sm text-purple-700">50%</span>
                                <i class="fas fa-volume-up text-purple-600"></i>
                            </div>
                        </div>
                        <div class="flex items-center gap-4">
                            <button id="monitor-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-4 rounded-lg transition-all flex items-center justify-center gap-2">
                                <i class="fas fa-play"></i> Ouvir
                            </button>
                            <input type="range" min="0" max="100" value="50" class="volume-slider flex-1" id="volume-slider">
                        </div>
                        <div class="mt-3 flex items-center gap-2 text-sm text-purple-700">
                            <div class="h-3 w-3 rounded-full bg-purple-400" id="monitor-indicator"></div>
                            <span id="monitor-status">Pronto para monitorar</span>
                        </div>
                    </div>
                    
                    <div class="mt-8 bg-blue-50 border border-blue-100 rounded-lg p-4" id="instructions">
                        <h3 class="font-medium text-blue-800 mb-2 flex items-center gap-2">
                            <i class="fas fa-info-circle"></i> Instruções
                        </h3>
                        <ol class="list-decimal list-inside text-blue-700 space-y-1">
                            <li>Permita o acesso ao microfone quando solicitado</li>
                            <li>Selecione seu dispositivo de microfone</li>
                            <li>Clique em "Testar Microfone" e comece a falar</li>
                            <li>Use o botão "Ouvir" para monitorar seu microfone em tempo real</li>
                            <li>O visualizador mostrará o nível de entrada de áudio</li>
                        </ol>
                    </div>
                </div>
            </div>
            
            <!-- Footer -->
            <div class="mt-12 text-center text-gray-500 text-sm">
                <p>© 2023 Microphone Checker | Desenvolvido com <i class="fas fa-heart text-red-500"></i> para testar seus dispositivos de áudio</p>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const statusText = document.getElementById('status-text');
            const statusIcon = document.getElementById('status-icon');
            const deviceSection = document.getElementById('device-section');
            const deviceSelect = document.getElementById('device-select');
            const testBtn = document.getElementById('test-btn');
            const stopBtn = document.getElementById('stop-btn');
            const audioLevel = document.getElementById('audio-level');
            const visualizer = document.getElementById('visualizer');
            const instructions = document.getElementById('instructions');
            const monitorSection = document.getElementById('monitor-section');
            const monitorBtn = document.getElementById('monitor-btn');
            const volumeSlider = document.getElementById('volume-slider');
            const volumeValue = document.getElementById('volume-value');
            const monitorStatus = document.getElementById('monitor-status');
            const monitorIndicator = document.getElementById('monitor-indicator');
            
            let audioContext;
            let microphone;
            let analyser;
            let isTesting = false;
            let devices = [];
            let monitorStream = null;
            let monitorGain = null;
            let isMonitoring = false;
            let volume = 0.5;
            
            // Check microphone availability
            checkMicrophoneAvailability();
            
            async function checkMicrophoneAvailability() {
                try {
                    // Request permission to list devices
                    const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
                    stream.getTracks().forEach(track => track.stop());
                    
                    // List audio devices
                    devices = await navigator.mediaDevices.enumerateDevices();
                    const audioDevices = devices.filter(device => device.kind === 'audioinput');
                    
                    if (audioDevices.length > 0) {
                        // Update status
                        statusText.textContent = `${audioDevices.length} microfone(s) disponível(is)`;
                        statusIcon.innerHTML = '<i class="fas fa-microphone text-green-500 pulse"></i>';
                        
                        // Show device selection and monitor section
                        deviceSection.style.display = 'block';
                        monitorSection.style.display = 'block';
                        populateDeviceSelect(audioDevices);
                        
                        // Enable test button
                        testBtn.disabled = false;
                    } else {
                        statusText.textContent = 'Nenhum microfone encontrado';
                        statusIcon.innerHTML = '<i class="fas fa-microphone-slash text-red-500"></i>';
                    }
                } catch (error) {
                    console.error('Error accessing microphone:', error);
                    statusText.textContent = 'Acesso ao microfone negado ou erro ao acessar';
                    statusIcon.innerHTML = '<i class="fas fa-microphone-slash text-red-500"></i>';
                    
                    // Update instructions
                    instructions.querySelector('ol').innerHTML = `
                        <li class="text-red-500">Permissão para acessar o microfone foi negada</li>
                        <li>Atualize a página e permita o acesso ao microfone</li>
                        <li>Verifique as configurações de privacidade do seu navegador</li>
                    `;
                }
            }
            
            function populateDeviceSelect(audioDevices) {
                deviceSelect.innerHTML = '';
                
                if (audioDevices.length === 0) {
                    deviceSelect.innerHTML = '<option value="">Nenhum microfone encontrado</option>';
                    return;
                }
                
                // Add default option
                const defaultOption = document.createElement('option');
                defaultOption.value = '';
                defaultOption.textContent = 'Selecione um microfone...';
                deviceSelect.appendChild(defaultOption);
                
                // Add devices
                audioDevices.forEach(device => {
                    const option = document.createElement('option');
                    option.value = device.deviceId;
                    option.textContent = device.label || `Microfone ${deviceSelect.options.length}`;
                    deviceSelect.appendChild(option);
                });
            }
            
            testBtn.addEventListener('click', startTest);
            stopBtn.addEventListener('click', stopTest);
            monitorBtn.addEventListener('click', toggleMonitor);
            volumeSlider.addEventListener('input', updateVolume);
            
            async function startTest() {
                if (isTesting) return;
                
                const deviceId = deviceSelect.value;
                if (!deviceId) {
                    alert('Por favor, selecione um microfone primeiro');
                    return;
                }
                
                try {
                    isTesting = true;
                    testBtn.disabled = true;
                    stopBtn.disabled = false;
                    visualizer.style.background = 'linear-gradient(90deg, #10b981, #3b82f6)';
                    
                    // Initialize audio context
                    audioContext = new (window.AudioContext || window.webkitAudioContext)();
                    analyser = audioContext.createAnalyser();
                    analyser.fftSize = 32;
                    
                    // Get microphone stream
                    const constraints = {
                        audio: {
                            deviceId: deviceId ? { exact: deviceId } : undefined,
                            echoCancellation: false,
                            noiseSuppression: false,
                            autoGainControl: false
                        }
                    };
                    
                    const stream = await navigator.mediaDevices.getUserMedia(constraints);
                    microphone = audioContext.createMediaStreamSource(stream);
                    microphone.connect(analyser);
                    
                    // Update UI
                    statusText.textContent = 'Testando microfone... Fale agora';
                    statusIcon.innerHTML = '<i class="fas fa-microphone text-green-500 animate-pulse"></i>';
                    
                    // Start visualization
                    visualize();
                } catch (error) {
                    console.error('Error starting test:', error);
                    statusText.textContent = 'Erro ao iniciar o teste do microfone';
                    statusIcon.innerHTML = '<i class="fas fa-microphone-slash text-red-500"></i>';
                    stopTest();
                }
            }
            
            function stopTest() {
                if (!isTesting) return;
                
                isTesting = false;
                testBtn.disabled = false;
                stopBtn.disabled = true;
                visualizer.style.background = 'linear-gradient(90deg, #3b82f6, #8b5cf6)';
                
                // Stop all tracks
                if (microphone && microphone.mediaStream) {
                    microphone.mediaStream.getTracks().forEach(track => track.stop());
                }
                
                // Disconnect audio nodes
                if (microphone && analyser) {
                    microphone.disconnect();
                }
                
                // Update UI
                statusText.textContent = 'Teste concluído';
                statusIcon.innerHTML = '<i class="fas fa-microphone text-green-500"></i>';
                audioLevel.style.width = '0';
            }
            
            function visualize() {
                if (!isTesting) return;
                
                const dataArray = new Uint8Array(analyser.frequencyBinCount);
                analyser.getByteFrequencyData(dataArray);
                
                // Calculate average volume
                let sum = 0;
                for (let i = 0; i < dataArray.length; i++) {
                    sum += dataArray[i];
                }
                const average = sum / dataArray.length;
                
                // Update visualizer
                audioLevel.style.width = `${average}%`;
                
                // Color intensity based on volume
                const intensity = Math.min(average / 100, 1);
                const r = Math.floor(16 + (255 - 16) * intensity);
                const g = Math.floor(182 + (255 - 182) * intensity);
                const b = Math.floor(255 * intensity);
                audioLevel.style.backgroundColor = `rgba(${r}, ${g}, ${b}, 0.5)`;
                
                // Continue animation
                requestAnimationFrame(visualize);
            }
            
            async function toggleMonitor() {
                if (isMonitoring) {
                    stopMonitor();
                } else {
                    await startMonitor();
                }
            }
            
            async function startMonitor() {
                const deviceId = deviceSelect.value;
                if (!deviceId) {
                    alert('Por favor, selecione um microfone primeiro');
                    return;
                }
                
                try {
                    // Initialize audio context if not already done
                    if (!audioContext) {
                        audioContext = new (window.AudioContext || window.webkitAudioContext)();
                    }
                    
                    // Get microphone stream
                    const constraints = {
                        audio: {
                            deviceId: deviceId ? { exact: deviceId } : undefined,
                            echoCancellation: false,
                            noiseSuppression: false,
                            autoGainControl: false
                        }
                    };
                    
                    monitorStream = await navigator.mediaDevices.getUserMedia(constraints);
                    const source = audioContext.createMediaStreamSource(monitorStream);
                    
                    // Create gain node for volume control
                    monitorGain = audioContext.createGain();
                    monitorGain.gain.value = volume;
                    
                    // Connect to destination
                    source.connect(monitorGain);
                    monitorGain.connect(audioContext.destination);
                    
                    // Update UI
                    isMonitoring = true;
                    monitorBtn.innerHTML = '<i class="fas fa-stop"></i> Parar';
                    monitorBtn.classList.remove('bg-purple-600', 'hover:bg-purple-700');
                    monitorBtn.classList.add('bg-red-500', 'hover:bg-red-600');
                    monitorStatus.textContent = 'Monitorando ativamente';
                    monitorIndicator.classList.remove('bg-purple-400');
                    monitorIndicator.classList.add('bg-green-500', 'animate-pulse');
                    
                } catch (error) {
                    console.error('Error starting monitor:', error);
                    alert('Erro ao iniciar o monitoramento: ' + error.message);
                }
            }
            
            function stopMonitor() {
                if (!isMonitoring) return;
                
                // Stop all tracks
                if (monitorStream) {
                    monitorStream.getTracks().forEach(track => track.stop());
                }
                
                // Disconnect audio nodes
                if (monitorGain) {
                    monitorGain.disconnect();
                }
                
                // Update UI
                isMonitoring = false;
                monitorBtn.innerHTML = '<i class="fas fa-play"></i> Ouvir';
                monitorBtn.classList.remove('bg-red-500', 'hover:bg-red-600');
                monitorBtn.classList.add('bg-purple-600', 'hover:bg-purple-700');
                monitorStatus.textContent = 'Pronto para monitorar';
                monitorIndicator.classList.remove('bg-green-500', 'animate-pulse');
                monitorIndicator.classList.add('bg-purple-400');
            }
            
            function updateVolume() {
                volume = volumeSlider.value / 100;
                volumeValue.textContent = `${volumeSlider.value}%`;
                
                if (monitorGain) {
                    monitorGain.gain.value = volume;
                }
            }
            
            // Handle device changes
            navigator.mediaDevices.addEventListener('devicechange', async () => {
                devices = await navigator.mediaDevices.enumerateDevices();
                const audioDevices = devices.filter(device => device.kind === 'audioinput');
                populateDeviceSelect(audioDevices);
                
                if (audioDevices.length > 0) {
                    statusText.textContent = `${audioDevices.length} microfone(s) disponível(is)`;
                    statusIcon.innerHTML = '<i class="fas fa-microphone text-green-500 pulse"></i>';
                    monitorSection.style.display = 'block';
                } else {
                    statusText.textContent = 'Nenhum microfone encontrado';
                    statusIcon.innerHTML = '<i class="fas fa-microphone-slash text-red-500"></i>';
                    monitorSection.style.display = 'none';
                }
                
                // Stop monitoring if device list changes
                if (isMonitoring) {
                    stopMonitor();
                }
            });
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=Ravisil/teste-microphone" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
</html>