Python Terminal Audio Visualizer
Required:
- numpy
- scipy
- pyalsaaudio or SoundCard
Optional:
$ git clone https://github.com/bharris6/pytermvis.git
$ cd pytermvis
$ pip install .
Once installed, you need to set up the appropriate sampler for your machine.
ALSA support relies on the pyalsaaudio
package and a loopback module snd-aloop
being loaded. Then your ALSA configuration needs to support splitting sound output to the loopback interface as well as to your normal speakers.
$ pip install --user pyalsaaudio
Some resources for ALSA loopback configuration can be found below:
NOTE: There's also the alsaloop command, but I have not played with that.
ALSA requires specification of the right sampler:
$ pytermvis -b alsa
SoundCard
supports Linux/pulseaudio, Mac/coreaudio, and Windows/WASAPI.
$ pip install --user soundcard
SoundCard
is the default sampler, but can be specified as well:
$ pytermvis -b soundcard
The install method will put a command pytermvis
on your path that you can execute. Once you've installed pytermvis
itself and installed an appropriate sampler, you can run it using that command:
$ pytermvis -r text
You can also run pytermvis
using python's -m
flag instead:
$ python -m pytermvis.run -r text
A basic install will only support a text-based renderer. To use the asciimatics
or pygame
renderers, you'll need to install their respective packages.
$ pip install --user asciimatics
Once installed, asciimatics
can be selected as the renderer by using the -r
flag:
$ pytermvis -r asciimatics
pip install --user pygame
Once installed, pygame
can be selected as the renderer by using the -r
flag:
$ pytermvis -r pygame
It will show the same prompt for selection of sound device as the other renderers. The difference is, a new window will be created in which the visualizer output is drawn.
Shortcode | Long Code | Description |
---|---|---|
-c | --char | What character to draw with. One-character string. Default "*" |
-s | --sample-rate | What rate to sample at. Integer. Default 44100. |
-r | --renderer | Renderer to use. "text", "asciimatics", or "pygame". Default "text" |
-b | --backend | Which backend sampler to use. "alsa" or "soundcard". Default "soundcard" |
-t | --type | Which waveform to use. "audio" or "spectrum". Default "spectrum" |
-v | --visualization | Which type of visualization to use. "graph" for solid bars/lines or "scope" for discrete points. Default "graph" |
pytermvis
uses SoundCard
's or pyalsaaudio
's ability to record from "loopback" devices. This means it is basically catching the audio output of your speaker and passing those raw frames through numpy
's/scipy
's FFT to get the frequency domain representation. Then, that FFT data is split into buckets based on the terminal width and each bucket's amplitude is printed as vertical lines using one of the renderers: asciimatics
, pygame
, or a printline output.
Requires Python 3.x, preferable 3.6+.
ALSA support isn't really configurable.