Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ jobs:
- name: End-to-end, computer
run: uv run pytest tests-e2e/test_computer.py -v -rs --basetemp=${{ runner.temp }}/e2e
- name: Evidence
if: failure()
# Always, not only on a failure: the echo canceller's recordings (audio.npz) are the data
# a better canceller is measured on, and the echo check no longer fails (specs/e2e.md,
# open question 4).
if: always()
uses: actions/upload-artifact@v7
with:
name: e2e-computer-evidence
path: ${{ runner.temp }}/e2e
if-no-files-found: ignore
retention-days: 30

e2e-reachy:
name: e2e (reachy)
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/computer.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ On macOS, the first run asks for microphone access, and camera access when visio

The microphone stays open while the voice plays, so the speaker's output travels through the air back into the microphone, the speech recognizer transcribes it, and it lands as something the person said: the agent reacts to its own voice. Echo cancellation taps what the voice is about to play as a reference signal and subtracts it from the microphone, in a WebRTC audio processor placed between the voice and the speech recognizer. It is on in the committed template and needs the `audio-processing` extra ([install.md](../reference/install.md#extras)).

The fields are `echo_cancellation.enabled` and `echo_cancellation.stream_delay_ms` ([reference](../reference/configuration.md#audio_processing-the-computers-mic-processing)). The delay is a hint: the reference is captured when the voice feeds its audio, which is ahead of what the microphone hears by the output buffer plus the acoustic path, and the canceller's delay estimator starts from the value you give it and absorbs the rest. The template's `50` suits a laptop's built-in audio; a Bluetooth speaker adds more. If the agent still answers itself with cancellation on, raise it in steps.
The fields are `echo_cancellation.enabled` and `echo_cancellation.stream_delay_ms` ([reference](../reference/configuration.md#audio_processing-the-computers-mic-processing)). You rarely need to touch the delay: the reference is captured as the voice plays, ahead of what the microphone hears by the output buffer plus the acoustic path, and the canceller measures that gap itself. The current canceller (WebRTC's AEC3) all but ignores `stream_delay_ms`; the template's `50` does no harm.

When the extra is not installed, or the WebRTC binding failed to build, the app still opens: the banner carries an `Audio processing:` line with the reason, and the microphone goes to the speech recognizer raw ([troubleshooting.md](troubleshooting.md#the-agent-hears-itself)). The speech recognizer must be configured for 16 kHz mono, the default, which is the processor's working rate; another format is reported on the same banner line.

Expand Down
4 changes: 2 additions & 2 deletions docs/guides/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ The page opens even when something could not be built, with one line per failure
- **They appear and clear, but no 🗣️ shows on the left.** The utterance never closed into a final segment, or it did while the agent was busy. A trigger arriving while a reasoning step is in flight is dropped, not queued ([limits.md](limits.md#one-reasoning-step-at-a-time)): wait for the previous reaction to finish and say it again.
- **A 🗣️ shows, a reaction opens, but there is no 🗣️ say.** Open the reaction: a **🚫 noop** means the model chose not to answer (ask directly); a 💭 item alone means it wrote free text instead of calling `say`, which the persona forbids and which a weaker model does anyway ([personas.md](personas.md)); a ❌ say shows the `TTS error: …` the voice returned.
- **The say runs but you hear nothing.** The computer: the speaker in `tts.engine.player.device`, the system volume, a voice whose `gain_db` is too low. The robot: the robot's speaker and the media session; on the `fake` backend nothing is heard by design.
- **Typed text works, speech does not.** Then the agent is fine and the problem is upstream of it: the microphone, the recognizer's key, or echo cancellation cleaning too much (a `stream_delay_ms` far from the real latency can eat speech, [computer.md](computer.md#echo-cancellation)).
- **Typed text works, speech does not.** Then the agent is fine and the problem is upstream of it: the microphone, the recognizer's key, or echo cancellation cleaning too much (with headphones it mutes you while the agent speaks: turn it off, [computer.md](computer.md#echo-cancellation)).

## The agent hears itself

The transcript shows the agent's own sentences coming back as 🗣️ input, and it answers them.

- **On the computer**, echo cancellation must be on: `audio_processing.echo_cancellation.enabled`, the `audio-processing` extra installed, and no `Audio processing:` banner line. Tune `stream_delay_ms` to your audio path's latency ([computer.md](computer.md#echo-cancellation)). Headphones remove the loop outright: with them, turn echo cancellation off, since with no echo to learn from it mutes you while the agent speaks.
- **On the computer**, echo cancellation must be on: `audio_processing.echo_cancellation.enabled`, the `audio-processing` extra installed, and no `Audio processing:` banner line ([computer.md](computer.md#echo-cancellation)). Short bursts can still leak through, mostly right after you talk over the agent: a known limit of the current canceller. Headphones remove the loop outright: with them, turn echo cancellation off, since with no echo to learn from it mutes you while the agent speaks.
- **On the robot**, the XVF3800 cancels the echo in hardware only when the voice plays through the robot's own media session, which is how the app plays it. A `tts.engine.player.device` has no place in a reachy config (the loader rejects it); the robot's volume still matters at the extremes.

## No camera frame, or no sign
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Computer only, optional: absent means both features off. One WebRTC processor cl
| Field | Default | What it does |
|---|---|---|
| `echo_cancellation.enabled` | `false` | subtract what the voice is playing from the mic, so the agent does not hear itself |
| `echo_cancellation.stream_delay_ms` | `0` | a hint for the canceller's delay estimator: the output latency of your audio path, in milliseconds |
| `echo_cancellation.stream_delay_ms` | `0` | the output latency of your audio path, in milliseconds, passed to the canceller as a hint; the current one (AEC3) measures the delay itself and all but ignores it |
| `noise_suppression.enabled` | `false` | attenuate steady ambient noise |
| `noise_suppression.level` | `2` | WebRTC's aggressiveness, `0` (mild) to `3` (max) |

Expand Down
21 changes: 21 additions & 0 deletions plans/202611101900_room-holds-echo-delay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The room holds its echo's delay

**Status:** Done

Implements the settled behavior in `specs/e2e.md` ("The room", "The echo's delay holds"): the end-to-end room keeps the app's echo at its 50 ms delay for the whole run, against the drift between its recording and playback streams and a late recording block. It leaves out drift on purpose (a room variant for two devices), which the spec defers.

## Scope

- `tests-e2e/room.py` — the `Mixer` holds the echo's delay, measured from recording to playback (PortAudio's ADC and DAC times): a one-sample resampled correction per block while its average is more than 0.5 ms off, the whole excess cut when it is more than 20 ms over; the old cut-back past 150 ms (`ECHO_SLACK_S`) goes; the room's log counts the hard corrections.
- `specs/e2e.md` — back to `Implemented` once done.

## Steps

1. In `Mixer`, replace the backlog cap in `heard` with a hold in `block`: `heard` takes the block's ADC time and `block` the DAC time of its first sample, so the echo's delay is measured from recording to playback (the backlog alone moves with the streams' phase). Lock the delay held after 100 blocks; track it with two averages (weights 0.01 and 0.03 per block), each adjusted by the room's own corrections so they never chase them; per block take `n + 1`, `n − 1` or `n` echo samples by the slow average's error (±24 samples at 48 kHz) and resample them to `n` (linear); when the fast average is more than 960 samples over, cut the whole excess as measured now and count it. Never pad a shortfall at once.
2. The room's log: the `rec` rows' last column becomes the count of hard corrections so far (it was "cut"); the module docstring says so.
3. Check offline: drive the `Mixer` with a recording stream 400 ppm faster than its playback, and with a 90 ms late block, and read the delay of what it plays back (cross-correlation): it holds within a millisecond, and the late block is corrected at once.
4. One CI run: the room's log shows the backlog flat at the delay, and the echo's delay measured on the app's side (the cross-correlation of `audio.npz`'s mic and reference, window by window) no longer creeps.

## Verification

`uv run ruff check .`, `uv run ruff format --check .`, `uv run pyright`, `uv run pytest`; the offline check of step 3; and one manual CI run (`gh workflow run ci.yml --ref <branch>`) whose computer evidence shows the delay held. Mark this plan `Done` (here and in [_index.md](_index.md)) and `specs/e2e.md` back to `Implemented` once all pass.
1 change: 1 addition & 0 deletions plans/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Implementation plans for WICA Interaction (formerly Reachy Mini Interaction WICA
| [202611100025_e2e-tier.md](202611100025_e2e-tier.md) | The end-to-end tier ([specs/e2e.md](../specs/e2e.md), [specs/ci.md](../specs/ci.md)): both embodiments with only the devices replaced — the cable and the room, a file as the webcam, hand photos in the sim; three focused scenarios and one conversation per body; its two CI jobs on `main` and by hand | Done |
| [202611100046_ci-source-build-cache.md](202611100046_ci-source-build-cache.md) | CI's uv cache keyed on the sdist-only packages' locked entries (`aec-audio-processing`, PyGObject, pycairo), not the whole `uv.lock` ([specs/ci.md](../specs/ci.md)): a sibling bump no longer costs a two-minute rebuild on every job | Done |
| [202611101225_input-wordings.md](202611101225_input-wordings.md) | The input wordings ([specs/app.md](../specs/app.md), [specs/asr-bridge.md](../specs/asr-bridge.md), [specs/gesture-input.md](../specs/gesture-input.md)): speech heard, gestures detected, a dictated passage marked complete | Done |
| [202611101900_room-holds-echo-delay.md](202611101900_room-holds-echo-delay.md) | The end-to-end room holds its echo's delay ([specs/e2e.md](../specs/e2e.md), "The room"): its echo backlog averaged and corrected one sample at a time against the two streams' clock drift, a late block cut or padded back at once, its log reporting the corrections | Done |
| _(add plans here — see [_plan-template.md](_plan-template.md))_ | | |

## Status legend
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ target-version = "py312" # keep in sync with requires-python
[tool.pytest.ini_options]
# Only the fast, deterministic tier is collected by default; tests-e2e/ is opt-in.
testpaths = ["tests"]
# sounddevice 0.5.6 raises this NumPy 2.5 deprecation in every audio callback (`data.shape = …`).
# A plain run ignores it, but pytest records each one (~17k in an end-to-end conversation) and
# processes them at the end of each test, freezing the process ~300 ms while the app's audio
# streams run: its mic then stays ~85 ms behind, and the echo canceller relearns. Fixed upstream
# (spatialaudio/python-sounddevice#641), not yet released: drop this filter once a sounddevice
# release after 0.5.6 is in uv.lock.
filterwarnings = [
"ignore:Setting the shape on a NumPy array has been deprecated:DeprecationWarning:sounddevice",
]

[tool.pyright]
include = ["src", "tests", "tests-e2e"] # type-check test code too, not just src
Expand Down
2 changes: 1 addition & 1 deletion specs/audio-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ With every feature **disabled** (the default), the embodiment's `mic` is `None`

1. **Resample the reference, not the playback.** Playback stays at the module's rate (full fidelity); only the *reference copy* is downsampled to 16 kHz with a **stateful** `samplerate` resampler (one `Resampler` carrying filter state across chunks), so a long utterance resamples without drift or boundary artifacts — drift would de-align the reference from the mic, which AEC punishes. (`samplerate` is MIT + BSD-2 libsamplerate; `soxr` was rejected as LGPL, `scipy` as ~90 MB for one function.)
2. **Re-chunk to 10 ms frames.** A 100 ms mic chunk is ten 160-sample frames; the coordinator buffers near-end samples and processes complete frames only.
3. **Alignment from what plays + delay hint (AEC).** The reference is taken as the voice's stream sends each block to the device — ahead of what the mic hears by the output buffering and the acoustic path, and by a constant amount, since the stream stays open; WebRTC's delay estimator, seeded by `stream_delay_ms`, absorbs that — the reason for a WebRTC-class processor over a bare adaptive filter.
3. **Alignment from what plays (AEC).** The reference is taken as the voice's stream sends each block to the device — ahead of what the mic hears by the output buffering and the acoustic path, and by a constant amount, since the stream stays open; AEC3's own delay estimator finds and absorbs that — the reason for a WebRTC-class processor over a bare adaptive filter. `stream_delay_ms` is passed through to the module, but AEC3 on its default settings all but ignores it (it uses an external delay only with `delay.use_external_delay_estimator`, which the binding does not expose): replaying the same audio with the hint at 0 to 500 ms changes the residual by 0.1 dB. The field stays, harmless, for a backend that uses it.

## The module: `computer/audio_processing.py`

Expand Down
2 changes: 1 addition & 1 deletion specs/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ One file, `.github/workflows/ci.yml`. It triggers on `pull_request`, on `push` t
- **Real-clock margins are sized for the hosted Mac.** The `macos-15` runner is a virtual machine whose short sleeps run several times long (the bridge measured a 10 ms sleep taking 34). A fast-tier test that asserts something has *not yet* happened inside a window — a hold, a stall — keeps that window at 0.5 s or more, so the check lands inside it there too.
- **Paths are compared as POSIX.** A test that compares file paths with Markdown or frontmatter text builds them with `as_posix()`, so the Windows entry sees the same strings.
- **Caches.** The uv setup action caches uv's cache, which its CI prune reduces to the wheels uv built itself. The ones that cost minutes are the sdist-only packages — `aec-audio-processing` on Linux and macOS (about two minutes), PyGObject and pycairo on Linux — so the cache is **keyed on their locked entries**, not on the whole `uv.lock`: a sibling bump, which changes the lock and nothing they build from, keeps the cache, and pull requests reuse `main`'s. The workflow names the packages in one pattern; a new sdist-only dependency joins it, or it rebuilds on every run.
- **The end-to-end jobs on Linux only.** The tier's devices are virtual: a PulseAudio null sink is the cable the person plays into, a source remapped over its monitor is the app's mic, a second null sink is the app's speaker, and its monitor is the echo device the room records the computer's voice from, to put it back on the cable ([e2e.md](e2e.md), "The room"). PortAudio, under `sounddevice`, lists ALSA devices only, so each gets an ALSA name (`wica_cable`, `wica_mic`, `wica_speaker`, `wica_echo`) through the ALSA pulse plugin (`libasound2-plugins`), written to `~/.asoundrc`; the jobs set the tier's `WICA_E2E_*_DEVICE` variables to them. The robot's job also makes each device findable by the bridge and the sim's daemon, and the mic and the speaker the defaults: they find devices through upstream's GStreamer listing, which matches PulseAudio's description, skips monitor sources (hence the remapped source), and on a host without PipeWire takes a virtual device only through its `device.string` (no `udev.id` or profile, as hardware has); so the mic and the speaker carry a description and a `device.string` equal to their name, which is both their PulseAudio and their ALSA name. It is the bridge's own live job otherwise (`reachy-mini-bridge/.github/workflows/ci.yml`, `e2e-sim`): Mesa's EGL renders the sim's camera offscreen, `gstreamer1.0-pulseaudio` and the ICE library serve the daemon's media, upstream's pinned action installs the Rust webrtc plugin no Ubuntu archive ships, and `REACHY_MINI_E2E_REQUIRED_CAPS=audio,camera,props:hand` fails a sim that comes up without them. macOS is the development machine, with BlackHole, and Windows would need VB-Audio's cable, so neither runs the job ([e2e.md](e2e.md), "Platforms"). The Hugging Face cache (the hand models, the phonon voice) is kept across runs, keyed on `uv.lock` with a fallback to the last one. On a failure the scenarios' evidence is uploaded as an artifact.
- **The end-to-end jobs on Linux only.** The tier's devices are virtual: a PulseAudio null sink is the cable the person plays into, a source remapped over its monitor is the app's mic, a second null sink is the app's speaker, and its monitor is the echo device the room records the computer's voice from, to put it back on the cable ([e2e.md](e2e.md), "The room"). PortAudio, under `sounddevice`, lists ALSA devices only, so each gets an ALSA name (`wica_cable`, `wica_mic`, `wica_speaker`, `wica_echo`) through the ALSA pulse plugin (`libasound2-plugins`), written to `~/.asoundrc`; the jobs set the tier's `WICA_E2E_*_DEVICE` variables to them. The robot's job also makes each device findable by the bridge and the sim's daemon, and the mic and the speaker the defaults: they find devices through upstream's GStreamer listing, which matches PulseAudio's description, skips monitor sources (hence the remapped source), and on a host without PipeWire takes a virtual device only through its `device.string` (no `udev.id` or profile, as hardware has); so the mic and the speaker carry a description and a `device.string` equal to their name, which is both their PulseAudio and their ALSA name. It is the bridge's own live job otherwise (`reachy-mini-bridge/.github/workflows/ci.yml`, `e2e-sim`): Mesa's EGL renders the sim's camera offscreen, `gstreamer1.0-pulseaudio` and the ICE library serve the daemon's media, upstream's pinned action installs the Rust webrtc plugin no Ubuntu archive ships, and `REACHY_MINI_E2E_REQUIRED_CAPS=audio,camera,props:hand` fails a sim that comes up without them. macOS is the development machine, with BlackHole, and Windows would need VB-Audio's cable, so neither runs the job ([e2e.md](e2e.md), "Platforms"). The Hugging Face cache (the hand models, the phonon voice) is kept across runs, keyed on `uv.lock` with a fallback to the last one. On a failure the scenarios' evidence is uploaded as an artifact; the computer's job uploads it on every run, kept 30 days, since its `audio.npz` recordings are the data a better echo canceller is measured on ([audio-processing.md](audio-processing.md), open question 3).
- **Timeouts.** Each job carries a `timeout-minutes` well under GitHub's default, so a hung job fails in minutes.

### Secrets and protection
Expand Down
Loading
Loading