A simple, janky, yet charming terminal-based audio visualizer written in Python. It can visualize audio data from a microphone or any other audio input device.
- Visualize audio data in vertical or horizontal bar charts.
- Adjustable parameters such as smoothing factor, buffer size, sampling rate, and number of bars.
- Works on Linux, macOS, and Windows.
- Works best in VSC terminal, iterm2, kitty, and alacritty.
- Python 3.6 or later
sudo apt-get update
sudo apt-get install -y portaudio19-devSetup a loopback device.
brew install blackhole-2ch- Open the "Audio MIDI Setup" app.
- Create an "Aggregate Device" with the default input device and "BlackHole 2ch".
- Set this Aggregate Device as the input device
Download and install the PortAudio library from here
-
Clone the repository:
git clone https://github.com/gituser12981u2/audio_visualizer
-
Set up a virtual environment:
python3 -m venv .venv source .venv/bin/activate # On Windows, use '.venv\Scripts\activate'
-
Install the dependencies:
pip install -r requirements.txt pip install .
To Start the visualizer, use the following command:
audio-visualizerOr run this command for the same outcome:
audio-visualizer --mode verticalOr to run in horizontal mode:
audio-visualizer --mode horizontal-ltrNote: there are two horizontal modes. One that draws bars from left to right (ltr) and one that draws bars from right to left (rtl)
--mode: Visualization mode('vertical or horizontal). Default isvertical. That is if you put no--modeoption.--alpha: Smoothing factor for FFT. Default is0.2.--chunk: Number of frames per buffer. Default is2048.--rate: Sampling rate Default is44100.--bar_count: Number of bars in the visualization. Default is75.
Example:
audio-visualizer --mode horizontal-rtl --alpha 0.3 --chunk 1024 --rate 48000 -bar_count 100On Windows, audio routing can be tricky. If you want to visualize audio from your speakers or headphones instead of just the microphone, you will need to use a virtual audio cable. Follow these steps:
- Download and install a virtual audio cable from VB-Audio
- Set your playback device to the virtual audio cable.
- In your recording devices, set the virtual audio cable as the default recording device.
- Route the audio through your headphones or speakers.
This will allow for the program to render the audio that is being outputted on the device as well as continue to have the user be able to hear the same audio.
- Fork the repository.
- Create a new branch(
git checkout -b feature-branch). - Commit your changes(
git commit -am 'Add new feature') - Push to the branch(
git push origin feature-branch).. - Create a new Pull Request.
Please ensure that any updates adhere to the project's style guidelines before committing.
- Run flake8 to check for linting issues:
flake8 audio_visualizer tests audio_capture.py horizontal_visualizer.py vertical_visualizer.py visualizer.py- Run autopep8 to format the code to flake8 standards
- Note that autopep8 doesn't work 100% so some manual formatting may be necessary
autopep8 --in-place --aggressive --aggressive audio_visualizer tests audio_capture.py horizontal_visualizer.py vertical_visualizer.py visualizer.pyOne can also set up a pre-commit hook to automate these checks:
- Install pre-commit:
pip install pre-commit- Create a .pre-commit-config.yaml file with the following content:
repos:
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.7
hooks:
- id: autopep8
args: [--aggressive, --aggressive]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8- Install the pre-commit hooks:
pre-commit installThis will ensure that autopep8 and flake8 run automatically before each commit.
This project is licensed under the MIT License. See the LICENSE file for details.