Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

ovos-phal-plugin-midi

An OpenVoiceOS PHAL plugin that gives the device a MIDI instrument on its message bus.

It is part of Emkay, and works on any OpenVoiceOS.

Skills can play music on it note by note, timed to the millisecond and changed while it plays, or give it a MIDI file. It plays them on:

  • a real instrument plugged into the device: a USB keyboard, a synth, a drum module, or anything else that speaks MIDI;
  • FluidSynth with a SoundFont (real instrument samples), when it is installed;
  • otherwise its own synthesizer: every General MIDI instrument and a drum kit, made in numpy, with a little room reverb. It needs nothing installed and nothing downloaded.

A keyboard plugged into the device works the other way too. What you play goes on the bus, so a skill can follow it, and with thru the device plays it.

Skills that play on it: ovos-skill-karaoke (the device sings, or you do) and ovos-skill-jamband (a band you lead with your voice).

Why a plugin, and why software?

Sound cards used to have a synthesizer chip, but that has been gone from ordinary computers for twenty years. A Raspberry Pi or a Mark II never had one. Today a computer plays MIDI with software: Windows and macOS have one built in, Linux uses FluidSynth or TiMidity. MIDI itself is alive and well as the language of keyboards and synths, over USB.

So this plugin is the device's synth and MIDI port in one. It runs once, in OVOS' PHAL service, and every skill can use it over the bus. That is what makes music that changes while it plays possible. A skill sends the next bar a moment ahead. When it changes its mind ("add strings"), it takes back what it sent (ovos.midi.cancel) and sends the bar again. The sound never stops or restarts, which a skill handing finished audio files to the player cannot do.

Install

pip install ovos-phal-plugin-midi

That is all the built-in synth needs. Restart OVOS' PHAL service (systemctl --user restart ovos-phal on ovos-installer and raspOVOS).

Optional, for more:

pip install "ovos-phal-plugin-midi[ports]" python-rtmidi: MIDI keyboards and instruments plugged into the device
pip install "ovos-phal-plugin-midi[sounddevice]" PortAudio: the lowest latency from the built-in synth
pip install "ovos-phal-plugin-midi[fluidsynth]" + sudo apt install fluidsynth fluid-soundfont-gm (Fedora: sudo dnf install fluidsynth-libs fluid-soundfont-gm) FluidSynth with the FluidR3 SoundFont: real instrument samples. It is used by itself once it is there

Configure

Nothing has to be set. To change something, in mycroft.conf:

{
  "PHAL": {
    "ovos-phal-plugin-midi": {
      "synth": "auto",
      "audio": "auto",
      "output_port": "",
      "inputs": ["*"],
      "thru": false
    }
  }
}
Setting
synth auto (the default) uses a MIDI port if output_port names one that is plugged in, else FluidSynth if it and a SoundFont are there, else the built-in synth. You can also choose port, fluidsynth or builtin.
audio where the built-in synth's sound goes. auto (the default) tries sounddevice, then paplay (PulseAudio and PipeWire), pw-cat, aplay (plain ALSA), in that order. In a browser it uses bus.
audio_device a PortAudio device for sounddevice (name or number)
soundfont a .sf2 file for FluidSynth (default: the first of the usual places, e.g. /usr/share/sounds/sf2/FluidR3_GM.sf2)
output_port a MIDI output port: its name or part of it, e.g. "Roland"
inputs the input ports to listen to, as names or globs (default ["*"]: all; []: none)
thru play what comes in from a keyboard on the device's own synth (default false)
gain, reverb the built-in synth's level (0.45) and room (true)
fluidsynth_gain FluidSynth's level (0.8): the two sound about as loud
duck, duck_volume turn the music down while OVOS speaks or listens (true), and how far (0.3)
sample_rate the built-in synth's sample rate (24000)

In the control panel

With ovos-control-panel on the device, the plugin has its own page, MIDI and instruments, under Music. It is described in controlpanel.json (strings in locale/<lang>/controlpanel.json) and drawn by the panel; no code of the plugin runs in the panel. It shows what plays the music (the built-in synth, FluidSynth and its SoundFont, or an instrument on a MIDI port), where the sound goes, the delay, and the keyboards and instruments plugged in, with what to install when something is missing. It plays a chord or a drum fill to try it, and stops all sound. It sets what is above: synth, output_port, listening to keyboards, thru, ducking and how far, reverb and audio, and soundfont when FluidSynth is chosen. They are saved in mycroft.conf with the panel's backups (only what differs from the defaults), and the plugin starts again with them at once (ovos.midi.reload), no restart. The page is in 11 languages.

Permissions

The plugin runs inside OVOS' PHAL service, as the same user. What that user needs depends on what you use:

  • Sound (the built-in synth or FluidSynth): the same access as OVOS' own speech.
    • On ovos-installer, raspOVOS and a Mark II, PHAL runs as the desktop or ovos user in its session, and PipeWire or PulseAudio is there.
    • If PHAL runs as a system service, it needs XDG_RUNTIME_DIR (or PULSE_SERVER) pointing at the user's sound server, or the user in the audio group for plain ALSA.
    • aplay -l or paplay --version as that user shows whether it can.
  • MIDI keyboards and instruments: ALSA's sequencer (/dev/snd/seq) and the USB MIDI devices (/dev/snd/midiC*). These are open to the audio group (sudo usermod -aG audio ovos, then log in again) and to the user at the desk (systemd-logind). aconnect -l as that user lists what it can see.
  • Docker (ovos-docker): the PHAL container needs the sound server's socket, as the audio container has it, and for MIDI devices --device /dev/snd and the audio group (group_add: [audio]).
  • Emkay (a browser): no device access at all. The sound comes over the bus to Emkay's page, which plays it. Emkay starts the plugin by itself when it is installed (with a skill that needs it, or from the panel), and at every start after that. Emkay sees no keyboards yet.

The plugin opens no network port and sends nothing off the device.

Anyone who can put messages on the bus can make the device play music, as they can make it speak. What you play on a keyboard goes on the bus too (ovos.midi.input), but nowhere else. Set "inputs": [] to keep the keyboards to yourself.

Rights

The plugin is Apache-2.0. Its built-in instruments are made by its own code, not recorded, so there is nothing else to license. A SoundFont you install for FluidSynth has its own license. Debian's and Fedora's fluid-soundfont-gm (FluidR3_GM) is MIT, and timgm6mb-soundfont is GPL-2. Both are fine to use. The music is whoever's music it is: the plugin plays the files it is given and keeps nothing.

The bus

All times are wall-clock seconds (time.time()) on the device. All channels are 0-15, with channel 9 as the drum kit, as in General MIDI.

Message Data
ovos.midi.events source, at (default: now + latency), events play events (below) at at + their own time
ovos.midi.cancel source, after (default: now) take back that source's events from then on; answers cancelled (how many)
ovos.midi.play uri / path / data (base64), source, at, loop, transpose, tempo, mute (channels) play a .mid or .kar file from at (default: as soon as it can). Answers ovos.midi.play.started (at, duration) or .failed (error); ovos.midi.play.ended when it ends
ovos.midi.clip path / uri / data (base64 WAV), source, at, gain recorded sound, heard from at on, in the same output as the music and in time with it (a voice singing to it). Answers at, duration (or error; a MIDI port plays no clips)
ovos.midi.stop source stop that source's file and notes; with no source, everything
ovos.midi.panic stop everything, all notes off
ovos.midi.status answers with the engine, latency, sample_rate, time (the device's clock), what is playing, the ports, the settings in use, found_soundfont, have_fluidsynth and an error when the sound could not start
ovos.midi.reload config: the plugin's section starts the synth, the sound and the ports again with it; answers as status
ovos.midi.ports answers inputs, outputs
ovos.midi.input port, type, channel, note, velocity, control, value, program sent by the plugin: what a keyboard played
ovos.midi.pcm seq, sample_rate, at, pcm (base64 s16le mono) sent by the plugin with "audio": "bus": the sound, for a client that plays it

While OVOS speaks or listens (recognizer_loop:audio_output_start, record_begin, and the ovos.audio.output.* / ovos.listener.* names) the music goes down, as ovos-audio does with its own.

mycroft.stop also stops what plays from files. A skill's own notes are its skill's to stop, with ovos.midi.stop.

Events, each with t as seconds after at:

["note", t, channel, note, velocity, seconds]   a note with its length
["on", t, channel, note, velocity]              note on (velocity 0: off)
["off", t, channel, note]
["program", t, channel, program]                 a General MIDI instrument, 0-127
["cc", t, channel, controller, value]            7 volume, 11 expression, 64 sustain pedal, 123 all notes off
["all_off", t, channel]                          channel -1: every channel

A bar of blues in D, starting in half a second:

import time
bus.emit(Message("ovos.midi.events", {"source": "my-skill", "at": time.time() + 0.5, "events": [
    ["program", 0, 0, 0], ["program", 0, 1, 32],                       # piano, acoustic bass
    ["note", 0.0, 0, 62, 80, 1.8], ["note", 0.0, 0, 66, 80, 1.8], ["note", 0.0, 0, 72, 80, 1.8],
    ["note", 0.0, 1, 38, 100, 0.45], ["note", 0.5, 1, 42, 90, 0.45],
    ["note", 1.0, 1, 45, 90, 0.45], ["note", 1.5, 1, 47, 90, 0.45],
    ["note", 0.0, 9, 36, 110, 0.1], ["note", 0.5, 9, 38, 100, 0.1],
    ["note", 1.0, 9, 36, 110, 0.1], ["note", 1.5, 9, 38, 100, 0.1],
]}))

To find out how far ahead to send, ask ovos.midi.status for latency and send at least that far ahead. A skill that sends a bar or two ahead and uses ovos.midi.cancel when the music changes is always on time and still answers quickly.

How it works

  • synth.py is the built-in synth: 16 channels, program, volume, expression and sustain pedal. A note's samples are made once (instruments.py, the same instruments as ovos-skill-karaoke's band) and kept, so playing is cheap.
  • fluid.py is FluidSynth as an instrument. It makes its samples here, a block at a time, instead of through its own audio driver, so its notes land on their sample too and get the same clips and ducking.
  • engine.py keeps the timeline of events. The engine mixes the instrument (the built-in synth or FluidSynth) with clips and ducks it, a block at a time, to an audio output. A MIDI port gets its notes sent at their time.
  • audio.py holds the sound outputs.
  • player.py plays files: it hands their events to the engine a couple of seconds ahead, so stop is immediate.
  • ports.py handles keyboards and instruments, and looks for newly plugged ones every few seconds.

Development

pip install -e ".[test]"
pytest -q tests

Metadata

Release files for ovos-phal-plugin-midi 0.3.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ovos-phal-plugin-midi 0.3.0a1
File Size Uploaded Provenance Actions
ovos_phal_plugin_midi-0.3.0a1.tar.gz 47.4 kB With provenance Details for ovos_phal_plugin_midi-0.3.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ovos-phal-plugin-midi 0.3.0a1
File Interpreter ABI Platform Actions
ovos_phal_plugin_midi-0.3.0a1-py3-none-any.whl Python 3 none any Details for ovos_phal_plugin_midi-0.3.0a1-py3-none-any.whl

Total release size: 95.3 kB

Release files / ovos_phal_plugin_midi-0.3.0a1.tar.gz

Download URL ovos_phal_plugin_midi-0.3.0a1.tar.gz
Size 47.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ddee1380334794a23b02a079eb3811ed3c15028c035658a064e1ee5851bde8c7
BLAKE2b-256 checksum
How to use checksums
0dbc03fc036db9d03106b238d2a6280976959ee6fe96cbaf3a31d72bafd8ef56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / ovos_phal_plugin_midi-0.3.0a1-py3-none-any.whl

Download URL ovos_phal_plugin_midi-0.3.0a1-py3-none-any.whl
Size 47.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a6b66293212e23afcdbaf7a82a1c9fc78563c291669598d4d67ecb22de23d1e
BLAKE2b-256 checksum
How to use checksums
6f9d53257f03b9523ef69971bb07c1e8360e640fedda86a96600a630a4621be9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for ovos-phal-plugin-midi 0.3.0a1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ovos_phal_plugin_midi-0.3.0a1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page