A simple package to do realtime audio analysis in native Python, using PyAudio and Numpy to extract and visualize FFT features from a live audio stream.
- Install Python v3.10.13 from Python.org- you are not required to add the installation to PATH, however it may come in handy later.
- Download this code using the button in the upper right: "Downlaod as ZIP"
- Locate the directory you downloaded the ZIP file to, and extract it to a new folder.
- Open your device's terminal, and change your root directory to the project folder you just made.
- In Windows, right click the folder and select the "Copy as path" option.
- Open a terminal window, and enter
cd "<path>". To fill in your path, hit Right Click.
- In the same terminal window, run
python3 -m pip install -r requirements.txt - Wait for the requirements to complete their installation, then run the program using
python3 -u run_FFT_analyzer.py
Requirements:
pip install -r requirements.txt
You also might have to
sudo apt install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 (tested on Ubuntu)
I developped this code on my local machine --> it has not been properly tested on other setups.. If something doesn't work, please first try to fix it yourself and post an issue/solution when appropriate!
- Tested on Ubuntu 18.04
- Other platforms like Mac/Windows should work if PyGame can find your display and Python finds your audio card (these can be tricky with WSL)
- For Mac OSX (tested on Catalina 10.15.4), please make sure you run with Python downloaded from Python.org (
pygamedoesn't work well with the default/Homebrew Python)
Tested with:
Alternatively to pyaudio, you can use sounddevice which might be more compatible with Windows/Mac
- just run
python3 -m pip install sounddevice - Tested on Ubuntu 18.04 with sounddevice version 0.3.15
- The code to switch between the two sound interfaces is in the
__init__function of the Stream_Analyzer class
ToDo:
- Implement realtime beat detection / melody extraction on top of FFT features (eg using Harmonic/Percussive decomposition)
- The pygame.transform operations sometimes cause weird visual artifacts (boxes) for some resolution settings --> fix??
- Remove the matplotlib dependency since it's only needed for the colormap of the vis..
- Slow bars decay speed currently depends on how often
.get_audio_features()is called --> fix

