Tengo este código que toma audio en vivo del micrófono, lo convierte en frecuencia y finalmente muestra el gráfico de tiempo frente a frecuencia. Está funcionando bien.
¿Lo que necesito hacer? Mientras tomo el audio del micrófono, hay ruido en el audio grabado que fluctúa en la frecuencia.
Necesito eliminar/reducir ese ruido/perturbación de fondo y obtener una salida un poco más suave: frecuencia de audio.
CÓDIGO
import { PitchDetector } from "https://esm.sh/pitchy@3"; function updatePitch(analyserNode, detector, input, sampleRate) { analyserNode.getFloatTimeDomainData(input); const [pitch, clarity] = detector.findPitch(input, sampleRate); Plotly.extendTraces('chart', {y: [[Math.round(pitch * 10) / 10]]}, [0]) document.getElementById("pitch").textContent = `${Math.round(pitch * 10) / 10 } Hz`; document.getElementById("clarity").textContent = `${Math.round( clarity * 100 )} %`; window.setTimeout( () => { updatePitch(analyserNode, detector, input, sampleRate); }, 250 ); } Plotly.plot( 'chart', [{ y: [Math.round(pitch * 10) / 10], type: 'line' }] ); document.addEventListener("DOMContentLoaded", () => { const audioContext = new window.AudioContext(); const analyserNode = audioContext.createAnalyser(); document .getElementById("resume-button") .addEventListener("click", () => audioContext.resume()); navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => { audioContext.createMediaStreamSource(stream).connect(analyserNode); const detector = PitchDetector.forFloat32Array(analyserNode.fftSize); const input = new Float32Array(detector.inputLength); updatePitch(analyserNode, detector, input, audioContext.sampleRate); }); });