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.

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 --pre 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 --pre "ovos-phal-plugin-midi[ports]" python-rtmidi: MIDI keyboards and instruments plugged into the device
pip install --pre "ovos-phal-plugin-midi[sounddevice]" PortAudio: the lowest latency from the built-in synth
pip install --pre "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)

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 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
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.1.0a2

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.1.0a2
File Size Uploaded Provenance Actions
ovos_phal_plugin_midi-0.1.0a2.tar.gz 36.4 kB With provenance Details for ovos_phal_plugin_midi-0.1.0a2.tar.gz

Built distribution (wheel)

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

Total release size: 69.7 kB

Release files / ovos_phal_plugin_midi-0.1.0a2.tar.gz

Download URL ovos_phal_plugin_midi-0.1.0a2.tar.gz
Size 36.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3cd26a6b08793404960c6e7fadf7f00621f0b992882f94663b5597ae8c6ef18a
BLAKE2b-256 checksum
How to use checksums
095f2ca0dd497ac4367e0fb80bdfffbb8b94cd4aca4a76ed32c6af2686b64ca4
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 20, 2026.

Transparency log

Release files / ovos_phal_plugin_midi-0.1.0a2-py3-none-any.whl

Download URL ovos_phal_plugin_midi-0.1.0a2-py3-none-any.whl
Size 33.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69fc0b42280ee6e2f16a39fc6763bf66d247278ff8e442023e111f8fafcf8968
BLAKE2b-256 checksum
How to use checksums
0a45d779d3a6620ad3482d79d9e2c9ad6f44365240ca738ad58f169459ae4e5c
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 20, 2026.

Transparency log

Security for ovos-phal-plugin-midi 0.1.0a2

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.1.0a2.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 20, 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