Skip to content

Release v0.122.0: spoken replies on a call are shaped for the phone band - #146

Merged
tesseractAZ merged 4 commits into
mainfrom
claude/v01220-readback-mastering
Nov 20, 2026
Merged

tesseractAZ merged 4 commits into
mainfrom
claude/v01220-readback-mastering

Conversation

@tesseractAZ

Copy link
Copy Markdown
Owner

Spoken replies on a call are shaped for the phone band

Everything the voice features say that has no recording goes through switchboard-tts (espeak-ng): the directory (411), the lights menu (43), dial-a-status (45), the announce line (46), the wake-up weather and calendar, and the voice assistant (47). Since 0.121.0 the handset announcements are mastered for the 300–3400 Hz band every phone here hears (all G.711 µ-law, wired and SIP). This release runs the same code on the spoken replies.

What changed

  • switchboard-tts passes espeak-ng's mono 16-bit output to announce_asterisk._master_speech, loaded from the web UI's directory so the two cannot drift apart. That is one ffmpeg process (band shaping and the resampler to 8 kHz), then the gain to -15 dBFS and the -1 dBFS limiter.
    • Fallback. Any failure gives exactly the pre-0.122 bytes: ffmpeg missing, exit ≠ 0, a timeout, unusable output, code that cannot load, or an exception. The old resampling moved, unchanged, into _resample_unmastered.
    • Time limit. ffmpeg gets 3 s per reply. The callers allow the whole synthesis 20 s (25 s for the assistant) and espeak alone may take 15 s, so the announcements' 10 s limit could turn a slow reply into a failed one.
    • Pause. A run past the limit pauses the mastering for 600 s across processes, kept as the mtime of a /tmp file opened with O_NOFOLLOW|O_NONBLOCK; only a regular file's mtime is moved. A link, a FIFO, a non-regular file, or a stamp dated in the future counts as no pause, and none of them can block a reply.
    • One log line per start. The first fallback creates a /tmp marker with O_CREAT|O_EXCL|O_NOFOLLOW, then writes its line. Each add-on start is a new container with an empty /tmp. If the marker cannot be created, every fallback logs.
    • Skipped quietly. Silence, clips under 20 ms and speech of 120 s or more skip the mastering without a log line.
  • The callers (agi_speech.say, switchboard-assistant.agi, switchboard-automation.agi) no longer capture switchboard-tts's stderr. It inherits theirs, which is Asterisk's stderr, the add-on journal, so switchboard-tts writes its lines there itself.
    • Why. Asterisk SIGHUPs the AGI's own pid on hangup and no AGI handles it. A note handed to the caller through a pipe was lost whenever the caller died first, and with it the once-per-start line. A stalled ffmpeg means 3 s of silence, which is just when a caller hangs up.
    • stdout. The child's stdout goes to /dev/null, because the AGI's stdout is the command channel and Asterisk ends an AGI at its EOF.
    • Side effect. The directory, dial-a-status, announce and wake-up features, which used to drop switchboard-tts's lines, now show them. switchboard-tts never writes the text to stderr, and an existing privacy test pins that.
  • announce_asterisk gains an optional per-call timeout (default None, which means MASTER_TIMEOUT_S, so announcements keep 10 s) and a _TIMED_OUT constant.

Review

Two review rounds, each with an adversarial verifier per lens.

  • Round 1: correctness, security and privacy, tests, docs. 12 findings confirmed or plausible, 2 refuted; all 12 fixed in the second commit.
  • Round 2: process lifecycle, a fresh end-to-end read, and completeness of the fixes.

Checked in the target environment before merge

The live add-on, running as uid 100 (the AGIs' user) under its AppArmor profile, with Python 3.12.16 (audioop) and ffmpeg 6.1.2. The new code was copied into a private test folder:

0.121.0 0.122.0
1.9 s reply 62 ms, -18.55 dBFS, peak -3.85 202 ms, -15.13 dBFS, peak -1.00
9.3 s reply 77 ms, -18.59 dBFS, peak -2.20 283 ms, -15.08 dBFS, peak -1.00
  • Same sample count; identical output on every run.
  • ffmpeg removed from PATH: the WAV file is byte-identical to the installed 0.121.0 output. One log line on the first fallback, none on the second.
  • ffmpeg that hangs: the reply is spoken after 3.14 s, byte-identical to 0.121.0. The next reply skips ffmpeg (63 ms) and logs nothing.
  • A caller that exits before switchboard-tts writes anything: the line still lands in that caller's stderr.

Tests

tests/test_tts_mastering.py, 23 tests:

  • the mastered path on a real ffmpeg (skipped cleanly without one), checking the level, the limit, the length, repeatability, and that the bytes equal _master_speech's;
  • every fallback giving the pre-0.122 bytes and logging once;
  • the 3 s limit and the pause carrying over to the next process;
  • links, FIFOs and future-dated stamps;
  • the import through MASTER_DIR;
  • silence and over-long speech skipped quietly;
  • the callers' subprocess.run arguments (stdout to /dev/null, stderr not captured);
  • the note landing in the journal after the caller has exited.

A mutation check with ffmpeg hidden from PATH and a green baseline killed all 15 mutants. They covered dropped mastered audio, a lost pause update, a followed link, a wrong MASTER_DIR, a missing sys.path insert, a narrowed guard, a missing O_NONBLOCK or O_EXCL, the 10 s limit, text in stderr, callers capturing stderr or inheriting stdout, and the announcements' default limit.

Full suite: 1564 passed, 30 skipped.

Docs

  • CHANGELOG ## 0.122.0, with 0.113.0 rotated into the archive.
  • DOCS.md (voice features), voice-operator.md ("How the replies are spoken"), and a cross-reference in paging-and-announcements.md.
  • how-its-built.md and the Dockerfile's ffmpeg comment.
  • Version 0.122.0.

🤖 Generated with Claude Code

tesseractAZ and others added 3 commits November 19, 2026 17:49
switchboard-tts runs the handset announcements' mastering (announce_asterisk,
v0.121.0) on espeak-ng's output: one ffmpeg process to the band and 8 kHz,
then the speech level set to the built-in prompts' -15 dBFS under a -1 dBFS
limiter. ffmpeg gets 3 s per reply (the callers allow the whole synthesis
20 s and espeak alone 15); a run past it pauses the mastering for 10 minutes
across processes (a file's mtime in /tmp). Any failure speaks the reply
exactly as before, byte for byte, with one Log tab line per start that the
three callers now pass on after a successful reply too. announce_asterisk
gains an optional per-call timeout; announcements keep their 10 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e order, tests

- The callers no longer capture switchboard-tts's stderr: it is theirs, the
  add-on journal, so the once-per-start note lands even when a hangup ends the
  AGI first (Asterisk SIGHUPs the AGI's own pid). Their stdout, the AGI
  channel, goes to /dev/null. The forwarding added in the previous commit is
  gone, and agi_speech's callers now show switchboard-tts's lines too.
- _pause opens with O_NONBLOCK and moves the mtime of a regular file only, so
  a FIFO at the pause file cannot block a reply.
- Native byte order throughout (wave already swaps); ffmpeg gets an s16le copy.
- Tests: a mastered reply is checked without a real ffmpeg, a second timeout
  restarts the pause, the link check uses a fresh target, a FIFO, the real
  import through MASTER_DIR, an error in switchboard-tts's own part, the
  callers' subprocess arguments, and the note landing after the caller is gone.
- Docs: how-its-built dates the shaping per path; the example log line has no
  caller prefix; CHANGELOG says where switchboard-tts's lines now appear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…paths, how-its-built

- The test helpers build and compare native-order PCM, as wave reads and
  writes it, and feed _master_speech the s16le copy switchboard-tts makes.
- The MASTER_DIR import test points PAUSE_FILE and NOTED_FILE at tmp_path, so
  it never reads or writes the machine's own /tmp markers.
- how-its-built: recognition and the spoken replies run as the asterisk
  user; handset announcements are rendered by the web UI, which runs as root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeQL py/overly-permissive-file. Nothing reads either file's contents: the
pause is the file's mtime (lstat), the note marker only has to exist, and
both are made and checked by the same user (the AGIs' uid 100).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tesseractAZ
tesseractAZ merged commit 8c83d92 into main Nov 20, 2026
11 checks passed
@tesseractAZ
tesseractAZ deleted the claude/v01220-readback-mastering branch November 20, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants