Skip to main content

Barebones utilities for low-level computer music programming in Python and NumPy. Teaching library for CMU 15-322.

Project description

pyquist

pyquist provides basic utilities for low-level computer music programming in Python and NumPy.

pyquist is designed for learning and is the teaching library for CMU's 15-322 Intro to Computer Music. Its primary purpose is to provide a barebones foundation for working with audio in Python, e.g., allocating sample buffers, audio file decoding and playback. Accordingly, it intentionally lacks a lot of functionality found in full-fledged computer music programming frameworks, such as a rich collection of unit generators.

Want to try it without installing anything? Open In Colab

Quick example

import numpy as np
import pyquist as pq

# A 1-second, 440 Hz sine wave at CD quality.
sr = 44100
t = np.arange(sr) / sr
audio = pq.Audio(0.5 * np.sin(2 * np.pi * 440 * t), sample_rate=sr)

pq.play(audio)        # play through default output (or notebook widget)
pq.plot(audio)        # waveform
pq.plot_spec(audio)   # spectrogram

Loading and transforming:

riff = pq.Audio.from_url(
    "https://github.com/gclef-cmu/pyquist/raw/refs/heads/main/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav"
)
clip = riff.segment(offset=5.0, duration=3.0).resample(8000)
pq.play(clip)

Rendering a Score with a custom instrument. An instrument is called as instrument(**event.kwargs) — declare the kwargs you use and absorb the rest with **kwargs:

from pyquist.score import Score, Event, BasicMetronome
from pyquist.helper import pitch_to_frequency

def sine_instrument(pitch, duration, **kwargs):
    sr = 44100
    t = np.arange(int(duration * sr)) / sr
    freq = pitch_to_frequency(pitch)
    return pq.Audio(0.3 * np.sin(2 * np.pi * freq * t) * np.exp(-3 * t), sample_rate=sr)

score = Score([
    Event(0, {"pitch": 60, "duration": 0.5}),
    Event(1, {"pitch": 64, "duration": 0.5}),
    Event(2, {"pitch": 67, "duration": 0.5}),
])
pq.play(score.render(sine_instrument, metronome=BasicMetronome(120)))

For a guided walkthrough — visualization, MIDI parsing, scores, instruments — open examples/HelloPyquist.ipynb or run it in Colab.

Installation

Requires Python 3.10 or later.

macOS

brew install python@3.10          # or 3.11, 3.12, 3.13
python3.10 -m venv .venv
source .venv/bin/activate
pip install --upgrade pyquist

If pq.play(...) is silent, give Terminal (or your IDE) microphone/audio access in System Settings → Privacy & Security → Microphone.

Linux

Install Python and the PortAudio system library that sounddevice wraps:

# Debian / Ubuntu
sudo apt install python3 python3-venv libportaudio2

# Fedora
sudo dnf install python3 python3-virtualenv portaudio

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pyquist

Windows

Install Python (3.10 or later, with "Add Python to PATH" checked), then open Command Prompt:

python -m venv .venv
.venv\Scripts\activate.bat
pip install --upgrade pyquist

From source

For hacking on pyquist itself:

git clone https://github.com/gclef-cmu/pyquist.git
cd pyquist
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,notebook]"
pre-commit install

Pick default audio devices

Once installed, the pyquist CLI lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):

pyquist devices

Run notebooks

pip install jupyter ipykernel ipywidgets
python -m ipykernel install --user --name=pyquist --display-name "Pyquist"
cd examples
jupyter notebook

Then open HelloPyquist.ipynb and select the Pyquist kernel.

Acknowledgements

Inspired in part by:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyquist-0.1.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyquist-0.1.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file pyquist-0.1.0.tar.gz.

File metadata

  • Download URL: pyquist-0.1.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyquist-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aac841f621e032d3267f7072840815bdd99799e4f71a90aa1f0c69989ba41ee0
MD5 75e860d563c740793e7801b64e6d3bae
BLAKE2b-256 dd8702188e64b931b3f031304bc3f7a9af77113a5c3d0246a2eb3d3aa1c1a9b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquist-0.1.0.tar.gz:

Publisher: publish.yml on gclef-cmu/pyquist

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyquist-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyquist-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyquist-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56665d6275de4bd8b9916ea95eec7c4b720927fb3b3ad2891b2b7f62b1b792d7
MD5 75a86159ee754c427b335498a9e9ba5b
BLAKE2b-256 1d9c2e7f649eeb6630f38bf1f2612d403d15a9281b12e67f21f99c3827063fa8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyquist-0.1.0-py3-none-any.whl:

Publisher: publish.yml on gclef-cmu/pyquist

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page