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 brings
its own page, MIDI and instruments, under Music. 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, and under More audio, soundfont and reverb. 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
ovosuser in its session, and PipeWire or PulseAudio is there. - If PHAL runs as a system service, it needs
XDG_RUNTIME_DIR(orPULSE_SERVER) pointing at the user's sound server, or the user in theaudiogroup for plain ALSA. aplay -lorpaplay --versionas that user shows whether it can.
- On ovos-installer, raspOVOS and a Mark II, PHAL runs as the desktop or
- MIDI keyboards and instruments: ALSA's sequencer (
/dev/snd/seq) and the USB MIDI devices (/dev/snd/midiC*). These are open to theaudiogroup (sudo usermod -aG audio ovos, then log in again) and to the user at the desk (systemd-logind).aconnect -las 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/sndand theaudiogroup (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.pyis 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.pyis 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.pykeeps 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.pyholds the sound outputs.player.pyplays files: it hands their events to the engine a couple of seconds ahead, so stop is immediate.ports.pyhandles 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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ovos_phal_plugin_midi-0.2.0.tar.gz | 52.1 kB | With provenance | Details for ovos_phal_plugin_midi-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ovos_phal_plugin_midi-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ovos_phal_plugin_midi-0.2.0-py3-none-any.whl |
Total release size: 105.2 kB
Release files / ovos_phal_plugin_midi-0.2.0.tar.gz
| Download URL | ovos_phal_plugin_midi-0.2.0.tar.gz |
|---|---|
| Size | 52.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7519ecc26607a7be9b05a50a4b07fd388053b6a2ba7d3f9470818306742995b
|
|
BLAKE2b-256 checksum How to use checksums |
c3f2d40addd6cb8f3bcbb7b65a7da8e4db5bd9b455aa5894a8e50413abc2eb55
|
| 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 21, 2026.
Transparency logRelease files / ovos_phal_plugin_midi-0.2.0-py3-none-any.whl
| Download URL | ovos_phal_plugin_midi-0.2.0-py3-none-any.whl |
|---|---|
| Size | 53.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
553d892fbcdbab997eeca064a23cc9f5801465c98cd7bddbb464a0b7e3aa6e7f
|
|
BLAKE2b-256 checksum How to use checksums |
cc516c464345dcee05e262bcfa0889dee2f1af3dc159e99ca4ecfd793550a2cc
|
| 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 21, 2026.
Transparency logSecurity for ovos-phal-plugin-midi 0.2.0
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.
Attestation for ovos_phal_plugin_midi-0.2.0.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 21, 2026.
Transparency logA 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.