accompy.tools#

Tools for generating accompaniment audio from Score objects.

Provides a pluggable score_to_wav engine architecture. The default engine uses MMA (Musical MIDI Accompaniment), but any callable with the ScoreToWav signature can be swapped in — including engines built from accompy’s own converter pipeline.

Quick start:

>>> from accompy import Score, generate_wav
>>> score = Score.from_string("| Dm7 | G7 | C^7 |")
>>> generate_wav(score, "/tmp/test.wav", groove="BossaNova", tempo=140)

Using an alternative engine:

>>> from accompy.tools import make_converter_engine, generate_wav
>>> engine = make_converter_engine(resolver="pychord", midi_gen="pretty_midi",
...                                 audio_renderer="fluidsynth")
>>> generate_wav(score, "/tmp/test.wav", score_to_wav=engine, tempo=140)

Module Attributes

generate_mma_wav(score, output_path, *[, ...])

Alias for mma_score_to_wav().

Functions

generate_mma_wav(score, output_path, *[, ...])

Alias for mma_score_to_wav().

generate_variations(score, output_dir, *[, ...])

Batch-generate WAV files for many key / tempo / groove combinations.

generate_wav(score, output_path, *[, ...])

Generate a WAV file from a Score using a pluggable engine.

make_converter_engine(*[, resolver, ...])

Create a ScoreToWav engine from accompy's converter pipeline.

mma_score_to_wav(score, output_path, *[, ...])

Render a Score to WAV using MMA (Musical MIDI Accompaniment).

Classes

ScoreToWav(*args, **kwargs)

Callable that renders a Score to a WAV file.

class accompy.tools.ScoreToWav(*args, **kwargs)[source]#

Bases: Protocol

Callable that renders a Score to a WAV file.

Any function matching this signature can be used as a score_to_wav engine in generate_wav() and generate_variations().

accompy.tools.generate_mma_wav(score, output_path, *, groove='Swing', tempo=120, repeats=1)#

Alias for mma_score_to_wav(). Kept for backward compatibility.

Return type:

Path

accompy.tools.generate_variations(score, output_dir, *, keys=('C',), tempos=(120,), grooves=('Swing',), repeats=1, filename_template='{title}_{key}_{tempo}bpm_{groove}.wav', score_to_wav=None)[source]#

Batch-generate WAV files for many key / tempo / groove combinations.

Produces one WAV for each (key, tempo, groove) triple (cycled from the shortest sequences). Useful for creating practice backing-track collections.

Parameters:
  • score (Score) – Base Score (will be transposed per key).

  • output_dir (Union[str, Path]) – Directory for output files.

  • keys (Sequence[str]) – Keys to transpose to.

  • tempos (Sequence[int]) – Tempos in BPM to cycle through.

  • grooves (Sequence[str]) – Groove / style names to cycle through.

  • repeats (int) – Number of repeats per file.

  • filename_template (str) – Template for filenames. Placeholders: {title}, {key}, {tempo}, {groove}.

  • score_to_wav (Optional[ScoreToWav]) – Engine callable. Defaults to mma_score_to_wav().

Return type:

list[Path]

Returns:

List of Paths to successfully generated files.

Example:

>>> from accompy import Score, generate_variations
>>> score = Score.from_string("| C6 | Do | C6/E | Fo |", key="C")
>>> generate_variations(
...     score, "/tmp/variations",
...     keys=["C", "G", "F"],
...     tempos=[100, 120],
...     grooves=["Swing", "BossaNova"],
... )

>>> # With a custom engine:
>>> from accompy.tools import make_converter_engine
>>> engine = make_converter_engine(audio_renderer="fluidsynth")
>>> generate_variations(
...     score, "/tmp/variations",
...     keys=["C", "G"],
...     tempos=[100, 120],
...     grooves=["Swing"],
...     score_to_wav=engine,
... )
accompy.tools.generate_wav(score, output_path, *, groove='Swing', tempo=120, repeats=1, score_to_wav=None)[source]#

Generate a WAV file from a Score using a pluggable engine.

By default uses MMA (Musical MIDI Accompaniment). Pass a custom score_to_wav callable to use a different backend — for instance one built with make_converter_engine().

Parameters:
  • score (Score) – A Score with chord measures.

  • output_path (Union[str, Path]) – Destination WAV file path.

  • groove (str) – Groove / style name (interpretation depends on the engine).

  • tempo (int) – Tempo in BPM.

  • repeats (int) – Number of times to repeat the progression.

  • score_to_wav (Optional[ScoreToWav]) – Engine callable. Defaults to mma_score_to_wav().

Return type:

Path

Returns:

Path to the generated WAV file.

Example:

>>> from accompy import Score, generate_wav
>>> score = Score.from_string("| Dm7 | G7 | C^7 |")
>>> generate_wav(score, "/tmp/test.wav", groove="BossaNova", tempo=140)
PosixPath('/tmp/test.wav')

>>> # With a custom engine:
>>> from accompy.tools import make_converter_engine
>>> engine = make_converter_engine(audio_renderer="fluidsynth")
>>> generate_wav(score, "/tmp/test.wav", score_to_wav=engine, tempo=140)
accompy.tools.make_converter_engine(*, resolver=None, midi_gen=None, audio_renderer=None, soundfont=None, sr=44100)[source]#

Create a ScoreToWav engine from accompy’s converter pipeline.

This wraps the ChordSequence → NoteSequence → MidiData → AudioData converter chain into the same interface that generate_wav() expects, so you can swap it in place of the default MMA engine.

Parameters:
  • resolver (Optional[str]) – Chord resolver name (e.g. "pychord", "tonal").

  • midi_gen (Optional[str]) – MIDI generator name (e.g. "pretty_midi", "midiutil").

  • audio_renderer (Optional[str]) – Audio renderer name (e.g. "fluidsynth", "pretty_midi").

  • soundfont (Optional[str]) – Path to a SoundFont file (for FluidSynth-based renderers).

  • sr (int) – Sample rate.

Return type:

ScoreToWav

Returns:

A callable matching the ScoreToWav protocol.

Example:

>>> engine = make_converter_engine(audio_renderer="fluidsynth")
>>> generate_wav(score, "/tmp/out.wav", score_to_wav=engine, tempo=120)
accompy.tools.mma_score_to_wav(score, output_path, *, groove='Swing', tempo=120, repeats=1)[source]#

Render a Score to WAV using MMA (Musical MIDI Accompaniment).

Accepts any valid MMA groove name (e.g. "Bebop", "GypsyJazz"). Run mma -Dg to list available grooves.

Parameters:
  • score (Score) – A Score with chord measures.

  • output_path (Union[str, Path]) – Destination WAV file path.

  • groove (str) – MMA groove name (case-sensitive).

  • tempo (int) – Tempo in BPM.

  • repeats (int) – Number of times to repeat the progression.

Return type:

Path

Returns:

Path to the generated WAV file.

Raises:

RuntimeError – If MMA is not installed or the groove is invalid.