.. _python-integration: Generate PCM from Python ======================== Submediant performs offline synthesis. You can compose a score, select an instrument and render samples entirely from Python, without a CLI subprocess, prerecorded audio, Pillow, or FFmpeg. Install the package as described in :doc:`runtime-setup`. Run the examples below from the repository root. Choose the API for the data you own ----------------------------------- * **New notes and instruments:** :class:`submediant.MusicalSong` plus :class:`submediant.EquipmentStudio` produces a result with a PCM array. * **An imported Wiggle performance:** :class:`submediant.SongData` plus :class:`submediant.Studio`, or :func:`submediant.replay`, returns verified WAV bytes. Decode that container to obtain PCM. * **A synthesis graph:** :func:`submediant.render_recipe` or :func:`submediant.render_asset` returns integer sample arrays directly. All three paths currently use mono audio at 24,000 Hz and signed 16-bit signal values. The returned Python types differ: do not write WAV bytes to a device expecting headerless PCM, or interpret integer samples as normalized floats. .. _pcm-from-notes: Compose notes and render PCM ---------------------------- This complete example builds three pitched-percussion notes, one xylophone, an explicit output endpoint, and a part-to-device binding. It writes a WAV and a headerless signed-16-bit little-endian file under ``build/python-api/``. .. literalinclude:: examples/compose_pcm.py :language: python Run it with:: python docs/sphinx/examples/compose_pcm.py The score uses integer sample frames: 6,000 frames is 0.25 seconds. ``pitch`` is a MIDI note number and ``velocity`` is a dimensionless value in [0, 1]. ``voice`` has an instrument-specific meaning; this xylophone requires ``bar-65`` for MIDI 65 and supports pitches 65–83. It is a percussion-family instrument even though its notes have pitch. Its natural ringing is deliberate; continuous bends are unsupported. The instrument owns its model and synthesis controls. The song owns notes and timing. The binding explicitly connects the ``melody`` part to ``xylo``. ``Endpoint`` and ``InstrumentFamily`` use their documented supporting-module imports; they are not package-root exports. The returned in-memory ``result.pcm`` is a read-only NumPy array with dtype ``