feat(terra): luna v3 voice, channel marker and rail panel
- TTS defaults to eleven_v3_conversational over the Text to Dialogue socket: performs audio tags and gets her German right. Flash still works via the TTS socket. - Every spoken message is prefixed with a [voice] marker so luna's profile on mars can tell the channel apart. - LunaIndicator/LunaCall replaced by a LunaPanel in the bar rail, with captions; headless test updated to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// Everything the Luna surfaces know, read off luna-voiced's unix socket
|
||||
// (services/desktop/luna-voice.nix).
|
||||
//
|
||||
// Read-only on purpose: the key that toggles voice mode runs `luna-voice
|
||||
// toggle` from Hyprland rather than writing here, so the toggle keeps working
|
||||
// while the shell is reloading — and a QML error can never leave the mic on
|
||||
// with nothing showing it.
|
||||
//
|
||||
// The daemon is a USER service that may start after the shell, restart under
|
||||
// it, or not be installed at all, so a missing socket is a normal state and
|
||||
// not an error: `reconnect` retries quietly and `connected` is what the
|
||||
// widget shows.
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
// "idle" | "listening" | "thinking" | "speaking"
|
||||
property string state: "idle"
|
||||
// Voice mode itself — the widget is only on screen while this is true.
|
||||
property bool active: false
|
||||
property bool connected: socket.connected
|
||||
// Mic level while listening, her output level while speaking. Drives the
|
||||
// only genuinely live part of the visuals.
|
||||
property real rms: 0
|
||||
property string userText: ""
|
||||
property string lunaText: ""
|
||||
property string error: ""
|
||||
|
||||
readonly property var socket: Socket {
|
||||
id: socket
|
||||
path: `${Quickshell.env("XDG_RUNTIME_DIR") ?? "/run/user/1000"}/luna-voiced.sock`
|
||||
connected: true
|
||||
|
||||
onConnectionStateChanged: {
|
||||
if (!socket.connected) {
|
||||
// A daemon that went away is not a daemon that is idle: reset
|
||||
// rather than leave the last frame of a conversation frozen
|
||||
// on screen.
|
||||
root.active = false;
|
||||
root.state = "idle";
|
||||
root.rms = 0;
|
||||
}
|
||||
}
|
||||
|
||||
parser: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: line => root.ingest(line)
|
||||
}
|
||||
}
|
||||
|
||||
// Retry forever, cheaply. Setting `connected` true on an already-open
|
||||
// socket is a no-op, so this doubles as the initial connect.
|
||||
readonly property var reconnect: Timer {
|
||||
interval: 2000
|
||||
running: !socket.connected
|
||||
repeat: true
|
||||
onTriggered: socket.connected = true
|
||||
}
|
||||
|
||||
function ingest(line: string): void {
|
||||
let msg;
|
||||
try {
|
||||
msg = JSON.parse(line);
|
||||
} catch (e) {
|
||||
return; // a half-written line is not worth a console error
|
||||
}
|
||||
|
||||
switch (msg.type) {
|
||||
case "mode":
|
||||
root.active = msg.active;
|
||||
if (!msg.active) {
|
||||
root.state = "idle";
|
||||
root.rms = 0;
|
||||
}
|
||||
break;
|
||||
case "state":
|
||||
root.state = msg.value;
|
||||
// Level is only meaningful during the phase that produces it.
|
||||
if (msg.value !== "listening" && msg.value !== "speaking")
|
||||
root.rms = 0;
|
||||
break;
|
||||
case "amplitude":
|
||||
root.rms = msg.rms;
|
||||
break;
|
||||
case "caption":
|
||||
if (msg.speaker === "user") {
|
||||
// A new user caption starts a turn, so it is what clears her
|
||||
// last reply — NOT speech_start, which arrives after her
|
||||
// first caption, not before it.
|
||||
root.userText = msg.text;
|
||||
root.lunaText = "";
|
||||
} else {
|
||||
root.lunaText = msg.text;
|
||||
}
|
||||
break;
|
||||
case "error":
|
||||
root.error = msg.message;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user