Python SDK ยท Game audio

Authentic music for your game, crafted in code.

While you focus on your game's logic, BeatCraft composes melodies and full soundtracks that match your game's genre, mood and emotion.

pip install beatcraft
BeatCraft: pip install beatcraft, compose a melody, set the game genre and play

How it works

Pick a melody engine, describe your game, and BeatCraft turns it into MIDI and then a full audio track.

๐Ÿงฌ

Genetic algorithm

The default engine evolves melodies over generations, scoring phrases against the scale for your game's emotion.

๐ŸŽผ

Backtracking

A rule-based engine that searches for phrases that fit musical constraints.

๐Ÿค–

Transformer

A GPT-2 based model that generates melodies in ABC notation, with built-in evaluation and plots.

๐Ÿ”Š

Full soundtrack

Turns your melody into a 30-second track with MusicGen, guided by your game's genre and mood.

From install to melody in seconds

Install from PyPI, create the SDK and call compose_melody(). You get back a list of notes, each one a (duration, MIDI pitch) pair, saved as a MIDI file you can play right away.

Terminal recording: installing BeatCraft with pip and generating a melody

Quickstart

Four steps from an empty script to a finished soundtrack.

Install

If you hit dependency conflicts, install with a constraints file.

# constraints.txt
pandas==2.2.3
numpy>=1.26.0
matplotlib==3.9.2
gradio==4.44.0
torchmetrics==1.4.2
encodec==0.1.1

pip install beatcraft -c constraints.txt

Configure & compose a melody

Describe your game with BeatCraftConfig, then compose.

from beat_craft_sdk.core import BeatCraft
from beat_craft_sdk.config import BeatCraftConfig, GameGenre, GameMood, GameEmotional

config = BeatCraftConfig(file_name='output_bt')
config.set_game_genre(GameGenre.ACTION)
config.set_game_mood(GameMood.TENSE)
config.set_game_emotional(GameEmotional.FEAR)

sdk = BeatCraft(config)
notes, results, summary = sdk.compose_melody()
# [(1, 65), (1, 67), (0.5, 64), (0.25, 67), ...]

Pick an engine (optional)

The genetic algorithm is the default. Swap it for another engine at any time.

from beat_craft_sdk.crafting_with_backingtrack import CraftingBackingTrack
from beat_craft_sdk.crafting_with_transformer import CraftingTransformer

sdk.set_melody_engine(CraftingBackingTrack())
# or: sdk.set_melody_engine(CraftingTransformer())
notes, results, summary = sdk.compose_melody()

Listen & generate the full track

Play the MIDI, convert it to WAV, and let BeatCraft build the soundtrack around it.

from beat_craft_sdk.utils.audio_converter import AudioConverter

sdk.play_generated_music('../.outputx/output_bt.mid')

conv = AudioConverter('../.outputx/output_bt.mid', '../.outputx/output_bt.wav')
conv.midi_to_wav()

sdk.generate_rythm('output_bt')  # 30 s track + waveform, spectrogram and pitch plots

Describe your game

Three settings shape the music. The emotion picks the musical scale, while genre and mood steer the soundtrack.

GameEmotional

ValueScale
EXCITEMENTMajor
FEARMinor
PEACEFULPentatonic
CHALLENGEDorian

GameGenre

ValueCharacter
ACTIONEnergetic
RPGEpic
HorrorDissonant
PuzzleAmbient

GameMood

ValueFeel
JOYFULUpbeat and lively
SERENECalm and ambient
EPICGrand and orchestral
RELAXINGRelaxing
TENSEDark and suspenseful

Hear it for yourself

Listen to a soundtrack BeatCraft generated for a game with a fearful emotion, action genre and tense mood.