lightfall-voice 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. lightfall_voice-0.1.0/.github/workflows/ci.yml +63 -0
  2. lightfall_voice-0.1.0/.github/workflows/release.yml +73 -0
  3. lightfall_voice-0.1.0/.gitignore +9 -0
  4. lightfall_voice-0.1.0/LEGAL.md +13 -0
  5. lightfall_voice-0.1.0/LICENSE.md +33 -0
  6. lightfall_voice-0.1.0/PKG-INFO +127 -0
  7. lightfall_voice-0.1.0/README.md +99 -0
  8. lightfall_voice-0.1.0/pyproject.toml +42 -0
  9. lightfall_voice-0.1.0/src/lightfall_voice/__init__.py +1 -0
  10. lightfall_voice-0.1.0/src/lightfall_voice/audio.py +78 -0
  11. lightfall_voice-0.1.0/src/lightfall_voice/daemon_client.py +80 -0
  12. lightfall_voice-0.1.0/src/lightfall_voice/events.py +32 -0
  13. lightfall_voice-0.1.0/src/lightfall_voice/manifest.py +30 -0
  14. lightfall_voice-0.1.0/src/lightfall_voice/mute_action.py +141 -0
  15. lightfall_voice-0.1.0/src/lightfall_voice/phrases.py +151 -0
  16. lightfall_voice-0.1.0/src/lightfall_voice/policy.py +165 -0
  17. lightfall_voice-0.1.0/src/lightfall_voice/service.py +323 -0
  18. lightfall_voice-0.1.0/src/lightfall_voice/settings.py +292 -0
  19. lightfall_voice-0.1.0/src/lightfall_voice/settings_editors.py +336 -0
  20. lightfall_voice-0.1.0/src/lightfall_voice/stt/__init__.py +1 -0
  21. lightfall_voice-0.1.0/src/lightfall_voice/stt/controller.py +844 -0
  22. lightfall_voice-0.1.0/src/lightfall_voice/stt/mic_button.py +77 -0
  23. lightfall_voice-0.1.0/src/lightfall_voice/stt/recorder.py +213 -0
  24. lightfall_voice-0.1.0/src/lightfall_voice/stt_plugin.py +41 -0
  25. lightfall_voice-0.1.0/src/lightfall_voice/stt_service/__init__.py +0 -0
  26. lightfall_voice-0.1.0/src/lightfall_voice/stt_service/__main__.py +18 -0
  27. lightfall_voice-0.1.0/src/lightfall_voice/stt_service/endpoint.py +75 -0
  28. lightfall_voice-0.1.0/src/lightfall_voice/stt_service/filters.py +22 -0
  29. lightfall_voice-0.1.0/src/lightfall_voice/stt_service/service.py +481 -0
  30. lightfall_voice-0.1.0/src/lightfall_voice/stt_service/transcriber.py +158 -0
  31. lightfall_voice-0.1.0/src/lightfall_voice/voices.py +20 -0
  32. lightfall_voice-0.1.0/tests/conftest.py +203 -0
  33. lightfall_voice-0.1.0/tests/stt/__init__.py +0 -0
  34. lightfall_voice-0.1.0/tests/stt/conftest.py +25 -0
  35. lightfall_voice-0.1.0/tests/stt/test_audio.py +85 -0
  36. lightfall_voice-0.1.0/tests/stt/test_controller.py +795 -0
  37. lightfall_voice-0.1.0/tests/stt/test_endpoint.py +63 -0
  38. lightfall_voice-0.1.0/tests/stt/test_filters.py +9 -0
  39. lightfall_voice-0.1.0/tests/stt/test_integration.py +200 -0
  40. lightfall_voice-0.1.0/tests/stt/test_recorder.py +238 -0
  41. lightfall_voice-0.1.0/tests/stt/test_service.py +796 -0
  42. lightfall_voice-0.1.0/tests/stt/test_transcriber.py +211 -0
  43. lightfall_voice-0.1.0/tests/test_daemon_client.py +87 -0
  44. lightfall_voice-0.1.0/tests/test_events.py +38 -0
  45. lightfall_voice-0.1.0/tests/test_manifest.py +9 -0
  46. lightfall_voice-0.1.0/tests/test_mute_action.py +168 -0
  47. lightfall_voice-0.1.0/tests/test_phrases.py +94 -0
  48. lightfall_voice-0.1.0/tests/test_policy.py +133 -0
  49. lightfall_voice-0.1.0/tests/test_service.py +249 -0
  50. lightfall_voice-0.1.0/tests/test_service_hold.py +78 -0
  51. lightfall_voice-0.1.0/tests/test_settings_plugin.py +467 -0
  52. lightfall_voice-0.1.0/tests/test_settings_voice_input.py +218 -0
  53. lightfall_voice-0.1.0/tests/test_stt_plugin.py +43 -0
  54. lightfall_voice-0.1.0/tools/stt_smoke.py +216 -0
@@ -0,0 +1,63 @@
1
+ # CI for lightfall-voice — lint and tests.
2
+ # Mirrors lightfall's ci.yml (minus the docs job: this project is README-only
3
+ # by design). Tests run offscreen against PySide6; no audio hardware, voice
4
+ # daemon or Whisper model is needed.
5
+
6
+ name: CI
7
+
8
+ on:
9
+ push:
10
+ branches: [master]
11
+ pull_request:
12
+
13
+ jobs:
14
+ lint:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.11"
21
+ - run: pip install ruff
22
+ - run: ruff check src/
23
+
24
+ test:
25
+ runs-on: ubuntu-latest
26
+ env:
27
+ QT_QPA_PLATFORM: offscreen
28
+ QT_OPENGL: software
29
+ QSG_RHI_BACKEND: "null"
30
+ LIBGL_ALWAYS_SOFTWARE: "1"
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ with:
34
+ fetch-depth: 0 # hatch-vcs derives the version from git tags
35
+ - uses: actions/setup-python@v5
36
+ with:
37
+ python-version: "3.11"
38
+ cache: pip
39
+ - name: Install Qt system libraries
40
+ run: |
41
+ sudo apt-get update
42
+ sudo apt-get install -y libdbus-1-3 libxkbcommon0 libxcb-cursor0 libegl1 libgl1 libopengl0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxcb-xinerama0 libxcb-xkb1 libpulse0 # libpulse: QtMultimedia (mic recorder)
43
+ # Test against lightfall's master, not the last PyPI release: a plugin must work
44
+ # with the app it ships next to (lightfall 0.3.0 on PyPI is far behind master).
45
+ - run: pip install "lightfall @ git+https://github.com/als-controls/lightfall@master"
46
+ - run: pip install -e ".[dev]" pytest-xdist pytest-timeout pytest-cov
47
+ - name: Run tests
48
+ # xdist spawns fresh workers (not fork) — avoids Qt fork-safety issues.
49
+ # --max-worker-restart=5 recovers from PySide6 segfaults in headless CI.
50
+ # --timeout=60 kills tests that hang on Qt event loops.
51
+ run: >-
52
+ pytest tests/ -v --tb=short
53
+ -n auto --max-worker-restart=5 --timeout=60
54
+ --cov=src/lightfall_voice --cov-report=xml:coverage.xml
55
+ --junitxml=results.xml
56
+ - uses: actions/upload-artifact@v4
57
+ if: always()
58
+ with:
59
+ name: test-results
60
+ path: |
61
+ coverage.xml
62
+ results.xml
63
+ retention-days: 7
@@ -0,0 +1,73 @@
1
+ # Release pipeline, triggered by v* tags. Mirrors lightfall's release.yml
2
+ # minus the Briefcase packaging jobs: lightfall-voice is a plugin, not a
3
+ # standalone app, so the release artifacts are just the sdist and wheel.
4
+ #
5
+ # - build-dist / publish-pypi: sdist + wheel to PyPI via OIDC trusted
6
+ # publishing (environment: pypi; publisher registered on pypi.org against
7
+ # this workflow file).
8
+ # - release: GitHub Release with the dist files attached.
9
+ #
10
+ # workflow_dispatch builds the dist only (no publish, no release) — use it
11
+ # to test packaging changes without minting a new tag.
12
+
13
+ name: Release
14
+
15
+ on:
16
+ push:
17
+ tags: ["v*"]
18
+ workflow_dispatch:
19
+
20
+ permissions:
21
+ contents: write
22
+
23
+ jobs:
24
+ build-dist:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ with:
29
+ fetch-depth: 0 # hatch-vcs derives the version from git tags
30
+ - uses: actions/setup-python@v5
31
+ with:
32
+ python-version: "3.11"
33
+ - name: Build sdist and wheel
34
+ run: |
35
+ python -m pip install build twine
36
+ python -m build
37
+ python -m twine check dist/*
38
+ - uses: actions/upload-artifact@v4
39
+ with:
40
+ name: dist-pypi
41
+ path: dist/
42
+ if-no-files-found: error
43
+ retention-days: 7
44
+
45
+ publish-pypi:
46
+ needs: build-dist
47
+ if: startsWith(github.ref, 'refs/tags/')
48
+ runs-on: ubuntu-latest
49
+ environment: pypi
50
+ permissions:
51
+ id-token: write # OIDC trusted publishing
52
+ steps:
53
+ - uses: actions/download-artifact@v4
54
+ with:
55
+ name: dist-pypi
56
+ path: dist/
57
+ - name: Publish to PyPI
58
+ uses: pypa/gh-action-pypi-publish@release/v1
59
+
60
+ release:
61
+ needs: build-dist
62
+ if: startsWith(github.ref, 'refs/tags/')
63
+ runs-on: ubuntu-latest
64
+ steps:
65
+ - uses: actions/download-artifact@v4
66
+ with:
67
+ name: dist-pypi
68
+ path: dist
69
+ - uses: softprops/action-gh-release@v2
70
+ with:
71
+ name: Lightfall Voice ${{ github.ref_name }}
72
+ generate_release_notes: true
73
+ files: dist/**
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .pytest_cache/
6
+
7
+ # superpowers specs/plans and scratch: never commit
8
+ docs/superpowers/
9
+ .superpowers/
@@ -0,0 +1,13 @@
1
+ Lightfall Copyright (c) 2026,
2
+ The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
3
+
4
+ If you have questions about your rights to use or distribute this software,
5
+ please contact Berkeley Lab's Intellectual Property Office at
6
+ IPO@lbl.gov.
7
+
8
+ NOTICE. This Software was developed under funding from the U.S. Department
9
+ of Energy and the U.S. Government consequently retains certain rights. As
10
+ such, the U.S. Government has been granted for itself and others acting on
11
+ its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
12
+ Software to reproduce, distribute copies to the public, prepare derivative
13
+ works, and perform publicly and display publicly, and to permit others to do so.
@@ -0,0 +1,33 @@
1
+ Lightfall Copyright (c) 2026,
2
+ The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ (1) Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ (2) Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ (3) Neither the name of the University of California, Lawrence Berkeley
15
+ National Laboratory, U.S. Dept. of Energy nor the names of its contributors
16
+ may be used to endorse or promote products derived from this software
17
+ without specific prior written permission.
18
+
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
24
+ You are under no obligation whatsoever to provide any bug fixes, patches,
25
+ or upgrades to the features, functionality or performance of the source
26
+ code ("Enhancements") to anyone; however, if you choose to make your
27
+ Enhancements available either publicly, or directly to Lawrence Berkeley
28
+ National Laboratory, without imposing a separate written license agreement
29
+ for such Enhancements, then you hereby grant the following license: a
30
+ non-exclusive, royalty-free perpetual license to install, use, modify,
31
+ prepare derivative works, incorporate into other computer software,
32
+ distribute, and sublicense such enhancements or derivative works thereof,
33
+ in binary and source code form.
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.5
2
+ Name: lightfall-voice
3
+ Version: 0.1.0
4
+ Summary: Voice notifications plugin for Lightfall via the local Kokoro voice daemon
5
+ Project-URL: Repository, https://github.com/als-controls/lightfall-voice
6
+ Project-URL: Issues, https://github.com/als-controls/lightfall-voice/issues
7
+ Author: ALS Controls Team
8
+ License-Expression: BSD-3-Clause
9
+ License-File: LEGAL.md
10
+ License-File: LICENSE.md
11
+ Requires-Python: >=3.11
12
+ Requires-Dist: lightfall-settings>=0.1.4
13
+ Requires-Dist: lightfall-utils>=0.3.0
14
+ Requires-Dist: lightfall>=0.4.0
15
+ Requires-Dist: numpy
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest; extra == 'dev'
18
+ Requires-Dist: pytest-qt; extra == 'dev'
19
+ Provides-Extra: gpu
20
+ Requires-Dist: faster-whisper>=1.1; extra == 'gpu'
21
+ Requires-Dist: numpy; extra == 'gpu'
22
+ Requires-Dist: nvidia-cublas-cu12; extra == 'gpu'
23
+ Requires-Dist: nvidia-cudnn-cu12; extra == 'gpu'
24
+ Provides-Extra: stt-service
25
+ Requires-Dist: faster-whisper>=1.1; extra == 'stt-service'
26
+ Requires-Dist: numpy; extra == 'stt-service'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # lightfall-voice
30
+
31
+ Voice notifications plugin for Lightfall. Speaks Claude agent events through
32
+ the local Kokoro voice daemon from `~/.claude/hooks/voice_notifications`
33
+ (JSON line protocol, TCP `127.0.0.1:52849`).
34
+
35
+ ## What it speaks
36
+
37
+ - **Permission requests** — "Permission needed to run a command" (high
38
+ priority, non-interruptible)
39
+ - **Turn summaries** — trimmed final assistant text, or "Task complete"
40
+ - **Tool announcements** — "Reading loader", "Running a command"; MCP tools
41
+ from their name ("Reading device" for `lightfall_read_device`). TodoWrite,
42
+ Task, Agent and ToolSearch stay silent. Rate-limited to one per tool per 3 s
43
+ - **Errors** — "Agent error. Attention needed"
44
+
45
+ Every session tab speaks by default. Mute the visible tab with the speaker
46
+ button in the Assistant panel's title bar, or any agent under **Preferences →
47
+ Voice Notifications → Agents**; a muted agent's permission requests and
48
+ errors still speak.
49
+
50
+ Voices: **Preferences → Voice Notifications → Voice notifications → Default voice** sets
51
+ the voice for every agent (default `af_heart`, the voice ascribe-link uses);
52
+ the Agents list picks a voice per agent. Both combos are editable, so any
53
+ Kokoro voice id can be typed. An empty default leaves the choice to the
54
+ daemon's `config.json` (`kokoro_voice`).
55
+
56
+ Agents other than the main `lightfall` assistant are named in
57
+ those phrases. Low-priority events older than 10 s are dropped, never
58
+ spoken late.
59
+
60
+ ## Install
61
+
62
+ pip install lightfall-voice
63
+
64
+ For development, from a clone: `pip install -e ".[dev]"`.
65
+
66
+ Registers via the `lightfall.plugins` entry point; the settings page appears
67
+ under Preferences → Plugins → Voice Notifications.
68
+
69
+ ## Voice input (speech to text)
70
+
71
+ Push-to-talk dictation into Claude agent tabs. A mic button sits next to each agent's input
72
+ box, and a hotkey (default `F9`) starts and stops recording on the visible agent tab. Esc
73
+ cancels. The recording goes to a local `stt` service (faster-whisper) that Lightfall launches
74
+ on demand; the transcript is submitted as a prompt (queued while the agent is busy).
75
+
76
+ Install the service dependencies into the interpreter that will run it:
77
+
78
+ pip install "lightfall-voice[stt-service]" # CPU
79
+ pip install "lightfall-voice[gpu]" # CUDA 12 (cuBLAS + cuDNN wheels)
80
+
81
+ The base install never imports faster-whisper. If the service dependencies live in a
82
+ separate environment, point `Python interpreter` at it.
83
+
84
+ Settings (Preferences -> Plugins -> Voice Notifications; keys `voice.input.*`). Device, Input device,
85
+ Model directory and Python interpreter are set at This console ("Voice input on this machine");
86
+ the rest are per user ("Voice input"):
87
+
88
+ | Setting | Key | Default |
89
+ |---|---|---|
90
+ | Enable voice input | `enabled` | off |
91
+ | Model directory | `model_dir` | empty (Hugging Face cache; downloads on first use) |
92
+ | Hotkey | `hotkey` | `F9` |
93
+ | Model | `model` | `small` (`base`, `small`, `medium`, `large-v3`, `distil-large-v3`) |
94
+ | Device | `device` | `auto` (`auto`, `gpu`, `cpu`; auto tries CUDA, then falls back to CPU) |
95
+ | Input device | `input_device` | system default |
96
+ | Silence | `silence_s` | 1.0 s of trailing silence ends the utterance |
97
+ | Language | `language` | `en` (empty: auto-detect) |
98
+ | Python interpreter | `python` | empty (Lightfall's own) |
99
+
100
+ Offline use: set `Model directory` to a folder holding a converted CTranslate2 model (for
101
+ example a `faster-whisper-small` snapshot); nothing is downloaded when the model is found
102
+ there.
103
+
104
+ While you dictate, spoken notifications are held and released afterwards.
105
+
106
+ ## Requirements
107
+
108
+ - The voice daemon must accept hookless direct messages
109
+ (`voice_daemon.py` commit "Add hookless direct-message path"). The plugin
110
+ does not start the daemon; if it is unreachable, notifications are
111
+ silently dropped.
112
+
113
+ ## Settings keys
114
+
115
+ `voice.enabled`, `voice.events.{tools,summary,permission,errors}`,
116
+ `voice.daemon_host`, `voice.daemon_port`, `voice.default_voice`, `voice.input.*`
117
+ (above), `voice.agent_overrides` (`{agent_name: {"muted": bool, "voice": "af_sky"}}`,
118
+ set from the Agents list).
119
+
120
+ `voice.daemon_host`, `voice.daemon_port` and the machine's voice input keys
121
+ (`device`, `input_device`, `model_dir`, `python`) belong to this console and are
122
+ set at This console; every other key is a per-user setting. Only edited keys
123
+ are saved; a blank daemon host means the default `127.0.0.1`.
124
+
125
+ ## Tests
126
+
127
+ .venv\Scripts\python -m pytest
@@ -0,0 +1,99 @@
1
+ # lightfall-voice
2
+
3
+ Voice notifications plugin for Lightfall. Speaks Claude agent events through
4
+ the local Kokoro voice daemon from `~/.claude/hooks/voice_notifications`
5
+ (JSON line protocol, TCP `127.0.0.1:52849`).
6
+
7
+ ## What it speaks
8
+
9
+ - **Permission requests** — "Permission needed to run a command" (high
10
+ priority, non-interruptible)
11
+ - **Turn summaries** — trimmed final assistant text, or "Task complete"
12
+ - **Tool announcements** — "Reading loader", "Running a command"; MCP tools
13
+ from their name ("Reading device" for `lightfall_read_device`). TodoWrite,
14
+ Task, Agent and ToolSearch stay silent. Rate-limited to one per tool per 3 s
15
+ - **Errors** — "Agent error. Attention needed"
16
+
17
+ Every session tab speaks by default. Mute the visible tab with the speaker
18
+ button in the Assistant panel's title bar, or any agent under **Preferences →
19
+ Voice Notifications → Agents**; a muted agent's permission requests and
20
+ errors still speak.
21
+
22
+ Voices: **Preferences → Voice Notifications → Voice notifications → Default voice** sets
23
+ the voice for every agent (default `af_heart`, the voice ascribe-link uses);
24
+ the Agents list picks a voice per agent. Both combos are editable, so any
25
+ Kokoro voice id can be typed. An empty default leaves the choice to the
26
+ daemon's `config.json` (`kokoro_voice`).
27
+
28
+ Agents other than the main `lightfall` assistant are named in
29
+ those phrases. Low-priority events older than 10 s are dropped, never
30
+ spoken late.
31
+
32
+ ## Install
33
+
34
+ pip install lightfall-voice
35
+
36
+ For development, from a clone: `pip install -e ".[dev]"`.
37
+
38
+ Registers via the `lightfall.plugins` entry point; the settings page appears
39
+ under Preferences → Plugins → Voice Notifications.
40
+
41
+ ## Voice input (speech to text)
42
+
43
+ Push-to-talk dictation into Claude agent tabs. A mic button sits next to each agent's input
44
+ box, and a hotkey (default `F9`) starts and stops recording on the visible agent tab. Esc
45
+ cancels. The recording goes to a local `stt` service (faster-whisper) that Lightfall launches
46
+ on demand; the transcript is submitted as a prompt (queued while the agent is busy).
47
+
48
+ Install the service dependencies into the interpreter that will run it:
49
+
50
+ pip install "lightfall-voice[stt-service]" # CPU
51
+ pip install "lightfall-voice[gpu]" # CUDA 12 (cuBLAS + cuDNN wheels)
52
+
53
+ The base install never imports faster-whisper. If the service dependencies live in a
54
+ separate environment, point `Python interpreter` at it.
55
+
56
+ Settings (Preferences -> Plugins -> Voice Notifications; keys `voice.input.*`). Device, Input device,
57
+ Model directory and Python interpreter are set at This console ("Voice input on this machine");
58
+ the rest are per user ("Voice input"):
59
+
60
+ | Setting | Key | Default |
61
+ |---|---|---|
62
+ | Enable voice input | `enabled` | off |
63
+ | Model directory | `model_dir` | empty (Hugging Face cache; downloads on first use) |
64
+ | Hotkey | `hotkey` | `F9` |
65
+ | Model | `model` | `small` (`base`, `small`, `medium`, `large-v3`, `distil-large-v3`) |
66
+ | Device | `device` | `auto` (`auto`, `gpu`, `cpu`; auto tries CUDA, then falls back to CPU) |
67
+ | Input device | `input_device` | system default |
68
+ | Silence | `silence_s` | 1.0 s of trailing silence ends the utterance |
69
+ | Language | `language` | `en` (empty: auto-detect) |
70
+ | Python interpreter | `python` | empty (Lightfall's own) |
71
+
72
+ Offline use: set `Model directory` to a folder holding a converted CTranslate2 model (for
73
+ example a `faster-whisper-small` snapshot); nothing is downloaded when the model is found
74
+ there.
75
+
76
+ While you dictate, spoken notifications are held and released afterwards.
77
+
78
+ ## Requirements
79
+
80
+ - The voice daemon must accept hookless direct messages
81
+ (`voice_daemon.py` commit "Add hookless direct-message path"). The plugin
82
+ does not start the daemon; if it is unreachable, notifications are
83
+ silently dropped.
84
+
85
+ ## Settings keys
86
+
87
+ `voice.enabled`, `voice.events.{tools,summary,permission,errors}`,
88
+ `voice.daemon_host`, `voice.daemon_port`, `voice.default_voice`, `voice.input.*`
89
+ (above), `voice.agent_overrides` (`{agent_name: {"muted": bool, "voice": "af_sky"}}`,
90
+ set from the Agents list).
91
+
92
+ `voice.daemon_host`, `voice.daemon_port` and the machine's voice input keys
93
+ (`device`, `input_device`, `model_dir`, `python`) belong to this console and are
94
+ set at This console; every other key is a per-user setting. Only edited keys
95
+ are saved; a blank daemon host means the default `127.0.0.1`.
96
+
97
+ ## Tests
98
+
99
+ .venv\Scripts\python -m pytest
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "lightfall-voice"
7
+ description = "Voice notifications plugin for Lightfall via the local Kokoro voice daemon"
8
+ readme = "README.md"
9
+ license = "BSD-3-Clause"
10
+ license-files = ["LICENSE.md", "LEGAL.md"]
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "ALS Controls Team" }]
13
+ dynamic = ["version"]
14
+ dependencies = [
15
+ "lightfall>=0.4.0",
16
+ "lightfall-utils>=0.3.0",
17
+ "lightfall-settings>=0.1.4",
18
+ "numpy",
19
+ ]
20
+
21
+ [project.urls]
22
+ Repository = "https://github.com/als-controls/lightfall-voice"
23
+ Issues = "https://github.com/als-controls/lightfall-voice/issues"
24
+
25
+ [project.optional-dependencies]
26
+ dev = ["pytest", "pytest-qt"]
27
+ stt-service = ["faster-whisper>=1.1", "numpy"]
28
+ gpu = ["lightfall-voice[stt-service]", "nvidia-cublas-cu12", "nvidia-cudnn-cu12"]
29
+
30
+ [project.entry-points."lightfall.plugins"]
31
+ lightfall_voice = "lightfall_voice.manifest:manifest"
32
+
33
+ [tool.hatch.version]
34
+ source = "vcs"
35
+ fallback-version = "0.0.0"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/lightfall_voice"]
39
+
40
+ [tool.ruff.lint]
41
+ # Match lightfall-vibe: keep the pre-0.16 ruff default rule set.
42
+ select = ["E4", "E7", "E9", "F"]
@@ -0,0 +1 @@
1
+ """Voice notifications plugin for Lightfall."""
@@ -0,0 +1,78 @@
1
+ """Audio helpers shared by the STT service and the recorder (no Qt)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import numpy as np
6
+
7
+ RATE = 16000
8
+ CHUNK_SAMPLES = 1600
9
+
10
+
11
+ def pcm16_to_float32(b: bytes) -> np.ndarray:
12
+ return np.frombuffer(b, dtype="<i2").astype(np.float32) / 32768.0
13
+
14
+
15
+ def float32_to_pcm16(a) -> bytes:
16
+ arr = np.clip(np.asarray(a, dtype=np.float32), -1.0, 1.0)
17
+ return np.round(arr * 32767.0).astype("<i2").tobytes()
18
+
19
+
20
+ def resample(a: np.ndarray, src_rate: int, dst_rate: int = RATE) -> np.ndarray:
21
+ """Linear resample via np.interp."""
22
+ a = np.asarray(a, dtype=np.float32)
23
+ if src_rate == dst_rate or len(a) == 0:
24
+ return a
25
+ n_out = int(round(len(a) * dst_rate / src_rate))
26
+ x_out = np.arange(n_out) * (src_rate / dst_rate)
27
+ return np.interp(x_out, np.arange(len(a)), a).astype(np.float32)
28
+
29
+
30
+ def rms(a) -> float:
31
+ arr = np.asarray(a, dtype=np.float64)
32
+ if arr.size == 0:
33
+ return 0.0
34
+ return float(np.sqrt(np.mean(arr * arr)))
35
+
36
+
37
+ class StreamResampler:
38
+ """Stateful mono resampler: windowed-sinc low-pass, then linear interpolation.
39
+
40
+ Filter history and the fractional read position carry across ``process`` calls,
41
+ so block size does not affect the output. numpy only.
42
+ """
43
+
44
+ TAPS = 65
45
+
46
+ def __init__(self, src_rate: int, dst_rate: int = RATE):
47
+ self.src_rate = src_rate
48
+ self.dst_rate = dst_rate
49
+ self._passthrough = src_rate == dst_rate
50
+ self._step = src_rate / dst_rate
51
+ fc = 0.45 * min(src_rate, dst_rate) / src_rate # cycles per input sample
52
+ n = np.arange(self.TAPS) - (self.TAPS - 1) / 2
53
+ h = 2 * fc * np.sinc(2 * fc * n) * np.hamming(self.TAPS)
54
+ self._h = h / h.sum()
55
+ self._hist = np.zeros(self.TAPS - 1, dtype=np.float64)
56
+ self._buf = np.zeros(0, dtype=np.float64)
57
+ self._pos = 0.0
58
+
59
+ def process(self, a) -> np.ndarray:
60
+ a = np.asarray(a, dtype=np.float32)
61
+ if self._passthrough or len(a) == 0:
62
+ return a
63
+ x = np.concatenate([self._hist, a.astype(np.float64)])
64
+ filtered = np.convolve(x, self._h, mode="valid") # len(a) samples
65
+ self._hist = x[-(self.TAPS - 1):]
66
+ buf = np.concatenate([self._buf, filtered])
67
+ last = len(buf) - 1
68
+ if self._pos > last:
69
+ self._buf = buf
70
+ return np.zeros(0, dtype=np.float32)
71
+ n_out = int((last - self._pos) // self._step) + 1
72
+ xs = self._pos + np.arange(n_out) * self._step
73
+ out = np.interp(xs, np.arange(len(buf)), buf).astype(np.float32)
74
+ new_pos = self._pos + n_out * self._step
75
+ k = min(int(new_pos), len(buf)) # excess stays in pos for the next block
76
+ self._buf = buf[k:]
77
+ self._pos = new_pos - k
78
+ return out
@@ -0,0 +1,80 @@
1
+ """Fire-and-forget TCP client for the voice daemon's JSON line protocol.
2
+
3
+ One background worker drains a queue; every send opens a short-lived
4
+ connection. Any failure drops the message -- a missed notification is
5
+ always better than a blocked or crashing GUI.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import queue
12
+ import socket
13
+ import threading
14
+ import time
15
+
16
+ from lightfall.utils.logging import logger
17
+
18
+ _SENTINEL = object()
19
+
20
+
21
+ class DaemonClient:
22
+ def __init__(
23
+ self,
24
+ host: str = "127.0.0.1",
25
+ port: int = 52849,
26
+ connect_timeout: float = 2.0,
27
+ ) -> None:
28
+ self._host = host
29
+ self._port = port
30
+ self._timeout = connect_timeout
31
+ self._queue: queue.Queue = queue.Queue()
32
+ self._thread = threading.Thread(
33
+ target=self._run, name="lightfall-voice-daemon-client", daemon=True
34
+ )
35
+ self._thread.start()
36
+
37
+ def configure(self, host: str, port: int) -> None:
38
+ self._queue.put({"_configure": (host, int(port))})
39
+
40
+ def speak(self, message: str, voice: str | None = None, ttl: float | None = None) -> None:
41
+ deadline = time.monotonic() + ttl if ttl is not None else None
42
+ self._queue.put(
43
+ {
44
+ "action": "speak",
45
+ "args": {"message": message, "voice": voice},
46
+ "_deadline": deadline,
47
+ }
48
+ )
49
+
50
+ def stop(self) -> None:
51
+ self._queue.put(_SENTINEL)
52
+ self._thread.join(timeout=3)
53
+
54
+ def _run(self) -> None:
55
+ while True:
56
+ item = self._queue.get()
57
+ if item is _SENTINEL:
58
+ return
59
+ if isinstance(item, dict) and "_configure" in item:
60
+ # Apply configuration change (maintains queue ordering)
61
+ self._host, self._port = item["_configure"]
62
+ continue
63
+ deadline = item.get("_deadline") if isinstance(item, dict) else None
64
+ if deadline is not None and time.monotonic() >= deadline:
65
+ logger.debug("voice daemon message expired before send, dropping")
66
+ continue
67
+ request = {k: v for k, v in item.items() if k != "_deadline"}
68
+ try:
69
+ self._send(request)
70
+ except Exception as e:
71
+ logger.debug("voice daemon unreachable, dropping message: {}", e)
72
+
73
+ def _send(self, request: dict) -> None:
74
+ with socket.create_connection((self._host, self._port), timeout=self._timeout) as sock:
75
+ sock.sendall((json.dumps(request) + "\n").encode("utf-8"))
76
+ sock.settimeout(self._timeout)
77
+ try:
78
+ sock.recv(4096) # read-and-ignore the response line
79
+ except OSError:
80
+ pass
@@ -0,0 +1,32 @@
1
+ """Normalized voice events. Priority follows daemon semantics:
2
+ high = non-interruptible (permission, error); low = interruptible chatter."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class VoiceEvent:
11
+ agent_name: str
12
+ kind: str # "tool" | "summary" | "permission" | "error"
13
+ text: str
14
+ priority: str # "high" | "low"
15
+ timestamp: float
16
+ tool_name: str | None = None
17
+
18
+
19
+ def tool_event(agent_name: str, tool_name: str, text: str, now: float) -> VoiceEvent:
20
+ return VoiceEvent(agent_name, "tool", text, "low", now, tool_name)
21
+
22
+
23
+ def summary_event(agent_name: str, text: str, now: float) -> VoiceEvent:
24
+ return VoiceEvent(agent_name, "summary", text, "low", now)
25
+
26
+
27
+ def permission_event(agent_name: str, text: str, now: float) -> VoiceEvent:
28
+ return VoiceEvent(agent_name, "permission", text, "high", now)
29
+
30
+
31
+ def error_event(agent_name: str, text: str, now: float) -> VoiceEvent:
32
+ return VoiceEvent(agent_name, "error", text, "high", now)