The Audiovisualizer.py
script is a real-time music visualizer that captures audio input and displays both the waveform and frequency spectrum of the audio signal. It uses the PyAudio library to capture audio and Matplotlib to visualize the data.
To run the Audiovisualizer.py
script, you need the following Python libraries:
pyaudio
numpy
matplotlib
You can install these dependencies using pip:
pip install pyaudio numpy matplotlib
Additionally, you need to have PortAudio installed on your system. On macOS, you can install it using Homebrew:
brew install portaudio
To run the audio visualizer, execute the Audiovisualizer.py
script:
python Audiovisualizer.py
-
Audio Parameters:
CHUNK
: Size of each audio chunk (default is 1024 samples).RATE
: Sampling rate in Hz (default is 44100 Hz).
-
PyAudio Initialization:
- The script initializes PyAudio and opens an audio stream with 16-bit resolution, mono audio, and the specified sampling rate and buffer size.
-
Visualization:
- The script creates a Matplotlib figure with two subplots: one for the waveform and one for the frequency spectrum.
- The waveform plot displays the raw audio data.
- The spectrum plot displays the frequency spectrum computed using the Fast Fourier Transform (FFT).
-
Animation:
- The
update
function reads audio data from the stream, updates the waveform plot, computes the FFT, and updates the spectrum plot. - The
FuncAnimation
function from Matplotlib animates the plots in real-time.
- The
-
Cleanup:
- After the visualization window is closed, the script stops and closes the audio stream and terminates the PyAudio instance.
Here is an example of how to run the script:
python Audiovisualizer.py
This will open a window displaying the real-time waveform and frequency spectrum of the audio input.
Pretty useless. I know. But who cares? It was fun to make.