DEV Community

blal1
blal1

Posted on

Genny: Building Procedural Sounds and Music with Python

Genny: Building Procedural Sounds and Music with Python

What if a game could generate its own sound effects instead of relying entirely on prerecorded audio files?

What if you could describe a material, an instrument, a physical interaction or a musical sequence in Python and turn it into an actual WAV file?

That is the idea behind Genny, an open-source Python library I have been developing to explore procedural audio synthesis and physically informed sound generation.

GitHub: https://github.com/blal1/genny

PyPI: https://pypi.org/project/genny/

What is Genny?

Genny is an offline sound and music synthesis library written in Python.

It provides a collection of generators and physical models that can produce audio from parameters, code or structured JSON specifications.

Rather than simply playing prerecorded samples, Genny can generate sounds based on properties such as:

  • Instrument type and playing parameters.
  • Material and object size.
  • Physical interactions such as impacts, friction and bouncing.
  • Environmental conditions and room acoustics.
  • Musical notes, sequences and effects.
  • Random seeds for controlled variations.

The project currently includes a large catalogue of instruments, drums, sound effects, audio effects and generative layers.

Its main goal is to make procedural audio accessible from ordinary Python programs while also providing lower-level tools for people interested in sound synthesis and physical modelling.

Getting started

Install Genny with pip:

pip install genny
Enter fullscreen mode Exit fullscreen mode

You can then import it directly into Python.

For example, let's generate a glass impact:

import genny
from genny.sfx import render_sfx
from genny.core import write_wav

sample_rate = 44100

audio = render_sfx(
    "impact",
    sample_rate,
    material="glass",
    size=0.2
)

write_wav("glass_tap.wav", audio, sample_rate)
Enter fullscreen mode Exit fullscreen mode

The generator returns a NumPy audio array, which can be processed, mixed or saved as a WAV file.

You are not limited to glass impacts. You can generate many kinds of sounds by changing the generator and its parameters.

Generating instruments and musical sequences

Genny also provides instruments and musical synthesis tools.

For example, you can generate a short guitar sequence:

genny seq guitar "E3:1 G3:1 B3:1 E4:2" --bpm 100 -o tune.wav
Enter fullscreen mode Exit fullscreen mode

You can also generate a sequence using another instrument:

genny seq cristal "A4:2 C5:2 E5:4" --bpm 60 -o cristal.wav
Enter fullscreen mode Exit fullscreen mode

The command-line interface makes it possible to experiment with sounds without writing a complete Python program.

Genny also includes generated music in multiple styles, alongside instruments ranging from keyboards and strings to winds, percussion and more.

Physical sound modelling

One of the most interesting parts of Genny is its physically informed synthesis engine.

The idea is to model aspects of how sounds are produced rather than relying exclusively on generic oscillators or static recordings.

For example, the library provides models for:

  • Plucked and bowed strings.
  • Piano strings and hammer interactions.
  • Acoustic tubes, reeds and wind instruments.
  • Membranes, bars and vibrating plates.
  • Impacts and friction between physical materials.
  • Bubbles, pouring liquids, fire and environmental sounds.
  • Room acoustics and sound propagation.

Here is a small example using a physical string model:

import genny

string = genny.StringInstrument(
    body="guitar",
    position=0.18,
    brightness=0.6
)

audio = string.pluck(
    220.0,
    2.0,
    velocity=0.8
)
Enter fullscreen mode Exit fullscreen mode

The library also exposes lower-level research-oriented modules under genny.physical, including waveguides, modal synthesis, particles, voice and room acoustics.

These models are reduced-order approximations designed for practical audio generation. They are not intended to replace full finite-element or boundary-element simulations.

Procedural audio for video games

Game development is one of the areas where I think procedural audio can be particularly useful.

Instead of shipping a separate audio file for every possible event, a game can generate sounds from its current state.

Imagine a game with a vehicle whose engine changes according to its RPM and load.

With Genny, you can generate an engine sound using parameters:

import genny
from genny.sfx import render_sfx
from genny.core import write_wav

engine = render_sfx(
    "pipe_engine",
    44100,
    rpm=3200.0,
    cylinders=6,
    dur=2.0
)

write_wav("engine.wav", engine, 44100)
Enter fullscreen mode Exit fullscreen mode

The same principle can be used for interface sounds, footsteps, environmental ambience, machinery, impacts and other dynamic events.

Another useful feature is deterministic generation: identical arguments produce identical audio samples. This makes it possible to cache generated sounds instead of recalculating them every time.

For example, a game could maintain a cache of sound effects generated from their parameters.

Building audio directly into Python applications

Genny is not limited to command-line usage.

Its Python API allows you to integrate sound generation into an application.

A generated sound can be stored in a variable, transformed with effects, mixed with other signals or converted into WAV bytes in memory.

For example:

from functools import lru_cache
import numpy as np

from genny.sfx import render_sfx

SAMPLE_RATE = 44100

@lru_cache(maxsize=256)
def sound(name, **params):
    return render_sfx(
        name,
        SAMPLE_RATE,
        **params
    )

glass = sound("impact", material="glass", size=0.2)
wood = sound("impact", material="wood", size=0.3)
Enter fullscreen mode Exit fullscreen mode

This is particularly useful when an application needs reusable sound generators or multiple variations of the same event.

The repository also contains a more complete integration example in examples/in_your_code.py, covering caching, parameter banks, interface events, effects, generated scenes and in-memory WAV conversion.

A large collection of sound generators

Genny includes a broad catalogue of sound generators and processing tools.

Some examples include:

  • Musical instruments and percussion.
  • Mechanical and vehicle sounds.
  • Environmental ambience.
  • Animals, insects and footsteps.
  • Impacts, scraping, rolling and breaking objects.
  • Speech and vocal synthesis.
  • Reverbs, filters and spectral processing.
  • Retro sound-generation engines.

You can inspect the available generators directly from the command line:

genny list
Enter fullscreen mode Exit fullscreen mode

You can also inspect an existing audio file:

genny info tune.wav
Enter fullscreen mode Exit fullscreen mode

The analysis tools provide information such as loudness, sharpness, brightness and spectral characteristics.

Open source and documentation

Genny is an ongoing project, and I am continuing to expand its catalogue, improve its physical models and refine its Python API.

If you want to explore the implementation, the repository contains several useful documentation resources:

Documentation What it covers
docs/README.md Documentation index and Python quick start
docs/catalog.md Instruments, effects, sound generators and parameters
docs/physics.md Physical models, references and known limitations
docs/api.md Public Python API
AGENTS.md JSON specifications, musical notation and generation recipes
examples/in_your_code.py Integration into Python applications

Important: some physical synthesis components are adapted from the Klang procedural library. If you intend to distribute Genny-generated audio in an interactive product, read THIRD_PARTY_NOTICES.md and THIRD_PARTY_KLANG_LICENSE.txt in the repository to understand the applicable attribution requirements.

Try it and share your feedback

I would love to see what other developers, audio programmers, musicians and game creators could build with Genny.

Some interesting directions include:

  • Procedural sound effects for indie games.
  • Dynamic audio systems driven by game state.
  • Generative music experiments.
  • Physical modelling and audio research.
  • Automated sound generation pipelines.
  • Creative coding projects.

If you are interested, you can find the project here:

GitHub: https://github.com/blal1/genny

PyPI: https://pypi.org/project/genny/

Contributions, bug reports, suggestions and discussions are welcome.

I'm particularly interested in feedback about the API, documentation, sound quality, physical modelling and potential applications.

Thanks for reading, and happy sound generation!

Top comments (0)