-
Notifications
You must be signed in to change notification settings - Fork 803
feat(collection): add optional speech for WebXR and desktop controls #4156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d2be723
feat(teleop): add optional offline speech for WebXR collection
TomCC7 7f69992
refactor(tts): scope enable setting to the speech module
TomCC7 f84e12d
fix(tts): declare CPU ONNX Runtime explicitly in speech extra
TomCC7 af934c8
feat(tts): add verified one-command model setup
TomCC7 ba2d3a9
fix(tts): reconcile dependency pins and paths after rebase
TomCC7 44ba883
fix(tts): download model assets automatically before startup
TomCC7 42f1386
refactor(webxr): own TTS locally and push prepared recording audio
TomCC7 63661e5
refactor(tts): use official Kokoro and shared Hugging Face assets
TomCC7 ef06c4f
fix(tts): install English tokenizer lazily through spaCy
TomCC7 f527ae0
Merge branch 'cc/feat/abc-policy' into cc/feat/webxr-audio
TomCC7 7ce6063
feat(collection): share recording speech with desktop controls
TomCC7 68c4e62
test(collection): trim redundant speech checks
TomCC7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright 2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Spoken feedback for confirmed collection transitions.""" | ||
|
|
||
| from dimos.msgs.imitation_msgs.EpisodeStatus import EpisodeStatus | ||
| from dimos.stream.audio.tts.kokoro import KokoroTTS, KokoroTTSConfig | ||
|
|
||
| RECORDING_PROMPTS = { | ||
| "start": "Recording started", | ||
| "save": "Episode saved", | ||
| "discard": "Recording canceled", | ||
| } | ||
|
|
||
|
|
||
| class CollectionPrompts: | ||
| def __init__(self) -> None: | ||
| self.previous: EpisodeStatus | None = None | ||
|
|
||
| def update(self, status: EpisodeStatus) -> str | None: | ||
| previous = self.previous | ||
| self.previous = status | ||
| if previous is not None and ( | ||
| status.state, | ||
| status.last_event, | ||
| status.episodes_saved, | ||
| status.episodes_discarded, | ||
| ) == ( | ||
| previous.state, | ||
| previous.last_event, | ||
| previous.episodes_saved, | ||
| previous.episodes_discarded, | ||
| ): | ||
| return None | ||
| if status.last_event == "start" and status.state == "recording": | ||
| return RECORDING_PROMPTS["start"] | ||
| if previous is not None: | ||
| if status.last_event == "save" and status.episodes_saved > previous.episodes_saved: | ||
| return RECORDING_PROMPTS["save"] | ||
| if ( | ||
| status.last_event == "discard" | ||
| and status.episodes_discarded > previous.episodes_discarded | ||
| ): | ||
| return RECORDING_PROMPTS["discard"] | ||
| return None | ||
|
|
||
|
|
||
| class CollectionSpeech: | ||
| """Prepare collection feedback once, then select WAVs for confirmed transitions.""" | ||
|
|
||
| def __init__(self, config: KokoroTTSConfig) -> None: | ||
| self._config = config | ||
| self._prompts = CollectionPrompts() | ||
| self._audio: dict[str, bytes] = {} | ||
|
|
||
| def prepare(self) -> None: | ||
| if not self._config.enabled: | ||
| return | ||
| speech = KokoroTTS(self._config) | ||
| try: | ||
| speech.prepare() | ||
| self._audio = { | ||
| phrase: speech.synthesize(phrase) for phrase in RECORDING_PROMPTS.values() | ||
| } | ||
| finally: | ||
| # All feedback is cached; collection needs no live inference engine. | ||
| speech.close() | ||
|
|
||
| def update(self, status: EpisodeStatus, *, snapshot: bool = False) -> bytes | None: | ||
| phrase = self._prompts.update(status) | ||
| return self._audio.get(phrase) if phrase is not None and not snapshot else None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Copyright 2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import pytest | ||
|
|
||
| from dimos.imitation.collection.prompts import CollectionSpeech | ||
| from dimos.msgs.imitation_msgs.EpisodeStatus import EpisodeStatus | ||
| from dimos.stream.audio.tts.kokoro import KokoroTTSConfig | ||
|
|
||
|
|
||
| def test_confirmed_transitions_use_prepared_audio_and_ignore_duplicate_polls(speech): | ||
| prompts, engine = speech | ||
| engine.close.assert_called_once() | ||
| engine.synthesize.reset_mock() | ||
| events = [ | ||
| ("init", "idle", 0, 0, None), | ||
| ("save", "idle", 0, 0, None), | ||
| ("discard", "idle", 0, 0, None), | ||
| ("start", "recording", 0, 0, b"Recording started"), | ||
| ("save", "idle", 1, 0, b"Episode saved"), | ||
| ("start", "recording", 1, 0, b"Recording started"), | ||
| ("discard", "idle", 1, 1, b"Recording canceled"), | ||
| ("start", "recording", 1, 1, b"Recording started"), | ||
| ("start", "recording", 2, 1, b"Recording started"), | ||
| ] | ||
| for ts, (event, state, saved, discarded, expected) in enumerate(events): | ||
| status = EpisodeStatus( | ||
| ts=ts, last_event=event, state=state, episodes_saved=saved, episodes_discarded=discarded | ||
| ) | ||
| assert prompts.update(status) == expected | ||
| assert prompts.update(status) is None | ||
| # RPC polling refreshes timestamps even when the episode has not changed. | ||
| assert prompts.update(status.model_copy(update={"ts": status.ts + 0.5})) is None | ||
| engine.synthesize.assert_not_called() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def speech(mocker): | ||
| engine = mocker.patch( | ||
| "dimos.imitation.collection.prompts.KokoroTTS", autospec=True | ||
| ).return_value | ||
| engine.synthesize.side_effect = lambda phrase: phrase.encode() | ||
| speech = CollectionSpeech(KokoroTTSConfig(enabled=True)) | ||
| speech.prepare() | ||
| return speech, engine | ||
|
|
||
|
|
||
| def test_failed_preparation_releases_engine(mocker): | ||
| engine = mocker.patch( | ||
| "dimos.imitation.collection.prompts.KokoroTTS", autospec=True | ||
| ).return_value | ||
| engine.synthesize.side_effect = RuntimeError("synthesis failed") | ||
| speech = CollectionSpeech(KokoroTTSConfig(enabled=True)) | ||
| with pytest.raises(RuntimeError, match="synthesis failed"): | ||
| speech.prepare() | ||
| engine.close.assert_called_once_with() | ||
| assert ( | ||
| speech.update( | ||
| EpisodeStatus( | ||
| ts=1, state="recording", last_event="start", episodes_saved=0, episodes_discarded=0 | ||
| ) | ||
| ) | ||
| is None | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.