lxmf: Sideband voice messages (transcribe + Piper voice replies)

The LXMF gateway now handles Sideband push-to-talk voice messages end to end.

Inbound: a PTT message carries its audio in LXMF.FIELD_AUDIO
(`[audio_mode, bytes]`); `lxmf_transport.parse_audio_field` normalizes it and
the adapter transcribes it into an ordinary command when
`gateway.lxmf.voice.enabled` is set. HQ Opus/OGG goes through faster-whisper
(requirements/transcribe.txt); non-HQ Codec2 through the optional pycodec2
bindings (requirements/codec2.txt). No microphone stack is needed.

Outbound: a chat that last messaged by voice is answered with a synthesized
voice message when `gateway.lxmf.voice.reply_with_voice` is on (the default).
`voice_transport.build_synthesizer` speaks the reply with Piper and
`voice_transport.pcm_to_opus_ogg` encodes it to OGG/Opus (48 kHz, PyAV's
libopus); `lxmf_transport.audio_fields` attaches it as a Sideband HQ PTT
message, with the reply text as the content so a text-only client still sees
it. The reply mode follows the chat's most recent inbound message. A missing
synthesizer or any synthesis/encode failure is traced and the reply falls back
to text. Deps: requirements/tts.txt (piper-tts + PyAV), still no microphone.

Also make LXMF replies result-only (`LxmfAdapter.result_only`, overridable via
`gateway.lxmf.result_only: false`): send the skill's result line, dropping
scheduler bookkeeping and the `<skill>: ok —` wrapper.

Wiring: new config keys under `gateway.lxmf` (result_only) and
`gateway.lxmf.voice` (reply_with_voice, max_speak_chars, reply_bitrate, tts);
regenerated config.example.json; the setup interview asks how to handle voice
messages and the install plan adds `install_lxmf_tts` (bootstrap installs
requirements/tts.txt and downloads the reply voice); cli anchors the LXMF
voice_dir to .runtime/voice/tts.

Tests cover the audio field shape, the outbound queue, the adapter's
voice-chat tracking and synthesis fallbacks, result-only routing, the
synthesis/encode helpers, and the setup plan. Docs updated.
This commit is contained in:
gabby committed 2026-10-17 04:53:51 +00:00
1 parent b1a7bfd272
commit ed894bd329
21 files changed
+1804 -78

No files matched your search

+62
View File
@@ -99,6 +99,13 @@ class Answers:
# Gateway platforms to enable.
gateways: list[str] = field(default_factory=list)
# LXMF gateway: transcribe Sideband push-to-talk voice messages into
# commands (install `requirements/transcribe.txt`; faster-whisper only) and
# reply to a voice chat with a Piper voice message (install
# `requirements/tts.txt`; piper-tts + PyAV).
lxmf_voice: bool = False
lxmf_voice_reply: bool = True
# IANA timezone; empty uses the host zone.
timezone: str = ""
@@ -462,6 +469,29 @@ def run_interview(
default=answers.gateways,
)
# 5b. LXMF voice messages (Sideband push-to-talk).
if "lxmf" in answers.gateways:
output("")
output("LXMF voice messages")
output(
" Sideband can send push-to-talk voice messages. The agent can\n"
" transcribe them into commands, and reply to a voice chat with a\n"
" synthesized voice message (Piper)."
)
mode = _ask_choice(
input_fn,
output,
"lxmf voice",
[
("off", "ignore voice messages"),
("transcribe", "transcribe to commands, reply with text"),
("reply", "transcribe, and reply with a synthesized voice"),
],
3,
)
answers.lxmf_voice = mode in ("transcribe", "reply")
answers.lxmf_voice_reply = mode == "reply"
# 6. Timezone.
output("")
answers.timezone = _ask_text(
@@ -568,6 +598,12 @@ def build_config(answers: Answers, packs: Sequence[SkillPack]) -> dict:
for platform in ("simplex", "lxmf", "voice"):
gateway.setdefault(platform, {})["enabled"] = platform in answers.gateways
gateway.setdefault("humanize", {})["enabled"] = bool(answers.gateways)
# Sideband voice messages are transcribed only when the LXMF gateway is on
# and the answer opted in; needs faster-whisper (requirements/transcribe.txt).
# A voice reply adds Piper + PyAV (requirements/tts.txt).
voice_block = gateway.setdefault("lxmf", {}).setdefault("voice", {})
voice_block["enabled"] = bool("lxmf" in answers.gateways and answers.lxmf_voice)
voice_block["reply_with_voice"] = bool(answers.lxmf_voice_reply)
return config
@@ -632,6 +668,17 @@ def build_plan(answers: Answers, packs: Sequence[SkillPack]) -> dict:
"install_simplex_forward": "simplex" in answers.packs,
"install_browser": "browser" in answers.packs,
"install_voice": "voice" in answers.gateways,
# faster-whisper only (no microphone stack): transcribe Sideband voice
# messages when the LXMF gateway is on and the answer opted in.
"install_transcribe": "lxmf" in answers.gateways and bool(answers.lxmf_voice),
# Piper + PyAV (no microphone stack): reply to a voice chat with a
# synthesized voice message when the LXMF gateway handles voice and the
# answer wants voice replies.
"install_lxmf_tts": (
"lxmf" in answers.gateways
and bool(answers.lxmf_voice)
and bool(answers.lxmf_voice_reply)
),
}
@@ -665,6 +712,21 @@ def plan_from_config(config: dict, packs: Sequence[SkillPack]) -> dict:
"install_simplex_forward": "simplex" in enabled,
"install_browser": "browser" in enabled,
"install_voice": "voice" in gateways,
"install_transcribe": bool(
(((config.get("gateway", {}) or {}).get("lxmf", {}) or {})
.get("voice", {}) or {})
.get("enabled")
),
"install_lxmf_tts": bool(
(((config.get("gateway", {}) or {}).get("lxmf", {}) or {})
.get("voice", {}) or {})
.get("enabled")
)
and bool(
(((config.get("gateway", {}) or {}).get("lxmf", {}) or {})
.get("voice", {}) or {})
.get("reply_with_voice", True)
),
}