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:
@@ -4,7 +4,7 @@ import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import qs.HyprChrome.Theme
|
||||
import qs.HyprChrome.Widgets.Bar.Debug
|
||||
import qs.HyprChrome.Widgets.Bar.Luna
|
||||
import qs.HyprChrome.Widgets.Bar.Host
|
||||
import qs.HyprChrome.Widgets.Bar.Vitals
|
||||
import qs.HyprChrome.Widgets.Bar.Workspaces
|
||||
@@ -87,8 +87,8 @@ PanelWindow {
|
||||
//
|
||||
// The zone still follows the target height, so tiled windows reflow once
|
||||
// per toggle, at the start, and slide while the panels animate.
|
||||
readonly property real expandedContent: Math.max(hostPanel.expandedHeight, workspacesPanel.expandedHeight, vitalsPanel.expandedHeight, testPanel.expandedHeight, trayPanel.expandedHeight) + window.margin * 2
|
||||
readonly property real contentHeight: Math.max(hostPanel.targetHeight, workspacesPanel.targetHeight, vitalsPanel.targetHeight, testPanel.targetHeight, trayPanel.targetHeight) + window.margin * 2
|
||||
readonly property real expandedContent: Math.max(hostPanel.expandedHeight, workspacesPanel.expandedHeight, vitalsPanel.expandedHeight, lunaPanel.expandedHeight, trayPanel.expandedHeight) + window.margin * 2
|
||||
readonly property real contentHeight: Math.max(hostPanel.targetHeight, workspacesPanel.targetHeight, vitalsPanel.targetHeight, lunaPanel.targetHeight, trayPanel.targetHeight) + window.margin * 2
|
||||
|
||||
implicitHeight: Math.round(window.expandedContent)
|
||||
|
||||
@@ -157,8 +157,8 @@ PanelWindow {
|
||||
// and a trace at each end.
|
||||
Item { Layout.fillWidth: true }
|
||||
|
||||
TestPanel {
|
||||
id: testPanel
|
||||
LunaPanel {
|
||||
id: lunaPanel
|
||||
|
||||
expanded: window.expanded
|
||||
toggleOnClick: false
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import qs.HyprChrome.Theme
|
||||
import qs.HyprChrome.Widgets.Bar.Panels
|
||||
|
||||
// luna's voice loop on the rail (services/desktop/luna-voice.nix).
|
||||
//
|
||||
// Always present, unlike the daemon it watches: the panel is where you look
|
||||
// to find out whether she is listening, so it has to be there when the answer
|
||||
// is "no" — including when luna-voiced is not running at all. SUPER+V toggles
|
||||
// LISTENING, not this.
|
||||
//
|
||||
// Collapsed it is the state and nothing else, because that is the one fact
|
||||
// worth a glance; expanded it carries the last exchange, which is the thing
|
||||
// you actually want during the seconds her reply takes to arrive.
|
||||
BarPanel {
|
||||
id: luna
|
||||
|
||||
// Overridable so the headless render can stage every state without a
|
||||
// daemon; in the rail they track the socket below.
|
||||
property string daemonState: state.state
|
||||
property bool active: state.active
|
||||
property bool connected: state.connected
|
||||
property real rms: state.rms
|
||||
property string userText: state.userText
|
||||
property string lunaText: state.lunaText
|
||||
|
||||
// Instantiated here rather than in the shell: the panel is the only
|
||||
// reader, and it is a second reader that would make this shell state.
|
||||
readonly property var state: LunaState {}
|
||||
|
||||
panelId: "LUN"
|
||||
title: "LUNA"
|
||||
meta: luna.active ? "VOICE" : "IDLE"
|
||||
|
||||
// Sized to content like the tray, and per DENSITY: collapsed it is one
|
||||
// word, so reserving the expanded body's width would leave the rail
|
||||
// carrying a mostly empty panel for the state it spends most of its time
|
||||
// in. It floats between two spacers, so the width change costs no other
|
||||
// panel anything.
|
||||
implicitWidth: luna.expanded
|
||||
? Math.max(luna.headerMinWidth, luna.padding * 2 + body.implicitWidth)
|
||||
: Math.max(luna.headerMinWidth, luna.briefLeft + brief.implicitWidth + luna.padding)
|
||||
|
||||
readonly property color stateColor: {
|
||||
if (!luna.connected)
|
||||
return Theme.disabled;
|
||||
switch (luna.daemonState) {
|
||||
case "listening":
|
||||
return Theme.accent;
|
||||
case "thinking":
|
||||
return Theme.muted;
|
||||
case "speaking":
|
||||
return Theme.accentSoft;
|
||||
default:
|
||||
return luna.active ? Theme.text : Theme.raised;
|
||||
}
|
||||
}
|
||||
|
||||
readonly property string stateLabel: {
|
||||
if (!luna.connected)
|
||||
return "OFFLINE";
|
||||
if (!luna.active)
|
||||
return "OFF";
|
||||
switch (luna.daemonState) {
|
||||
case "listening":
|
||||
return "LISTENING";
|
||||
case "thinking":
|
||||
return "THINKING";
|
||||
case "speaking":
|
||||
return "SPEAKING";
|
||||
default:
|
||||
return "READY";
|
||||
}
|
||||
}
|
||||
|
||||
summary: Row {
|
||||
id: brief
|
||||
spacing: 6
|
||||
|
||||
// Breathes only while the mic is open, so "she is listening to me
|
||||
// right now" is legible without reading the word next to it.
|
||||
Rectangle {
|
||||
width: 7
|
||||
height: 7
|
||||
radius: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: luna.stateColor
|
||||
|
||||
SequentialAnimation on opacity {
|
||||
running: luna.daemonState === "listening"
|
||||
loops: Animation.Infinite
|
||||
alwaysRunToEnd: true
|
||||
NumberAnimation { to: 0.25; duration: 700; easing.type: Easing.InOutQuad }
|
||||
NumberAnimation { to: 1.0; duration: 700; easing.type: Easing.InOutQuad }
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: luna.stateLabel
|
||||
color: luna.stateColor
|
||||
font.family: Theme.displayFont
|
||||
font.pixelSize: 13
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: body
|
||||
spacing: 6
|
||||
|
||||
// Level meter: live whenever voice mode is on, not only once a
|
||||
// trigger has fired, so a mic too quiet to reach the threshold still
|
||||
// shows movement instead of looking broken.
|
||||
Row {
|
||||
id: meter
|
||||
width: 260
|
||||
height: 18
|
||||
spacing: 2
|
||||
|
||||
readonly property int count: 28
|
||||
readonly property bool sweeping: luna.daemonState === "thinking"
|
||||
property real phase: 0
|
||||
|
||||
NumberAnimation on phase {
|
||||
running: meter.sweeping
|
||||
loops: Animation.Infinite
|
||||
from: 0
|
||||
to: 1
|
||||
duration: 1200
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: meter.count
|
||||
|
||||
Rectangle {
|
||||
required property int index
|
||||
|
||||
width: (meter.width - (meter.count - 1) * meter.spacing) / meter.count
|
||||
height: {
|
||||
if (meter.sweeping) {
|
||||
const pos = index / (meter.count - 1);
|
||||
return 2 + 14 * Math.max(0, 1 - Math.abs(pos - meter.phase) * 6);
|
||||
}
|
||||
if (!luna.active && luna.daemonState !== "speaking")
|
||||
return 2;
|
||||
// sqrt opens up the quiet end, which on this mic is
|
||||
// where all of the speech actually sits.
|
||||
const level = Math.min(1, Math.sqrt(luna.rms) * 6.0);
|
||||
const centre = 1 - Math.abs(index / (meter.count - 1) - 0.5) * 1.6;
|
||||
return 2 + 16 * level * Math.max(0.15, centre);
|
||||
}
|
||||
anchors.bottom: parent.bottom
|
||||
color: luna.stateColor
|
||||
opacity: meter.sweeping ? 0.9 : 0.5 + 0.5 * (height / 18)
|
||||
|
||||
Behavior on height {
|
||||
enabled: !meter.sweeping
|
||||
NumberAnimation { duration: 70; easing.type: Easing.OutQuad }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
width: 260
|
||||
visible: luna.userText !== ""
|
||||
text: `> ${luna.userText}`
|
||||
color: Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 10
|
||||
wrapMode: Text.WordWrap
|
||||
maximumLineCount: 2
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
Text {
|
||||
width: 260
|
||||
visible: luna.lunaText !== ""
|
||||
text: luna.lunaText
|
||||
color: Theme.text
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 11
|
||||
wrapMode: Text.WordWrap
|
||||
maximumLineCount: 4
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
Text {
|
||||
visible: luna.userText === "" && luna.lunaText === ""
|
||||
text: luna.connected ? "SUPER+V TO TALK" : "DAEMON NOT RUNNING"
|
||||
color: Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 9
|
||||
font.letterSpacing: 1.4
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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