diff --git a/.gitignore b/.gitignore index d27fa76..55d5daa 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ keys.txt # local visual-verification output .artifacts/ + +# rust build output +target/ diff --git a/CLAUDE.md b/CLAUDE.md index bf59bbd..37bfc43 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -210,6 +210,19 @@ kept its ssh host key. Run it after ANY change to the kexec paths. - **`kexec-local` stages on `/var/tmp`, not `/tmp`**: `kexec-run.sh` appends a fresh cpio to `kexec/initrd` in place and execs binaries from that dir, so a size-capped or `noexec` tmpfs gives a half-written initrd or a bare "Permission denied". +- **A sops secret a USER service reads needs `owner`, not a mode.** `luna-voiced` + (`services/desktop/luna-voice.nix`) runs as darman's user unit, and a user manager + cannot read root:root 0400 — `LoadCredential` does not bridge that gap either. + Hence `sops.secrets..owner = "darman"` in `hosts/terra/secrets.nix`. +- **`elevenlabs_api_key` is in BOTH `secrets/mars.yaml` and `secrets/terra.yaml`** — + same value. terra calls ElevenLabs directly (the client-direct path Hermes + documents) rather than relaying audio through mars, so rotating that key means + editing two files. `hermes_api_server_key` is duplicated for the same reason: + mars serves the API, terra is its only client. +- **whisper invents words out of silence** — "you", "Thank you.", "Bye." — and a + held push-to-talk key over a quiet room is long AND empty, so duration alone + does not catch it. `stt::has_speech` gates on the loudest 100ms window instead; + without it every stray keypress sends a hallucinated sentence to luna. - **terra's greeter is a throwaway Hyprland running `dotfiles/quickshell/greeter.qml`** (`services/desktop/quickshell-greeter.nix`). It must exit after login or greetd never starts the session, and with a Lua config `hyprctl dispatch exit` is REJECTED — it needs diff --git a/hosts/terra/configuration.nix b/hosts/terra/configuration.nix index e57dd0a..1586510 100644 --- a/hosts/terra/configuration.nix +++ b/hosts/terra/configuration.nix @@ -19,8 +19,27 @@ in ../../services/desktop/desktop-hyprland.nix ../../services/desktop/desktop-apps.nix ../../services/desktop/librechat.nix + ../../services/desktop/luna-voice.nix ]; + # Talk to luna (Hermes Agent on mars) with SUPER+V — see + # hosts/terra/home/hyprland.nix for the push-to-talk binds. + homelab.lunaVoice = { + enable = true; + hermesKeyFile = config.sops.secrets.hermes_api_server_key.path; + elevenLabsKeyFile = config.sops.secrets.elevenlabs_api_key.path; + # luna's own voice — must stay in sync with `tts.elevenlabs.voice_id` in + # her config.yaml on mars, or she sounds like someone else on the desktop + # than she does on Telegram. + voiceId = "LZAcK8Cx5QjdQhfBsJQZ"; + systemPrompt = '' + You are being spoken to out loud and your reply will be read aloud by a + speech synthesiser. Answer in one or two sentences unless asked for + detail. No markdown, no lists, no code blocks — they do not survive the + trip to audio. + ''; + }; + networking.hostName = "terra"; homelab.greeter = { diff --git a/hosts/terra/home/hyprland.nix b/hosts/terra/home/hyprland.nix index cc28d9b..7c15638 100644 --- a/hosts/terra/home/hyprland.nix +++ b/hosts/terra/home/hyprland.nix @@ -195,6 +195,12 @@ in # expand / collapse the hyprchrome bar as a whole (bind "SUPER + A" (dsp.global "quickshell:chrome")) + # push-to-talk for luna (services/desktop/luna-voice.nix). Two binds, + # not one: the daemon records between the press and the release, so + # the release edge is what ends the utterance. + (bind "SUPER + V" (dsp.exec "luna-voice ptt-down")) + (bindo "SUPER + V" (dsp.exec "luna-voice ptt-up") { release = true; }) + (bind "SUPER + B" (dsp.exec "vivaldi")) (bind "SUPER + E" (dsp.exec "cosmic-files")) (bind "SUPER + SHIFT + G" (dsp.workspaceRef "game")) @@ -237,7 +243,7 @@ in (bind "SUPER + T" (dsp.togglespecial "terminal")) (bind "SUPER + C" (dsp.togglespecial "communications")) (bind "SUPER + M" (dsp.togglespecial "music")) - (bind "SUPER + V" (dsp.togglespecial "version_control")) + # (bind "SUPER + V" (dsp.togglespecial "version_control")) # cycle workspaces (bind "SUPER + ALT + up" (dsp.workspaceRef "e+1")) diff --git a/hosts/terra/secrets.nix b/hosts/terra/secrets.nix index a39ba2b..f2d1087 100644 --- a/hosts/terra/secrets.nix +++ b/hosts/terra/secrets.nix @@ -27,6 +27,18 @@ # tokens. All four are random, generated once with `sops --set` (see # CLAUDE.md) — losing/rotating them just invalidates existing sessions and # any saved per-user API keys, nothing else depends on their value. + # luna-voiced (services/desktop/luna-voice.nix) runs as a USER service, so + # these cannot stay root:root 0400 — a user manager cannot read them and + # LoadCredential does not bridge that gap either. Hence owner, not mode. + # + # hermes_api_server_key mirrors secrets/mars.yaml (the serving side); + # elevenlabs_api_key mirrors it too, because client-direct TTS is the + # documented low-latency path — terra calls ElevenLabs itself rather than + # relaying audio through mars. Rotating that key therefore touches BOTH + # files; see CLAUDE.md. + sops.secrets.hermes_api_server_key.owner = "darman"; + sops.secrets.elevenlabs_api_key.owner = "darman"; + sops.secrets.librechat_creds_key = { }; sops.secrets.librechat_creds_iv = { }; sops.secrets.librechat_jwt_secret = { }; diff --git a/pkgs/luna-voice.nix b/pkgs/luna-voice.nix new file mode 100644 index 0000000..4e19702 --- /dev/null +++ b/pkgs/luna-voice.nix @@ -0,0 +1,32 @@ +{ lib +, rustPlatform +, pkg-config +, alsa-lib +}: + +# luna-voiced — the push-to-talk voice loop for luna (Hermes Agent on mars). +# Wiring (secrets, whisper model, systemd user unit) lives in +# services/desktop/luna-voice.nix; this only builds the binary. +# +# cargoLock.lockFile rather than a cargoHash: the lockfile is committed, so a +# dependency bump is a visible diff instead of a hash nobody can read. +# +# alsa-lib is cpal's backend even on a pipewire box — pipewire's ALSA +# compatibility layer is what actually serves it, so there is no pipewire +# build dependency here. +rustPlatform.buildRustPackage { + pname = "luna-voice"; + version = "0.1.0"; + + src = ./luna-voice; + cargoLock.lockFile = ./luna-voice/Cargo.lock; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ alsa-lib ]; + + meta = { + description = "Push-to-talk voice loop for luna (Hermes Agent)"; + mainProgram = "luna-voice"; + platforms = lib.platforms.linux; + }; +} diff --git a/pkgs/luna-voice/Cargo.lock b/pkgs/luna-voice/Cargo.lock new file mode 100644 index 0000000..98e6f49 --- /dev/null +++ b/pkgs/luna-voice/Cargo.lock @@ -0,0 +1,2166 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "alsa" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7572b7ba83a31e20d1b48970ee402d2e3e0537dcfe0a3ff4d6eb7508617d43" +dependencies = [ + "alsa-sys", + "bitflags 2.13.2", + "cfg-if", + "libc", +] + +[[package]] +name = "alsa-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bindgen" +version = "0.72.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" +dependencies = [ + "bitflags 2.13.2", + "cexpr", + "clang-sys", + "itertools", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex 1.3.0", + "syn 2.0.119", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex 2.0.1", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core 0.10.1", +] + +[[package]] +name = "clang-sys" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "combine" +version = "4.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfc320937d09e6de266b31b9afb480f197d7a861be86be7cb2ea7e5d1bfffc5e" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "coreaudio-rs" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "321077172d79c662f64f5071a03120748d5bb652f5231570141be24cfcd2bace" +dependencies = [ + "bitflags 1.3.2", + "core-foundation-sys", + "coreaudio-sys", +] + +[[package]] +name = "coreaudio-sys" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9b4739a805a62757a83e5654fa3faabec0442666b263bb2287d5a8185bfd953" +dependencies = [ + "bindgen", +] + +[[package]] +name = "cpal" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "873dab07c8f743075e57f524c583985fbaf745602acbe916a01539364369a779" +dependencies = [ + "alsa", + "core-foundation-sys", + "coreaudio-rs", + "dasp_sample", + "jni", + "js-sys", + "libc", + "mach2", + "ndk", + "ndk-context", + "oboe", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "dasp_sample" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" + +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "either" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "rand_core 0.10.1", + "wasm-bindgen", +] + +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hound" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f" + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots 1.0.9", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys 0.3.1", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + +[[package]] +name = "luna-voice" +version = "0.1.0" +dependencies = [ + "anyhow", + "base64", + "cpal", + "futures-util", + "hound", + "reqwest", + "serde", + "serde_json", + "tokio", + "tokio-tungstenite", +] + +[[package]] +name = "mach2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "ndk" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +dependencies = [ + "bitflags 2.13.2", + "jni-sys 0.3.1", + "log", + "ndk-sys", + "num_enum", + "thiserror 1.0.69", +] + +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + +[[package]] +name = "ndk-sys" +version = "0.5.0+25.2.9519653" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" +dependencies = [ + "jni-sys 0.3.1", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0bca838442ec211fa11de3a8b0e0e8f3a4522575b5c4c06ed722e005036f26" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "680998035259dcfcafe653688bf2aa6d3e2dc05e98be6ab46afb089dc84f1df8" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "oboe" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8b61bebd49e5d43f5f8cc7ee2891c16e0f41ec7954d36bcb6c14c5e0de867fb" +dependencies = [ + "jni", + "ndk", + "ndk-context", + "num-derive", + "num-traits", + "oboe-sys", +] + +[[package]] +name = "oboe-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8bb09a4a2b1d668170cfe0a7d5bc103f8999fb316c98099b6a9939c9f2e79d" +dependencies = [ + "cc", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.20", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9746dbde176634f4f2f1faf2404e30a31b2bc1e9cafb5329c95d8177a18c9fc" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand 0.10.3", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.20", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core 0.10.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core 0.10.1", +] + +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots 1.0.9", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustls" +version = "0.23.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl 2.0.20", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c85f2c3ef0b1cd58b36682f4b17aaa995f0e5db534d85692b4903abce21f67" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9" +dependencies = [ + "futures-util", + "log", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tungstenite", + "webpki-roots 0.26.11", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.15+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1340ea94a5856333492c9064b02c778b191dd2c853778d9609debdcdfea3a614" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56" +dependencies = [ + "winnow", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand 0.8.8", + "rustls", + "rustls-pki-types", + "sha1", + "thiserror 1.0.69", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef4c5d3d2cdf5c54f4231181768f5510842e350db025faf1f7163b1030ed928" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.6", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbddc4a036f00ec4f18c83445bd3115cb306a91da554919a099d9222fe4a7f8" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.9", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +dependencies = [ + "windows-core", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" +dependencies = [ + "memchr", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/pkgs/luna-voice/Cargo.toml b/pkgs/luna-voice/Cargo.toml new file mode 100644 index 0000000..8778194 --- /dev/null +++ b/pkgs/luna-voice/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "luna-voice" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1" +base64 = "0.22" +cpal = "0.15" +futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } +hound = "3" +reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "sync", "time", "process", "io-util", "signal"] } +tokio-tungstenite = { version = "0.24", default-features = false, features = ["connect", "rustls-tls-webpki-roots"] } + +[profile.release] +opt-level = 2 diff --git a/pkgs/luna-voice/src/audio.rs b/pkgs/luna-voice/src/audio.rs new file mode 100644 index 0000000..eaa580a --- /dev/null +++ b/pkgs/luna-voice/src/audio.rs @@ -0,0 +1,265 @@ +use anyhow::{anyhow, Result}; +use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; +use std::collections::VecDeque; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; +use std::sync::{Arc, Mutex}; + +/// What whisper wants. Everything captured is resampled to this before it +/// reaches disk. +pub const STT_RATE: u32 = 16_000; +/// What we ask ElevenLabs for (pcm_24000), resampled to the device on the way out. +pub const TTS_RATE: u32 = 24_000; + +/// Mic. The stream runs for the whole session, not just while recording: +/// barge-in needs a live RMS while she is speaking, and restarting a cpal +/// stream per utterance costs ~100ms of dropped samples on pipewire. +/// +/// cpal::Stream is !Send, so it is owned by a parked thread rather than by +/// this handle — which then holds nothing but atomics and a mutex and can be +/// shared across tokio tasks freely. +pub struct Capture { + pub rms: Arc, + recording: Arc, + buffer: Arc>>, + rate: u32, +} + +impl Capture { + pub fn new() -> Result { + let rms = Arc::new(AtomicU32::new(0)); + let recording = Arc::new(AtomicBool::new(false)); + let buffer = Arc::new(Mutex::new(Vec::new())); + + let (r, rec, buf) = (rms.clone(), recording.clone(), buffer.clone()); + let rate = spawn_stream(move || { + let device = cpal::default_host() + .default_input_device() + .ok_or_else(|| anyhow!("no input device"))?; + let config = device.default_input_config()?; + let rate = config.sample_rate().0; + let channels = config.channels() as usize; + let stream = device.build_input_stream( + &config.into(), + move |data: &[f32], _: &cpal::InputCallbackInfo| { + // Downmix to mono up front; nothing downstream cares about stereo. + let mono: Vec = data + .chunks(channels) + .map(|f| f.iter().sum::() / channels as f32) + .collect(); + let sum: f32 = mono.iter().map(|s| s * s).sum(); + let level = (sum / mono.len().max(1) as f32).sqrt(); + r.store(level.to_bits(), Ordering::Relaxed); + if rec.load(Ordering::Relaxed) { + if let Ok(mut b) = buf.lock() { + b.extend_from_slice(&mono); + } + } + }, + |e| eprintln!("luna-voice: capture error: {e}"), + None, + )?; + stream.play()?; + Ok((stream, rate)) + })?; + + Ok(Capture { rms, recording, buffer, rate }) + } + + pub fn level(&self) -> f32 { + f32::from_bits(self.rms.load(Ordering::Relaxed)) + } + + pub fn start(&self) { + self.buffer.lock().map(|mut b| b.clear()).ok(); + self.recording.store(true, Ordering::Relaxed); + } + + /// Stops recording and returns what was captured, resampled to STT_RATE. + pub fn stop(&self) -> Vec { + self.recording.store(false, Ordering::Relaxed); + let raw = self + .buffer + .lock() + .map(|mut b| std::mem::take(&mut *b)) + .unwrap_or_default(); + resample(&raw, self.rate, STT_RATE) + } +} + +/// Speaker. Fed from the TTS websocket; `clear` is what makes barge-in +/// instant rather than "after the current sentence". +pub struct Playback { + queue: Arc>>, + rate: u32, +} + +impl Playback { + pub fn new() -> Result { + let queue: Arc>> = Arc::new(Mutex::new(VecDeque::new())); + let q = queue.clone(); + let rate = spawn_stream(move || { + let device = cpal::default_host() + .default_output_device() + .ok_or_else(|| anyhow!("no output device"))?; + let config = device.default_output_config()?; + let rate = config.sample_rate().0; + let channels = config.channels() as usize; + let stream = device.build_output_stream( + &config.into(), + move |data: &mut [f32], _: &cpal::OutputCallbackInfo| { + let mut q = match q.lock() { + Ok(q) => q, + Err(_) => return, + }; + for frame in data.chunks_mut(channels) { + let s = q.pop_front().unwrap_or(0.0); + for out in frame.iter_mut() { + *out = s; + } + } + }, + |e| eprintln!("luna-voice: playback error: {e}"), + None, + )?; + stream.play()?; + Ok((stream, rate)) + })?; + Ok(Playback { queue, rate }) + } + + pub fn push(&self, pcm: &[f32]) { + let out = resample(pcm, TTS_RATE, self.rate); + if let Ok(mut q) = self.queue.lock() { + q.extend(out); + } + } + + pub fn clear(&self) { + self.queue.lock().map(|mut q| q.clear()).ok(); + } + + pub fn pending(&self) -> usize { + self.queue.lock().map(|q| q.len()).unwrap_or(0) + } + + /// Short sine burst, so you know the key registered without looking at + /// anything. Hermes' voice mode has `beep_enabled` for the same reason: + /// push-to-talk with no acknowledgement is indistinguishable from broken. + /// + /// Raised-cosine envelope — a bare sine starting at full amplitude clicks. + pub fn beep(&self, freq: f32, ms: u32) { + let n = (self.rate as f32 * ms as f32 / 1000.0) as usize; + let samples: Vec = (0..n) + .map(|i| { + let t = i as f32 / self.rate as f32; + let progress = i as f32 / n as f32; + let envelope = (std::f32::consts::PI * progress).sin(); + (t * freq * std::f32::consts::TAU).sin() * envelope * 0.15 + }) + .collect(); + if let Ok(mut q) = self.queue.lock() { + q.extend(samples); + } + } +} + +/// Builds a cpal stream on a dedicated thread that then parks forever, +/// keeping it alive. Returns the device's sample rate, or the build error — +/// a stream that fails here must surface at startup, not as silence later. +fn spawn_stream(build: F) -> Result +where + F: FnOnce() -> Result<(cpal::Stream, u32)> + Send + 'static, +{ + let (tx, rx) = std::sync::mpsc::channel::>(); + std::thread::spawn(move || match build() { + Ok((_stream, rate)) => { + let _ = tx.send(Ok(rate)); + // Dropping `stream` would stop the device, so the thread holds it + // for the life of the process. + loop { + std::thread::park(); + } + #[allow(unreachable_code)] + drop(_stream); + } + Err(e) => { + let _ = tx.send(Err(e.to_string())); + } + }); + rx.recv() + .map_err(|_| anyhow!("audio thread died during setup"))? + .map_err(|e| anyhow!(e)) +} + +/// Linear resampling. Speech at these rates does not justify a windowed sinc, +/// and rubato would add a dependency for inaudible gain. +pub fn resample(input: &[f32], from: u32, to: u32) -> Vec { + if from == to || input.is_empty() { + return input.to_vec(); + } + let ratio = to as f64 / from as f64; + let out_len = (input.len() as f64 * ratio).round() as usize; + (0..out_len) + .map(|i| { + let src = i as f64 / ratio; + let j = src.floor() as usize; + let frac = (src - j as f64) as f32; + let a = input.get(j).copied().unwrap_or(0.0); + let b = input.get(j + 1).copied().unwrap_or(a); + a + (b - a) * frac + }) + .collect() +} + +/// 16-bit mono WAV, which is the only thing whisper-cli accepts without +/// converting first. +pub fn write_wav(path: &std::path::Path, samples: &[f32], rate: u32) -> Result<()> { + let spec = hound::WavSpec { + channels: 1, + sample_rate: rate, + bits_per_sample: 16, + sample_format: hound::SampleFormat::Int, + }; + let mut w = hound::WavWriter::create(path, spec)?; + for s in samples { + w.write_sample((s.clamp(-1.0, 1.0) * i16::MAX as f32) as i16)?; + } + w.finalize()?; + Ok(()) +} + +/// Signed 16-bit little-endian, as ElevenLabs sends pcm_*. +pub fn pcm16_to_f32(bytes: &[u8]) -> Vec { + bytes + .chunks_exact(2) + .map(|b| i16::from_le_bytes([b[0], b[1]]) as f32 / i16::MAX as f32) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn resample_keeps_length_ratio() { + let input = vec![0.0f32; 1000]; + assert_eq!(resample(&input, 48_000, 16_000).len(), 333); + assert_eq!(resample(&input, 24_000, 48_000).len(), 2000); + } + + #[test] + fn resample_is_identity_at_equal_rates() { + let input = vec![0.1, -0.4, 0.9]; + assert_eq!(resample(&input, 16_000, 16_000), input); + } + + #[test] + fn pcm16_roundtrips_through_f32() { + let bytes = [0x00, 0x00, 0xff, 0x7f, 0x01, 0x80]; + let got = pcm16_to_f32(&bytes); + assert_eq!(got.len(), 3); + assert!((got[0]).abs() < 1e-6); + assert!((got[1] - 1.0).abs() < 1e-3); + assert!((got[2] + 1.0).abs() < 1e-3); + } +} diff --git a/pkgs/luna-voice/src/brain.rs b/pkgs/luna-voice/src/brain.rs new file mode 100644 index 0000000..7b8e126 --- /dev/null +++ b/pkgs/luna-voice/src/brain.rs @@ -0,0 +1,123 @@ +use anyhow::{bail, Result}; +use futures_util::StreamExt; +use serde::{Deserialize, Serialize}; +use tokio::sync::mpsc; + +#[derive(Clone, Serialize, Deserialize, Debug)] +pub struct Message { + pub role: String, + pub content: String, +} + +impl Message { + pub fn user(content: impl Into) -> Self { + Message { role: "user".into(), content: content.into() } + } + pub fn assistant(content: impl Into) -> Self { + Message { role: "assistant".into(), content: content.into() } + } + pub fn system(content: impl Into) -> Self { + Message { role: "system".into(), content: content.into() } + } +} + +/// Streams a reply from Hermes' OpenAI-compatible API, pushing text deltas +/// into `tx` as they arrive. +/// +/// /v1/chat/completions with client-side history, not /v1/responses with +/// previous_response_id: the Responses API keeps the transcript server-side, +/// which is nicer, but this shape is the one every OpenAI client exercises so +/// it is the one least likely to differ between Hermes versions. Her memory +/// and skills are unaffected either way — those are not conversation state. +pub async fn stream_reply( + client: &reqwest::Client, + base_url: &str, + key: &str, + model: &str, + history: &[Message], + tx: mpsc::Sender, +) -> Result { + let body = serde_json::json!({ + "model": model, + "messages": history, + "stream": true, + }); + + let resp = client + .post(format!("{}/v1/chat/completions", base_url.trim_end_matches('/'))) + .bearer_auth(key) + .json(&body) + .send() + .await?; + + if !resp.status().is_success() { + let status = resp.status(); + let text = resp.text().await.unwrap_or_default(); + bail!("hermes {status}: {}", text.trim()); + } + + let mut stream = resp.bytes_stream(); + let mut pending = String::new(); + let mut full = String::new(); + + while let Some(chunk) = stream.next().await { + pending.push_str(&String::from_utf8_lossy(&chunk?)); + // SSE frames are separated by a blank line; a chunk boundary can land + // mid-frame, so only complete frames are consumed. + while let Some(idx) = pending.find("\n\n") { + let frame: String = pending.drain(..idx + 2).collect(); + for line in frame.lines() { + let Some(data) = line.strip_prefix("data:") else { continue }; + let data = data.trim(); + if data == "[DONE]" { + return Ok(full); + } + if let Some(delta) = parse_delta(data) { + full.push_str(&delta); + // A closed receiver means the reply was cancelled (barge-in). + if tx.send(delta).await.is_err() { + return Ok(full); + } + } + } + } + } + Ok(full) +} + +/// Pulls choices[0].delta.content out of one SSE data payload. Tool-call +/// frames and role-only frames carry no content and are skipped. +fn parse_delta(data: &str) -> Option { + let v: serde_json::Value = serde_json::from_str(data).ok()?; + let content = v + .get("choices")? + .get(0)? + .get("delta")? + .get("content")? + .as_str()?; + (!content.is_empty()).then(|| content.to_string()) +} + +#[cfg(test)] +mod tests { + use super::parse_delta; + + #[test] + fn extracts_content_delta() { + let d = r#"{"choices":[{"delta":{"content":"hi"}}]}"#; + assert_eq!(parse_delta(d).as_deref(), Some("hi")); + } + + #[test] + fn ignores_role_only_and_tool_frames() { + assert!(parse_delta(r#"{"choices":[{"delta":{"role":"assistant"}}]}"#).is_none()); + assert!(parse_delta(r#"{"choices":[{"delta":{"tool_calls":[]}}]}"#).is_none()); + assert!(parse_delta(r#"{"choices":[{"delta":{"content":""}}]}"#).is_none()); + } + + #[test] + fn ignores_malformed_json_rather_than_failing_the_stream() { + assert!(parse_delta("not json").is_none()); + assert!(parse_delta("{}").is_none()); + } +} diff --git a/pkgs/luna-voice/src/config.rs b/pkgs/luna-voice/src/config.rs new file mode 100644 index 0000000..10604cf --- /dev/null +++ b/pkgs/luna-voice/src/config.rs @@ -0,0 +1,80 @@ +use anyhow::{Context, Result}; +use std::path::PathBuf; + +/// Everything the daemon needs, all from the environment so the NixOS module +/// is the only place that knows paths. Secrets arrive as *_FILE (sops paths), +/// never as values — an env var is readable from /proc for anything of the +/// user's, a 0400 file is not. +pub struct Config { + pub hermes_url: String, + pub hermes_key: String, + pub model: String, + pub system_prompt: Option, + + pub eleven_key: String, + pub voice_id: String, + pub tts_model: String, + + pub whisper_bin: String, + pub whisper_model: PathBuf, + + pub socket_path: PathBuf, + /// Speech during playback louder than noise_floor * this counts as barge-in. + pub barge_in_mult: f32, + pub barge_in_grace_ms: u64, +} + +fn env(key: &str) -> Result { + std::env::var(key).with_context(|| format!("{key} is not set")) +} + +fn env_or(key: &str, default: &str) -> String { + std::env::var(key).unwrap_or_else(|_| default.to_string()) +} + +/// Reads a secret out of a file and trims it. A trailing newline in a bearer +/// token produces a 401 whose message says nothing about whitespace. +fn secret(key: &str) -> Result { + let path = env(key)?; + let raw = std::fs::read_to_string(&path).with_context(|| format!("reading {path}"))?; + Ok(raw.trim().to_string()) +} + +impl Config { + pub fn from_env() -> Result { + let runtime = env_or( + "XDG_RUNTIME_DIR", + &format!("/run/user/{}", unsafe { libc_getuid() }), + ); + Ok(Config { + hermes_url: env_or("LUNA_HERMES_URL", "http://mars.orbit.sol:8642"), + hermes_key: secret("LUNA_HERMES_KEY_FILE")?, + model: env_or("LUNA_MODEL", "hermes"), + system_prompt: std::env::var("LUNA_SYSTEM_PROMPT").ok(), + + eleven_key: secret("LUNA_ELEVENLABS_KEY_FILE")?, + voice_id: env("LUNA_VOICE_ID")?, + tts_model: env_or("LUNA_TTS_MODEL", "eleven_flash_v2_5"), + + whisper_bin: env_or("LUNA_WHISPER_BIN", "whisper-cli"), + whisper_model: PathBuf::from(env("LUNA_WHISPER_MODEL")?), + + socket_path: PathBuf::from(env_or( + "LUNA_SOCKET", + &format!("{runtime}/luna-voiced.sock"), + )), + barge_in_mult: env_or("LUNA_BARGE_IN_MULT", "3.0").parse().unwrap_or(3.0), + barge_in_grace_ms: env_or("LUNA_BARGE_IN_GRACE_MS", "500") + .parse() + .unwrap_or(500), + }) + } +} + +// Avoids pulling in the libc crate for one call. +unsafe fn libc_getuid() -> u32 { + extern "C" { + fn getuid() -> u32; + } + getuid() +} diff --git a/pkgs/luna-voice/src/ipc.rs b/pkgs/luna-voice/src/ipc.rs new file mode 100644 index 0000000..1520972 --- /dev/null +++ b/pkgs/luna-voice/src/ipc.rs @@ -0,0 +1,183 @@ +use anyhow::Result; +use serde::Serialize; +use std::path::{Path, PathBuf}; +use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; +use tokio::net::{UnixListener, UnixStream}; +use tokio::sync::{broadcast, mpsc}; + +use crate::visemes::Viseme; + +/// Daemon -> shell. Newline-delimited JSON; the shell reads it with a +/// SplitParser and never has to spawn anything. +#[derive(Serialize, Clone, Debug)] +#[serde(tag = "type", rename_all = "snake_case")] +pub enum Event { + State { value: &'static str }, + /// Emitted when the first PCM frame reaches the speaker. Viseme offsets + /// are relative to THIS, so the two processes never compare clocks. + SpeechStart, + Visemes { seq: Vec }, + Amplitude { rms: f32 }, + /// What was said, and by whom. Her side is emitted sentence by sentence + /// as it goes to the synthesiser, so subtitles can lead the audio the + /// same way the visemes do. + Caption { speaker: &'static str, text: String }, + SpeechStop { reason: &'static str }, + Error { message: String }, +} + +/// Shell -> daemon. +#[derive(Debug, Clone)] +pub enum Command { + Ptt { down: bool }, + Cancel, + /// Run a turn from typed text, skipping the microphone entirely. This is + /// how the brain -> TTS -> speaker half gets tested without speaking, and + /// how you tell a broken mic from a broken pipeline. + Say { text: String }, +} + +pub struct Ipc { + pub events: broadcast::Sender, + path: PathBuf, +} + +impl Ipc { + /// Binds the socket and serves it until dropped. A stale socket from a + /// crashed run is removed first — bind() would fail with EADDRINUSE on a + /// file nothing is listening to. + pub fn bind(path: &Path, commands: mpsc::Sender) -> Result { + if path.exists() { + let _ = std::fs::remove_file(path); + } + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent)?; + } + let listener = UnixListener::bind(path)?; + let (events, _) = broadcast::channel(256); + + let tx = events.clone(); + tokio::spawn(async move { + loop { + match listener.accept().await { + Ok((stream, _)) => { + let rx = tx.subscribe(); + let cmds = commands.clone(); + tokio::spawn(client(stream, rx, cmds)); + } + Err(e) => { + eprintln!("luna-voice: accept failed: {e}"); + return; + } + } + } + }); + + Ok(Ipc { events, path: path.to_path_buf() }) + } + + pub fn emit(&self, event: Event) { + // An error here only means nobody is connected, which is normal. + let _ = self.events.send(event); + } +} + +impl Drop for Ipc { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.path); + } +} + +async fn client( + stream: UnixStream, + mut rx: broadcast::Receiver, + commands: mpsc::Sender, +) { + let (read, mut write) = stream.into_split(); + let mut lines = BufReader::new(read).lines(); + + loop { + tokio::select! { + event = rx.recv() => { + let Ok(event) = event else { return }; + let Ok(mut line) = serde_json::to_string(&event) else { continue }; + line.push('\n'); + if write.write_all(line.as_bytes()).await.is_err() { + return; + } + } + line = lines.next_line() => { + match line { + Ok(Some(line)) => { + if let Some(cmd) = parse_command(&line) { + let _ = commands.send(cmd).await; + } + } + _ => return, + } + } + } + } +} + +fn parse_command(line: &str) -> Option { + let v: serde_json::Value = serde_json::from_str(line).ok()?; + match v.get("type")?.as_str()? { + "ptt" => Some(Command::Ptt { + down: v.get("down").and_then(|d| d.as_bool()).unwrap_or(false), + }), + "cancel" => Some(Command::Cancel), + "say" => Some(Command::Say { + text: v.get("text")?.as_str()?.to_string(), + }), + _ => None, + } +} + +/// Client side of the same socket, for the `luna-voice ptt` subcommand that +/// Hyprland binds a key to before the quickshell widget exists. +pub async fn send_command(path: &Path, line: &str) -> Result<()> { + let mut stream = UnixStream::connect(path).await?; + stream.write_all(format!("{line}\n").as_bytes()).await?; + stream.flush().await?; + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_ptt_commands() { + assert!(matches!( + parse_command(r#"{"type":"ptt","down":true}"#), + Some(Command::Ptt { down: true }) + )); + assert!(matches!( + parse_command(r#"{"type":"ptt","down":false}"#), + Some(Command::Ptt { down: false }) + )); + } + + #[test] + fn ptt_without_down_defaults_to_release() { + assert!(matches!( + parse_command(r#"{"type":"ptt"}"#), + Some(Command::Ptt { down: false }) + )); + } + + #[test] + fn ignores_unknown_and_malformed() { + assert!(parse_command(r#"{"type":"nope"}"#).is_none()); + assert!(parse_command("garbage").is_none()); + } + + #[test] + fn events_serialise_with_a_type_tag() { + let json = serde_json::to_string(&Event::State { value: "listening" }).unwrap(); + assert_eq!(json, r#"{"type":"state","value":"listening"}"#); + let json = serde_json::to_string(&Event::SpeechStart).unwrap(); + assert_eq!(json, r#"{"type":"speech_start"}"#); + } +} diff --git a/pkgs/luna-voice/src/main.rs b/pkgs/luna-voice/src/main.rs new file mode 100644 index 0000000..cc15c90 --- /dev/null +++ b/pkgs/luna-voice/src/main.rs @@ -0,0 +1,336 @@ +//! luna-voiced — push-to-talk voice loop for luna (the Hermes Agent on mars). +//! +//! mic -> whisper (local, vulkan) -> Hermes /v1/chat/completions -> ElevenLabs +//! streaming TTS -> speaker, with the speaking state, amplitude and viseme +//! timeline published on a unix socket for the quickshell avatar. +//! +//! Nothing here talks to the compositor: push-to-talk arrives over the same +//! socket, from either `luna-voice ptt` or the shell's GlobalShortcut. + +mod audio; +mod brain; +mod config; +mod ipc; +mod stt; +mod tts; +mod visemes; + +use anyhow::Result; +use serde_json; +use config::Config; +use ipc::{Command, Event}; +use std::sync::Arc; +use std::time::Duration; +use tokio::sync::mpsc; + +#[tokio::main] +async fn main() -> Result<()> { + let mut args = std::env::args().skip(1); + match args.next().as_deref() { + None | Some("daemon") => daemon().await, + // Fire-and-forget clients so a keybind costs one short-lived process + // and never blocks the compositor. + Some("ptt-down") => client(r#"{"type":"ptt","down":true}"#).await, + Some("ptt-up") => client(r#"{"type":"ptt","down":false}"#).await, + Some("cancel") => client(r#"{"type":"cancel"}"#).await, + // The debugging tool: everything the avatar will eventually see, + // printed. `journalctl -fu luna-voiced` shows only what the daemon + // chose to log; this shows the actual protocol. + Some("watch") => watch().await, + Some("say") => { + let text: Vec = args.collect(); + if text.is_empty() { + eprintln!("luna-voice: say what?"); + std::process::exit(2); + } + let payload = serde_json::json!({ "type": "say", "text": text.join(" ") }); + client(&payload.to_string()).await + } + Some(other) => { + eprintln!("luna-voice: unknown command {other:?}"); + eprintln!("usage: luna-voice [daemon|ptt-down|ptt-up|cancel|watch]"); + std::process::exit(2); + } + } +} + +fn socket_path() -> std::path::PathBuf { + let runtime = std::env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/run/user/1000".into()); + std::env::var("LUNA_SOCKET") + .map(std::path::PathBuf::from) + .unwrap_or_else(|_| std::path::Path::new(&runtime).join("luna-voiced.sock")) +} + +async fn watch() -> Result<()> { + use tokio::io::{AsyncBufReadExt, BufReader}; + let path = socket_path(); + let stream = tokio::net::UnixStream::connect(&path) + .await + .map_err(|e| anyhow::anyhow!("{}: {e} (is luna-voiced running?)", path.display()))?; + let mut lines = BufReader::new(stream).lines(); + eprintln!("luna-voice: watching {}", path.display()); + while let Some(line) = lines.next_line().await? { + println!("{line}"); + } + Ok(()) +} + +async fn client(line: &str) -> Result<()> { + ipc::send_command(&socket_path(), line).await +} + +/// Errors go to the desktop, not just the journal — terra runs its own +/// notification daemon (HyprChrome/Widgets/Notifications), so this is the one +/// channel that is visible while you are talking rather than debugging. +/// Best-effort: a missing notify-send must never take the daemon down. +fn notify(body: &str) { + let _ = std::process::Command::new("notify-send") + .args(["-a", "luna", "-u", "critical", "luna voice", body]) + .spawn(); +} + +/// Where the loop is. One utterance at a time by construction: the state +/// machine is a single task, so there is no way to start a second reply while +/// one is in flight. +async fn daemon() -> Result<()> { + let cfg = Arc::new(Config::from_env()?); + let capture = audio::Capture::new()?; + let playback = Arc::new(audio::Playback::new()?); + + let (cmd_tx, mut cmd_rx) = mpsc::channel::(16); + let ipc = Arc::new(ipc::Ipc::bind(&cfg.socket_path, cmd_tx)?); + eprintln!("luna-voice: listening on {}", cfg.socket_path.display()); + + let http = reqwest::Client::builder() + // Her replies can involve tool calls; the default 30s would cut those + // off mid-thought. + .timeout(Duration::from_secs(300)) + .build()?; + + let mut history: Vec = Vec::new(); + if let Some(prompt) = &cfg.system_prompt { + history.push(brain::Message::system(prompt.clone())); + } + + ipc.emit(Event::State { value: "idle" }); + + // Her first reply after the container starts costs ~16s against ~5s warm, + // and the first one is always the one you are sitting there waiting for. + // Spending one throwaway token at login moves that cost off the + // conversation. Failure is ignored on purpose: mars may simply be down, + // which must not stop the daemon from coming up. + tokio::spawn({ + let (http, url, key, model) = + (http.clone(), cfg.hermes_url.clone(), cfg.hermes_key.clone(), cfg.model.clone()); + async move { + let (tx, mut rx) = mpsc::channel(4); + tokio::spawn(async move { while rx.recv().await.is_some() {} }); + let warm = [brain::Message::user("hi")]; + match brain::stream_reply(&http, &url, &key, &model, &warm, tx).await { + Ok(_) => eprintln!("luna-voice: warmed up"), + Err(e) => eprintln!("luna-voice: warmup skipped: {e}"), + } + } + }); + + while let Some(cmd) = cmd_rx.recv().await { + match cmd { + Command::Ptt { down: true } => { + // Anything still playing is cut off: pressing the key while + // she talks means you want to talk instead. + playback.clear(); + capture.start(); + playback.beep(880.0, 70); + ipc.emit(Event::State { value: "listening" }); + } + Command::Ptt { down: false } => { + let samples = capture.stop(); + playback.beep(587.0, 70); + ipc.emit(Event::State { value: "thinking" }); + + let heard = + match stt::transcribe(&cfg.whisper_bin, &cfg.whisper_model, &samples).await { + Ok(h) => h, + Err(e) => { + eprintln!("luna-voice: {e:#}"); + ipc.emit(Event::Error { message: e.to_string() }); + notify(&e.to_string()); + ipc.emit(Event::State { value: "idle" }); + continue; + } + }; + + if heard.is_empty() { + // Distinct low tone: "I heard nothing" and "I am + // thinking" must not feel the same, or a dead mic reads + // as a slow reply. + playback.beep(220.0, 120); + eprintln!("luna-voice: nothing heard ({} samples)", samples.len()); + ipc.emit(Event::SpeechStop { reason: "nothing_heard" }); + ipc.emit(Event::State { value: "idle" }); + continue; + } + + run_turn(&cfg, &http, &ipc, &capture, &playback, &mut cmd_rx, &mut history, heard) + .await; + } + Command::Say { text } => { + ipc.emit(Event::State { value: "thinking" }); + run_turn(&cfg, &http, &ipc, &capture, &playback, &mut cmd_rx, &mut history, text) + .await; + } + Command::Cancel => { + playback.clear(); + ipc.emit(Event::SpeechStop { reason: "cancelled" }); + ipc.emit(Event::State { value: "idle" }); + } + } + } + Ok(()) +} + +/// Runs one turn and reports failure through every channel that has a +/// listener: journal, socket, desktop notification. +#[allow(clippy::too_many_arguments)] +async fn run_turn( + cfg: &Config, + http: &reqwest::Client, + ipc: &Arc, + capture: &audio::Capture, + playback: &Arc, + cmd_rx: &mut mpsc::Receiver, + history: &mut Vec, + heard: String, +) { + if let Err(e) = turn(cfg, http, ipc, capture, playback, cmd_rx, history, heard).await { + eprintln!("luna-voice: {e:#}"); + ipc.emit(Event::Error { message: e.to_string() }); + notify(&e.to_string()); + } + ipc.emit(Event::State { value: "idle" }); +} + +#[allow(clippy::too_many_arguments)] +async fn turn( + cfg: &Config, + http: &reqwest::Client, + ipc: &Arc, + capture: &audio::Capture, + playback: &Arc, + cmd_rx: &mut mpsc::Receiver, + history: &mut Vec, + heard: String, +) -> Result<()> { + eprintln!("luna-voice: heard {heard:?}"); + ipc.emit(Event::Caption { speaker: "user", text: heard.clone() }); + history.push(brain::Message::user(heard)); + + // Noise floor sampled before she starts, so barge-in adapts to the room + // rather than to a constant. + let floor = capture.level().max(0.005); + + let (sentence_tx, sentence_rx) = mpsc::channel::(16); + let (event_tx, mut event_rx) = mpsc::channel::(64); + + let speech = tokio::spawn({ + let tts_cfg = tts::TtsConfig { + key: cfg.eleven_key.clone(), + voice_id: cfg.voice_id.clone(), + model: cfg.tts_model.clone(), + }; + async move { tts::speak(&tts_cfg, sentence_rx, event_tx).await } + }); + + // Audio and visemes flow to the speaker/shell on their own task so the + // reply stream is never blocked by playback. + let player = tokio::spawn({ + let ipc = ipc.clone(); + let playback = playback.clone(); + async move { + let mut started = false; + while let Some(ev) = event_rx.recv().await { + match ev { + tts::SpeechEvent::Audio(pcm) => { + if !started { + started = true; + ipc.emit(Event::SpeechStart); + ipc.emit(Event::State { value: "speaking" }); + } + playback.push(&pcm); + } + // A chunk whose alignment held nothing visible still + // arrives; forwarding it would make the shell reset the + // mouth mid-word. + tts::SpeechEvent::Visemes(seq) if !seq.is_empty() => { + ipc.emit(Event::Visemes { seq }) + } + tts::SpeechEvent::Visemes(_) => {} + tts::SpeechEvent::Done => break, + } + } + } + }); + + let (delta_tx, mut delta_rx) = mpsc::channel::(64); + let reply = tokio::spawn({ + let http = http.clone(); + let (url, key, model) = (cfg.hermes_url.clone(), cfg.hermes_key.clone(), cfg.model.clone()); + let history = history.clone(); + async move { brain::stream_reply(&http, &url, &key, &model, &history, delta_tx).await } + }); + + let mut splitter = tts::SentenceSplitter::new(); + while let Some(delta) = delta_rx.recv().await { + for sentence in splitter.push(&delta) { + ipc.emit(Event::Caption { speaker: "luna", text: sentence.clone() }); + if sentence_tx.send(sentence).await.is_err() { + break; + } + } + } + if let Some(tail) = splitter.finish() { + ipc.emit(Event::Caption { speaker: "luna", text: tail.clone() }); + let _ = sentence_tx.send(tail).await; + } + drop(sentence_tx); + + let full = reply.await??; + eprintln!("luna-voice: said {:?}", full.trim()); + if !full.trim().is_empty() { + history.push(brain::Message::assistant(full)); + } + + // Wait for the speaker to drain, watching for barge-in. Polling the queue + // is enough: cpal gives no drain callback, and 50ms of latency on "she + // finished" is invisible. + let grace = tokio::time::Instant::now() + Duration::from_millis(cfg.barge_in_grace_ms); + loop { + if speech.is_finished() && playback.pending() == 0 { + break; + } + if tokio::time::Instant::now() > grace + && capture.level() > floor * cfg.barge_in_mult + { + playback.clear(); + ipc.emit(Event::SpeechStop { reason: "barge_in" }); + // She is told she was cut off, so the next turn can react to it + // rather than carrying on obliviously. + history.push(brain::Message::system( + "[The user interrupted you mid-sentence.]", + )); + break; + } + // A cancel arriving mid-playback must be honoured now, not after. + if let Ok(Command::Cancel) = cmd_rx.try_recv() { + playback.clear(); + ipc.emit(Event::SpeechStop { reason: "cancelled" }); + break; + } + ipc.emit(Event::Amplitude { rms: capture.level() }); + tokio::time::sleep(Duration::from_millis(50)).await; + } + + speech.abort(); + player.abort(); + Ok(()) +} diff --git a/pkgs/luna-voice/src/stt.rs b/pkgs/luna-voice/src/stt.rs new file mode 100644 index 0000000..478076b --- /dev/null +++ b/pkgs/luna-voice/src/stt.rs @@ -0,0 +1,112 @@ +use crate::audio; +use anyhow::{bail, Result}; +use std::path::Path; +use tokio::process::Command; + +/// Shells out to whisper-cli rather than linking whisper.cpp: nixpkgs already +/// ships whisper-cpp-vulkan built against this box's GPU stack, and a bundled +/// build would have to rediscover that at cargo time. +pub async fn transcribe(bin: &str, model: &Path, samples: &[f32]) -> Result { + // Whisper hallucinates confident words into silence — "you", "Thank + // you.", "Bye." — which then reach luna as if spoken. Duration alone does + // not catch it (a held key over a quiet room is long AND empty), so gate + // on level too. + if samples.len() < (audio::STT_RATE as usize) / 3 || !has_speech(samples) { + return Ok(String::new()); + } + + let dir = std::env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".into()); + let wav = Path::new(&dir).join(format!("luna-stt-{}.wav", std::process::id())); + audio::write_wav(&wav, samples, audio::STT_RATE)?; + + let out = Command::new(bin) + .args(["-m"]) + .arg(model) + .args(["-f"]) + .arg(&wav) + // -nt: transcript only, no [00:00:00] prefixes. -np: no progress + // banner. Together they make stdout exactly the text. + .args(["-nt", "-np"]) + .output() + .await?; + let _ = std::fs::remove_file(&wav); + + if !out.status.success() { + bail!( + "whisper-cli failed: {}", + String::from_utf8_lossy(&out.stderr).trim() + ); + } + Ok(clean(&String::from_utf8_lossy(&out.stdout))) +} + +/// True if any 100ms window is loud enough to be a voice. Peak rather than +/// overall RMS: a short sentence inside a long silent recording averages down +/// to nothing, and that is the common case for a held key. +fn has_speech(samples: &[f32]) -> bool { + const FLOOR: f32 = 0.015; + let window = (audio::STT_RATE as usize) / 10; + samples.chunks(window).any(|w| { + let sum: f32 = w.iter().map(|s| s * s).sum(); + (sum / w.len().max(1) as f32).sqrt() > FLOOR + }) +} + +/// whisper emits bracketed non-speech annotations ([BLANK_AUDIO], (wind +/// blowing)) that are not words and must not reach the agent. +fn clean(raw: &str) -> String { + let mut out = String::new(); + let mut depth = 0i32; + for c in raw.chars() { + match c { + '[' | '(' => depth += 1, + ']' | ')' => depth = (depth - 1).max(0), + c if depth == 0 => out.push(c), + _ => {} + } + } + out.split_whitespace().collect::>().join(" ") +} + +#[cfg(test)] +mod tests { + use super::{clean, has_speech}; + use crate::audio::STT_RATE; + + #[test] + fn silence_is_not_speech() { + assert!(!has_speech(&vec![0.0f32; STT_RATE as usize])); + // Room tone: audible on a meter, not a voice. + assert!(!has_speech(&vec![0.004f32; STT_RATE as usize])); + } + + #[test] + fn a_short_utterance_in_a_long_silence_counts() { + let mut s = vec![0.0f32; STT_RATE as usize]; + for v in s.iter_mut().take(STT_RATE as usize / 5) { + *v = 0.2; + } + assert!(has_speech(&s)); + } + + #[test] + fn strips_bracketed_annotations() { + assert_eq!(clean("[BLANK_AUDIO]"), ""); + assert_eq!(clean(" hello (wind blowing) there \n"), "hello there"); + assert_eq!(clean("[ music ] real words"), "real words"); + } + + #[test] + fn collapses_whitespace() { + assert_eq!(clean(" a b \n c "), "a b c"); + } + + #[test] + fn unbalanced_brackets_do_not_eat_the_rest() { + // The stray closer is dropped (depth floors at 0) but the words + // around it survive — the failure mode that matters is a lone + // bracket swallowing the whole transcript. + assert_eq!(clean("ok] fine"), "ok fine"); + assert_eq!(clean("[ oops real words"), ""); + } +} diff --git a/pkgs/luna-voice/src/tts.rs b/pkgs/luna-voice/src/tts.rs new file mode 100644 index 0000000..cf2cffa --- /dev/null +++ b/pkgs/luna-voice/src/tts.rs @@ -0,0 +1,319 @@ +use crate::audio; +use crate::visemes::{self, Viseme}; +use anyhow::Result; +use base64::Engine; +use futures_util::{SinkExt, StreamExt}; +use tokio::sync::mpsc; +use tokio_tungstenite::tungstenite::client::IntoClientRequest; +use tokio_tungstenite::tungstenite::Message as Ws; + +pub enum SpeechEvent { + /// Decoded PCM at audio::TTS_RATE. + Audio(Vec), + /// Mouth shapes, timed from the start of this reply's audio. + Visemes(Vec), + Done, +} + +pub struct TtsConfig { + pub key: String, + pub voice_id: String, + pub model: String, +} + +/// Speaks sentences as they arrive on `sentences`, over one websocket per +/// reply. +/// +/// pcm_24000 rather than the default mp3: there is no decoder in this process +/// and no reason to add one. sync_alignment makes the character timings ride +/// along with the audio frames instead of needing a second request. +pub async fn speak( + cfg: &TtsConfig, + mut sentences: mpsc::Receiver, + events: mpsc::Sender, +) -> Result<()> { + let url = format!( + "wss://api.elevenlabs.io/v1/text-to-speech/{}/stream-input\ + ?model_id={}&output_format=pcm_{}&sync_alignment=true&auto_mode=true", + cfg.voice_id, + cfg.model, + audio::TTS_RATE + ); + let mut req = url.into_client_request()?; + // Header, not the ?authorization= query param: a key in a URL ends up in + // every proxy and error log that touches it. + req.headers_mut().insert( + "xi-api-key", + tokio_tungstenite::tungstenite::http::HeaderValue::from_str(&cfg.key)?, + ); + + let (stream, _) = tokio_tungstenite::connect_async(req).await?; + let (mut sink, mut source) = stream.split(); + + // The protocol requires an opening frame of a single space before any + // real text; it carries the voice settings for the whole connection. + sink.send(Ws::Text( + serde_json::json!({ + "text": " ", + "voice_settings": { "stability": 0.4, "similarity_boost": 0.8, "speed": 1.0 }, + }) + .to_string(), + )) + .await?; + + let reader = tokio::spawn(async move { + // Alignment times may be per-chunk or cumulative depending on the + // model; `emitted_ms` lets us normalise either into one timeline. + let mut emitted_ms: u32 = 0; + while let Some(Ok(msg)) = source.next().await { + let Ws::Text(txt) = msg else { continue }; + let Ok(v) = serde_json::from_str::(&txt) else { continue }; + + if let Some(b64) = v.get("audio").and_then(|a| a.as_str()) { + if let Ok(bytes) = base64::engine::general_purpose::STANDARD.decode(b64) { + let pcm = audio::pcm16_to_f32(&bytes); + let chunk_ms = (pcm.len() as f64 / audio::TTS_RATE as f64 * 1000.0) as u32; + if let Some(al) = v.get("normalizedAlignment").or_else(|| v.get("alignment")) { + if let Some(t) = alignment_to_timeline(al, emitted_ms) { + let _ = events.send(SpeechEvent::Visemes(t)).await; + } + } + emitted_ms += chunk_ms; + if events.send(SpeechEvent::Audio(pcm)).await.is_err() { + return; // receiver gone: barge-in cancelled this reply + } + } + } + if v.get("isFinal").and_then(|f| f.as_bool()).unwrap_or(false) { + break; + } + } + let _ = events.send(SpeechEvent::Done).await; + }); + + while let Some(text) = sentences.recv().await { + // Every text frame must end with a space or the model holds the last + // word back waiting for more input. + let text = format!("{} ", text.trim()); + sink.send(Ws::Text( + serde_json::json!({ "text": text }).to_string(), + )) + .await?; + } + + // Empty string = end of input. Without it the socket sits until the + // inactivity timeout and the last sentence never gets flushed. + sink.send(Ws::Text(serde_json::json!({ "text": "" }).to_string())) + .await?; + let _ = reader.await; + Ok(()) +} + +fn alignment_to_timeline(al: &serde_json::Value, emitted_ms: u32) -> Option> { + let chars: Vec = al + .get("chars")? + .as_array()? + .iter() + .map(|c| c.as_str().unwrap_or("").to_string()) + .collect(); + let starts: Vec = num_array(al.get("charStartTimesMs")?)?; + let durs: Vec = num_array(al.get("charDurationsMs")?)?; + let starts = absolutize(&starts, emitted_ms); + Some(visemes::timeline(&chars, &starts, &durs)) +} + +fn num_array(v: &serde_json::Value) -> Option> { + Some(v.as_array()?.iter().map(|n| n.as_i64().unwrap_or(0)).collect()) +} + +/// Normalises chunk-relative and stream-absolute alignments into one +/// timeline. If the first start time is behind audio we have already emitted, +/// the timings must be relative to this chunk, so they get shifted. +fn absolutize(starts: &[i64], emitted_ms: u32) -> Vec { + let offset = match starts.first() { + Some(&first) if first < emitted_ms as i64 => emitted_ms as i64, + _ => 0, + }; + starts.iter().map(|s| s + offset).collect() +} + +/// Splits streamed text into speakable sentences, and strips what should +/// never be read aloud. Hermes' own voice mode does the same thing for the +/// same reason: without it she pronounces asterisks. +pub struct SentenceSplitter { + buf: String, + in_think: bool, +} + +impl SentenceSplitter { + pub fn new() -> Self { + SentenceSplitter { buf: String::new(), in_think: false } + } + + /// Feeds a delta, returning any sentences that completed. + pub fn push(&mut self, delta: &str) -> Vec { + self.buf.push_str(delta); + let mut out = Vec::new(); + + // blocks are reasoning, not speech, and can be long. + loop { + if self.in_think { + match self.buf.find("") { + Some(i) => { + self.buf.drain(..i + "".len()); + self.in_think = false; + } + None => { + self.buf.clear(); + return out; + } + } + } + match self.buf.find("") { + Some(i) => { + let head: String = self.buf.drain(..i).collect(); + self.buf.drain(.."".len()); + self.in_think = true; + out.extend(drain_sentences(&mut { head.clone() }, true)); + } + None => break, + } + } + + out.extend(drain_sentences(&mut self.buf, false)); + out.into_iter().filter(|s| !s.is_empty()).collect() + } + + /// Whatever is left when the reply ends. + pub fn finish(&mut self) -> Option { + let rest = clean_for_speech(&std::mem::take(&mut self.buf)); + (!rest.is_empty()).then_some(rest) + } +} + +fn drain_sentences(buf: &mut String, force: bool) -> Vec { + let mut out = Vec::new(); + // A sentence is only worth sending once it is long enough to synthesise + // well; ElevenLabs' own guidance is ~20 characters minimum. + while let Some(end) = buf.find(['.', '!', '?', '\n']) { + if end < 20 && !force { + // Abbreviation or a very short clause — keep accumulating. + if buf.len() < 80 { + break; + } + } + let s: String = buf.drain(..end + 1).collect(); + let s = clean_for_speech(&s); + if !s.is_empty() { + out.push(s); + } + } + if force && !buf.is_empty() { + let s = clean_for_speech(&std::mem::take(buf)); + if !s.is_empty() { + out.push(s); + } + } + out +} + +/// Markdown, emoji and kaomoji are for eyes. +/// +/// A whitelist, not a blacklist: she writes things like "(¬‿¬)", whose +/// characters live in ordinary Latin-1 and punctuation blocks rather than in +/// any emoji range, so enumerating what to drop never converges. Letters +/// stays unicode-aware on purpose — German is in scope, "ö" is a letter. +pub fn clean_for_speech(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + for c in s.chars() { + if c.is_alphanumeric() || c.is_whitespace() || is_speakable_punctuation(c) { + out.push(c); + } else if matches!(c, '—' | '–') { + // " — " must not leave " , ": the comma binds to the word before it. + while out.chars().last().is_some_and(char::is_whitespace) { + out.pop(); + } + // An em dash is a pause, not a space. Dropping it runs the two + // clauses together and changes what the sentence means; a comma + // is the closest thing the synthesiser understands. ASCII '-' + // deliberately does NOT land here — it is usually intra-word + // ("push-to-talk"), where a comma would be worse than a space. + out.push(','); + } else { + // Not dropped silently: a symbol between two words is usually a + // dash or a bullet, and gluing the words together mispronounces + // both. + out.push(' '); + } + } + out.split_whitespace().collect::>().join(" ") +} + +/// Punctuation a TTS model actually uses for prosody. Everything else is +/// noise once it reaches audio. +fn is_speakable_punctuation(c: char) -> bool { + matches!(c, '.' | ',' | '!' | '?' | ';' | ':' | '\'' | '"') +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn absolutize_shifts_chunk_relative_times() { + assert_eq!(absolutize(&[0, 50], 1000), vec![1000, 1050]); + } + + #[test] + fn absolutize_leaves_already_absolute_times() { + assert_eq!(absolutize(&[1000, 1050], 1000), vec![1000, 1050]); + } + + #[test] + fn splitter_emits_complete_sentences_only() { + let mut s = SentenceSplitter::new(); + assert!(s.push("This is a long enough first sentence").is_empty()); + let got = s.push(". And more"); + assert_eq!(got, vec!["This is a long enough first sentence."]); + } + + #[test] + fn splitter_drops_think_blocks() { + let mut s = SentenceSplitter::new(); + s.push("internal monologue that is long"); + let got = s.push("Actually speakable sentence here. "); + assert_eq!(got, vec!["Actually speakable sentence here."]); + } + + #[test] + fn splitter_returns_tail_on_finish() { + let mut s = SentenceSplitter::new(); + s.push("no terminator here"); + assert_eq!(s.finish().as_deref(), Some("no terminator here")); + } + + #[test] + fn markdown_and_emoji_never_reach_the_voice() { + assert_eq!(clean_for_speech("**bold** `code` 🎉 ok"), "bold code ok"); + } + + #[test] + fn kaomoji_and_dashes_are_stripped_without_gluing_words() { + // Her actual first reply over the API. + assert_eq!( + clean_for_speech("Loud and clear, boss — hallo! (¬‿¬)"), + "Loud and clear, boss, hallo!" + ); + } + + #[test] + fn em_dash_becomes_a_pause_but_hyphens_do_not() { + assert_eq!(clean_for_speech("I can't confirm — there's nothing"), "I can't confirm, there's nothing"); + assert_eq!(clean_for_speech("push-to-talk"), "push to talk"); + } + + #[test] + fn keeps_non_ascii_letters() { + assert_eq!(clean_for_speech("schön, größer"), "schön, größer"); + } +} diff --git a/pkgs/luna-voice/src/visemes.rs b/pkgs/luna-voice/src/visemes.rs new file mode 100644 index 0000000..6f854fd --- /dev/null +++ b/pkgs/luna-voice/src/visemes.rs @@ -0,0 +1,131 @@ +use serde::Serialize; + +/// VRM 1.0's standard mouth expressions, which is what the avatar rig exposes +/// (`aa`/`ih`/`ou`/`ee`/`oh`). A rig with the full ARKit 52 can map these onto +/// jawOpen/mouthFunnel/etc — the shell side owns that, not this. +/// +/// These names are a CONTRACT with the balsam-generated morph targets: the +/// glTF target names become the QML ids, so renaming a shape key in Blender +/// breaks the binding silently, with no eval error. +pub const SILENCE: &str = "sil"; + +#[derive(Debug, Clone, PartialEq, Serialize)] +pub struct Viseme { + pub shape: &'static str, + /// Milliseconds from speech_start, NOT wall clock — the shell starts its + /// own timer when the first PCM frame hits the speaker, so the two clocks + /// never have to agree. + pub at: u32, + pub ms: u32, +} + +/// One character to a mouth shape. English orthography is a lie about +/// phonetics, but at 40ms of animation per character nobody can tell: what +/// reads as "talking" is the OPEN/CLOSE rhythm, not vowel accuracy. +fn shape_for(c: char) -> &'static str { + match c.to_ascii_lowercase() { + 'a' => "aa", + 'e' => "ee", + 'i' | 'y' => "ih", + 'o' => "oh", + 'u' | 'w' => "ou", + // Bilabials close the mouth; giving them silence is what produces the + // visible "p/b/m" beat. + 'p' | 'b' | 'm' => SILENCE, + // Everything else is a partially open consonant. "ih" is the least + // committal shape to land on. + c if c.is_alphabetic() => "ih", + _ => SILENCE, + } +} + +/// Builds a playable timeline from ElevenLabs' character alignment. +/// +/// The three arrays are parallel; a short or missing one means the frame was +/// truncated, so we take the shortest common prefix rather than panicking on +/// an index. +pub fn timeline(chars: &[String], starts: &[i64], durations: &[i64]) -> Vec { + let n = chars.len().min(starts.len()).min(durations.len()); + let mut out: Vec = Vec::with_capacity(n); + + for i in 0..n { + let c = match chars[i].chars().next() { + Some(c) => c, + None => continue, + }; + let shape = shape_for(c); + let at = starts[i].max(0) as u32; + let ms = durations[i].max(0) as u32; + + // Merge runs of the same shape: "ll" is one mouth position held, not + // two identical keyframes the shell would re-trigger. + match out.last_mut() { + Some(last) if last.shape == shape && last.at + last.ms >= at => { + last.ms = (at + ms).saturating_sub(last.at); + } + _ => out.push(Viseme { shape, at, ms }), + } + } + + // Sub-frame keys cannot be seen and only cost socket bytes. + out.retain(|v| v.ms >= 20); + out +} + +#[cfg(test)] +mod tests { + use super::*; + + fn s(v: &[&str]) -> Vec { + v.iter().map(|s| s.to_string()).collect() + } + + #[test] + fn maps_vowels_to_distinct_shapes() { + let t = timeline( + &s(&["a", "e", "o"]), + &[0, 100, 200], + &[100, 100, 100], + ); + assert_eq!( + t.iter().map(|v| v.shape).collect::>(), + vec!["aa", "ee", "oh"] + ); + } + + #[test] + fn merges_repeated_shapes_into_one_held_key() { + let t = timeline(&s(&["l", "l", "l"]), &[0, 50, 100], &[50, 50, 50]); + assert_eq!(t.len(), 1); + assert_eq!(t[0].shape, "ih"); + assert_eq!(t[0].at, 0); + assert_eq!(t[0].ms, 150); + } + + #[test] + fn bilabials_close_the_mouth() { + let t = timeline(&s(&["a", "m", "a"]), &[0, 100, 200], &[100, 100, 100]); + assert_eq!(t[1].shape, SILENCE); + } + + #[test] + fn drops_keys_too_short_to_see() { + let t = timeline(&s(&["a", "e"]), &[0, 5], &[5, 100]); + assert_eq!(t.len(), 1); + assert_eq!(t[0].shape, "ee"); + } + + #[test] + fn tolerates_truncated_arrays() { + let t = timeline(&s(&["a", "e", "o"]), &[0, 100], &[100]); + assert_eq!(t.len(), 1); + } + + #[test] + fn punctuation_and_spaces_are_silence() { + let t = timeline(&s(&[" ", ",", "!"]), &[0, 100, 200], &[100, 100, 100]); + assert_eq!(t.len(), 1); + assert_eq!(t[0].shape, SILENCE); + assert_eq!(t[0].ms, 300); + } +} diff --git a/services/desktop/luna-voice.nix b/services/desktop/luna-voice.nix new file mode 100644 index 0000000..be06632 --- /dev/null +++ b/services/desktop/luna-voice.nix @@ -0,0 +1,114 @@ +{ config, pkgs, lib, ... }: + +# Voice loop for luna: hold a key, talk, hear her answer. +# +# mic -> whisper-cpp (local, vulkan) -> Hermes' OpenAI-compatible API on mars +# -> ElevenLabs streaming TTS -> speaker. State, amplitude and the viseme +# timeline are published on a unix socket for the quickshell avatar to read +# (nothing consumes it yet — the widget is the next phase). +# +# A USER service, not a system one: it needs darman's pipewire session and his +# XDG_RUNTIME_DIR for the socket. That is also why the two secrets it reads +# are owner-darman in hosts/terra/secrets.nix — a user manager cannot read a +# root-owned 0400 file, and LoadCredential does not bridge that gap. +# +# STT is LOCAL on purpose: mars already runs faster-whisper for Telegram voice +# notes, but routing the mic through it would put every spoken word on the +# network for no latency win. This is the client-direct path Hermes itself +# documents. + +let + cfg = config.homelab.lunaVoice; + luna-voice = pkgs.callPackage ../../pkgs/luna-voice.nix { }; + + # Pinned like the KittenTTS models on mars: a model that re-downloads at + # first use is a service that fails on a fresh install with no network. + whisperModel = pkgs.fetchurl { + url = "https://huggingface.co/ggerganov/whisper.cpp/resolve/5359861c739e955e79d9a303bcbc70fb988958b1/ggml-base.en.bin"; + sha256 = "sha256-oDd5yG3zMjB19eeWyyzlAp8A7Ihp7uP9+4l6/jbG0AI="; + }; +in +{ + options.homelab.lunaVoice = { + enable = lib.mkEnableOption "luna voice daemon"; + + user = lib.mkOption { + type = lib.types.str; + default = "darman"; + description = "User whose session runs the daemon."; + }; + + hermesUrl = lib.mkOption { + type = lib.types.str; + default = "http://mars.orbit.sol:8642"; + description = "Base URL of luna's Hermes API server (tailnet-only)."; + }; + + model = lib.mkOption { + type = lib.types.str; + default = "hermes-agent"; + description = "Model name to request; Hermes routes it to her configured provider."; + }; + + voiceId = lib.mkOption { + type = lib.types.str; + description = "ElevenLabs voice id — luna's voice."; + }; + + ttsModel = lib.mkOption { + type = lib.types.str; + default = "eleven_flash_v2_5"; + description = "~75ms model, the one ElevenLabs recommends for live conversation."; + }; + + hermesKeyFile = lib.mkOption { + type = lib.types.path; + description = "File holding the API_SERVER_KEY bearer token."; + }; + + elevenLabsKeyFile = lib.mkOption { + type = lib.types.path; + description = "File holding the ElevenLabs API key."; + }; + + systemPrompt = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = '' + Prepended to the conversation. Worth setting to something like "You + are being spoken to out loud; keep replies short" — her Telegram + register is too long-form to listen to. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ luna-voice ]; + + systemd.user.services.luna-voiced = { + description = "luna voice loop"; + wantedBy = [ "graphical-session.target" ]; + after = [ "graphical-session.target" "pipewire.service" ]; + partOf = [ "graphical-session.target" ]; + + environment = { + LUNA_HERMES_URL = cfg.hermesUrl; + LUNA_MODEL = cfg.model; + LUNA_VOICE_ID = cfg.voiceId; + LUNA_TTS_MODEL = cfg.ttsModel; + LUNA_HERMES_KEY_FILE = toString cfg.hermesKeyFile; + LUNA_ELEVENLABS_KEY_FILE = toString cfg.elevenLabsKeyFile; + LUNA_WHISPER_BIN = "${pkgs.whisper-cpp-vulkan}/bin/whisper-cli"; + LUNA_WHISPER_MODEL = whisperModel; + } // lib.optionalAttrs (cfg.systemPrompt != null) { + LUNA_SYSTEM_PROMPT = cfg.systemPrompt; + }; + + serviceConfig = { + ExecStart = "${luna-voice}/bin/luna-voice daemon"; + Restart = "on-failure"; + RestartSec = 3; + }; + }; + }; +}