Skip to content

ohksith/audio_visualizer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Audio Visualizer

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.

Features

  • 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.

Installation

Prerequisites

  • Python 3.6 or later

Install the PortAudio Library

Linux

sudo apt-get update
sudo apt-get install -y portaudio19-dev

macOS

Setup a loopback device.

brew install blackhole-2ch
  1. Open the "Audio MIDI Setup" app.
  2. Create an "Aggregate Device" with the default input device and "BlackHole 2ch".
  3. Set this Aggregate Device as the input device

Windows

Download and install the PortAudio library from here

Install the Python Package

  1. Clone the repository:

    git clone https://github.com/gituser12981u2/audio_visualizer
  2. Set up a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate  # On Windows, use '.venv\Scripts\activate'
  3. Install the dependencies:

    pip install -r requirements.txt
    pip install .

Usage

Running the Visualizer

To Start the visualizer, use the following command:

audio-visualizer

Or run this command for the same outcome:

audio-visualizer --mode vertical

Or to run in horizontal mode:

audio-visualizer --mode horizontal-ltr

Note: there are two horizontal modes. One that draws bars from left to right (ltr) and one that draws bars from right to left (rtl)

Command Line Options

  • --mode: Visualization mode('vertical or horizontal). Default is vertical. That is if you put no --mode option.
  • --alpha: Smoothing factor for FFT. Default is 0.2.
  • --chunk: Number of frames per buffer. Default is 2048.
  • --rate: Sampling rate Default is 44100.
  • --bar_count: Number of bars in the visualization. Default is 75.

Example:

audio-visualizer --mode horizontal-rtl --alpha 0.3 --chunk 1024 --rate 48000 -bar_count 100

Windows Specific Instructions

On 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:

  1. Download and install a virtual audio cable from VB-Audio
  2. Set your playback device to the virtual audio cable.
  3. In your recording devices, set the virtual audio cable as the default recording device.
  4. 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.

Contributing

  1. Fork the repository.
  2. Create a new branch(git checkout -b feature-branch).
  3. Commit your changes(git commit -am 'Add new feature')
  4. Push to the branch(git push origin feature-branch)..
  5. Create a new Pull Request.

Linting and Formatting

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.py

One can also set up a pre-commit hook to automate these checks:

  1. Install pre-commit:
pip install pre-commit
  1. 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
  1. Install the pre-commit hooks:
pre-commit install

This will ensure that autopep8 and flake8 run automatically before each commit.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A janky, yet charming terminal-based audio visualizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%