talk: 0.1.0 -> 0.1.1 (now built from code.m3ta.dev/m3tam3re/talk)
talk moved to its own repository and is now a Go binary with a background daemon instead of a bash script around curl/mpv. crunch: call `talk say --wait` so the announcement finishes before the systemd transient unit exits and takes an autostarted daemon with it; update documented env vars. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ed2b9fb089
commit
72695e2ef0
3 files changed
+56
-229
No files matched your search
@@ -13,7 +13,7 @@
|
||||
# crunch — Voice-notified reminders & AI crunch jobs
|
||||
# via systemd transient timers.
|
||||
#
|
||||
# Requires: talk (ElevenLabs TTS) in PATH, ELEVENLABS_API_KEY env.
|
||||
# Requires: talk in PATH (TTS keys via TALK_ELEVENLABS_KEY etc.).
|
||||
# Optional: pi, opencode for AI crunch mode.
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -51,8 +51,7 @@
|
||||
crunch cancel mll-rausbringen-12345
|
||||
|
||||
Environment:
|
||||
VOICE_NOTIFY=0 Silence voice output (passed to talk)
|
||||
ELEVENLABS_API_KEY Required by talk
|
||||
TALK_ELEVENLABS_KEY ElevenLabs key for talk (optional, falls back to free voices)
|
||||
TALK Override path to talk binary
|
||||
EOF
|
||||
}
|
||||
@@ -130,16 +129,16 @@
|
||||
case "''${1:-}" in
|
||||
_say)
|
||||
shift
|
||||
exec "$TALK" "$*"
|
||||
exec "$TALK" say --wait "$*"
|
||||
;;
|
||||
_ai)
|
||||
engine="$2"; shift 2
|
||||
case "$engine" in
|
||||
pi|pi-agent)
|
||||
pi -p "$*" | "$TALK"
|
||||
pi -p "$*" | "$TALK" say --wait
|
||||
;;
|
||||
opencode|oc)
|
||||
opencode run "$*" -q | "$TALK"
|
||||
opencode run "$*" -q | "$TALK" say --wait
|
||||
;;
|
||||
*)
|
||||
echo "Unknown engine: $engine (use: pi, opencode)" >&2
|
||||
@@ -153,7 +152,7 @@
|
||||
rc=0
|
||||
output=$(bash "$script_path" "$@" 2>&1) || rc=$?
|
||||
if [ -n "''${output:-}" ]; then
|
||||
printf '%s' "$output" | "$TALK"
|
||||
printf '%s' "$output" | "$TALK" say --wait
|
||||
fi
|
||||
exit "$rc"
|
||||
;;
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
# talk
|
||||
|
||||
ElevenLabs TTS voice notifications with a dismissable desktop popup. Generates speech from text via the ElevenLabs API, plays it through `mpv`, and shows a notification with a **⛔ Abbrechen** button to stop playback.
|
||||
|
||||
## Usage
|
||||
|
||||
### Argument
|
||||
|
||||
```bash
|
||||
talk "Build abgeschlossen. Alle Tests erfolgreich."
|
||||
```
|
||||
|
||||
### Stdin (pipe)
|
||||
|
||||
```bash
|
||||
echo "Deployment fertig" | talk
|
||||
nixos-rebuild build 2>&1 | tail -3 | talk
|
||||
pi -p "Fasse zusammen" | talk
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Required | Default | Description |
|
||||
|---|---|---|---|
|
||||
| `ELEVENLABS_API_KEY` | ⚠️ | — | Fallback if agenix file is absent |
|
||||
| `ELEVENLABS_KEY_FILE` | ❌ | `/run/agenix/elevenlabs-key` | Path to agenix secrets file (preferred) |
|
||||
| `ELEVENLABS_VOICE_ID` | ❌ | `KXxZd16DiBqt82nbarJx` | Voice ID to use |
|
||||
| `VOICE_NOTIFY` | ❌ | `1` | Set to `0` to silence all output |
|
||||
|
||||
The API key is read from the agenix file at `/run/agenix/elevenlabs-key` by default. The file should contain just the key (trailing newline is stripped automatically via `read -r`). If the file doesn't exist, `talk` falls back to the `ELEVENLABS_API_KEY` environment variable.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. Sends text to ElevenLabs `text-to-speech` API → receives MP3
|
||||
2. Plays audio via `mpv` (background)
|
||||
3. Shows `notify-send` popup with **⛔ Abbrechen** action (background)
|
||||
4. Polls every 0.2s:
|
||||
- If mpv finished → kill notification, exit
|
||||
- If user clicked **Abbrechen** → kill mpv, exit
|
||||
5. Cleans up temp files on exit
|
||||
|
||||
## Cancel Button
|
||||
|
||||
The notification popup has a **⛔ Abbrechen** action button. Clicking it kills `mpv` playback immediately. The popup disappears when audio finishes or is cancelled.
|
||||
|
||||
The poll loop uses `[ -s ]` (non-empty file check) on the action output file. This ensures the loop only reacts when `notify-send` actually writes the action key — not when the empty file is created by the shell redirect.
|
||||
|
||||
## Integration Patterns
|
||||
|
||||
### After long-running tasks
|
||||
|
||||
```bash
|
||||
nixos-rebuild switch 2>&1 | tail -5 | talk
|
||||
```
|
||||
|
||||
### With AI agents (print mode)
|
||||
|
||||
```bash
|
||||
# Pi
|
||||
pi -p "Review diesen Code" | talk
|
||||
|
||||
# OpenCode
|
||||
opencode run "Erkläre diese Funktion" -q | talk
|
||||
```
|
||||
|
||||
### With crunch (scheduled jobs)
|
||||
|
||||
```bash
|
||||
crunch ai pi daily "08:00" "Fasse Basecamp Todos zusammen"
|
||||
# → talk speaks the summary at 08:00
|
||||
```
|
||||
|
||||
## NixOS Installation
|
||||
|
||||
```nix
|
||||
# home-manager
|
||||
home.packages = [ pkgs.m3ta.talk ];
|
||||
```
|
||||
|
||||
The API key is read from `/run/agenix/elevenlabs-key` at runtime — set up the secret in your agenix configuration:
|
||||
|
||||
```nix
|
||||
# secrets.nix
|
||||
age.secrets."elevenlabs-key" = {
|
||||
file = ./secrets/elevenlabs-key.age;
|
||||
# Optionally set owner/group if needed
|
||||
};
|
||||
```
|
||||
|
||||
No need to export `ELEVENLABS_API_KEY` in shell environment anymore.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `curl` — API calls
|
||||
- `python3` — JSON payload construction
|
||||
- `mpv` — audio playback
|
||||
- `libnotify` — desktop notification
|
||||
- `busybox` — coreutils (rm, cat, grep, sleep, kill, stat)
|
||||
+50
-124
@@ -1,137 +1,63 @@
|
||||
{
|
||||
lib,
|
||||
stdenv,
|
||||
writeShellScriptBin,
|
||||
fetchurl,
|
||||
curl,
|
||||
python3,
|
||||
mpv,
|
||||
buildGoModule,
|
||||
fetchFromGitea,
|
||||
makeWrapper,
|
||||
alsa-lib,
|
||||
espeak-ng,
|
||||
libnotify,
|
||||
busybox,
|
||||
}: let
|
||||
icon = fetchurl {
|
||||
url = "https://s3.m3tam3re.com/public/chiron.jpeg";
|
||||
hash = "sha256-LIIR3aqJ5ePsZuvVQxJ70c6yd+L85fLE5uY/fLE5Ypo=";
|
||||
};
|
||||
script = writeShellScriptBin "talk" ''
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ── Toggle: VOICE_NOTIFY=0 deaktiviert alles ───────────────────
|
||||
if [ "''${VOICE_NOTIFY:-1}" = "0" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── Config ──────────────────────────────────────────────────────
|
||||
# API key: read from agenix file (preferred), fall back to env var.
|
||||
# `read -r` strips the trailing newline that agenix files contain.
|
||||
ELEVENLABS_KEY_FILE="''${ELEVENLABS_KEY_FILE:-/run/agenix/elevenlabs-key}"
|
||||
if [ -f "$ELEVENLABS_KEY_FILE" ]; then
|
||||
read -r API_KEY < "$ELEVENLABS_KEY_FILE"
|
||||
elif [ -n "''${ELEVENLABS_API_KEY:-}" ]; then
|
||||
API_KEY="''${ELEVENLABS_API_KEY}"
|
||||
else
|
||||
echo "Error: No ElevenLabs API key found." >&2
|
||||
echo "Create $ELEVENLABS_KEY_FILE (agenix) or set ELEVENLABS_API_KEY env var." >&2
|
||||
exit 1
|
||||
fi
|
||||
VOICE_ID="''${ELEVENLABS_VOICE_ID:-KXxZd16DiBqt82nbarJx}"
|
||||
# Argument hat Vorrang, sonst stdin lesen wenn Pipe
|
||||
if [ $# -ge 1 ]; then
|
||||
TEXT="$1"
|
||||
elif [ ! -t 0 ]; then
|
||||
TEXT=$(cat)
|
||||
else
|
||||
echo "Usage: talk \"Text\" oder echo Text | talk" >&2
|
||||
exit 1
|
||||
fi
|
||||
AUDIO_FILE="/tmp/voice-notify-$$.mp3"
|
||||
ACTION_FILE="/tmp/voice-action-$$"
|
||||
|
||||
CURL="${lib.getExe curl}"
|
||||
PYTHON="${lib.getExe python3}"
|
||||
MPV="${lib.getExe mpv}"
|
||||
NOTIFY="${lib.getExe libnotify}"
|
||||
RM="${busybox}/bin/rm"
|
||||
CAT="${busybox}/bin/cat"
|
||||
GREP="${busybox}/bin/grep"
|
||||
SLEEP="${busybox}/bin/sleep"
|
||||
KILL="${busybox}/bin/kill"
|
||||
STAT="${busybox}/bin/stat"
|
||||
|
||||
trap '$RM -f "$AUDIO_FILE" "$ACTION_FILE"' EXIT
|
||||
|
||||
# ── TTS generieren ──────────────────────────────────────────────
|
||||
PAYLOAD=$("$PYTHON" -c '
|
||||
import json, sys
|
||||
print(json.dumps({
|
||||
"text": sys.argv[1],
|
||||
"model_id": "eleven_multilingual_v2",
|
||||
"voice_settings": {"stability": 0.5, "similarity_boost": 0.75}
|
||||
}))
|
||||
' "$TEXT")
|
||||
|
||||
HTTP_CODE=$("$CURL" -s -o "$AUDIO_FILE" -w "%{http_code}" \
|
||||
-X POST "https://api.elevenlabs.io/v1/text-to-speech/''${VOICE_ID}" \
|
||||
-H "xi-api-key: ''${API_KEY}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$PAYLOAD") || HTTP_CODE="000"
|
||||
|
||||
if [ "$HTTP_CODE" != "200" ]; then
|
||||
ERR=$($CAT "$AUDIO_FILE" 2>/dev/null | head -c 300)
|
||||
$RM -f "$AUDIO_FILE"
|
||||
"$NOTIFY" -u critical "❌ Voice Fehler" "HTTP ''${HTTP_CODE}\n''${ERR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ── Gleichzeitig: Audio + Notification ──────────────────────────
|
||||
"$MPV" --no-video --no-terminal --really-quiet "$AUDIO_FILE" &
|
||||
MPV_PID=$!
|
||||
|
||||
(
|
||||
exec "$NOTIFY" \
|
||||
--action=cancel="⛔ Abbrechen" \
|
||||
--urgency=normal \
|
||||
--icon=${icon} \
|
||||
"🔊 KI Antwort" \
|
||||
"$TEXT" > "$ACTION_FILE" 2>/dev/null
|
||||
) &
|
||||
NOTIFY_PID=$!
|
||||
|
||||
# ── Poll-Loop ───────────────────────────────────────────────────
|
||||
while true; do
|
||||
if ! $KILL -0 "$MPV_PID" 2>/dev/null; then
|
||||
$KILL "$NOTIFY_PID" 2>/dev/null || true
|
||||
break
|
||||
fi
|
||||
if [ -s "$ACTION_FILE" ]; then
|
||||
if $GREP -q "cancel" "$ACTION_FILE" 2>/dev/null; then
|
||||
$KILL "$MPV_PID" 2>/dev/null || true
|
||||
fi
|
||||
break
|
||||
fi
|
||||
$SLEEP 0.2
|
||||
done
|
||||
|
||||
wait "$MPV_PID" 2>/dev/null || true
|
||||
'';
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
nix-update-script,
|
||||
versionCheckHook,
|
||||
}:
|
||||
buildGoModule (finalAttrs: {
|
||||
pname = "talk";
|
||||
version = "0.1.0";
|
||||
version = "0.1.1";
|
||||
|
||||
dontUnpack = true;
|
||||
src = fetchFromGitea {
|
||||
domain = "code.m3ta.dev";
|
||||
owner = "m3tam3re";
|
||||
repo = "talk";
|
||||
tag = "v${finalAttrs.version}";
|
||||
hash = "sha256-1vmseIvcrEO5rg65zcsD96+tHvRdT0fJ3Bt66rNfHlQ=";
|
||||
};
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p "$out/bin"
|
||||
ln -s ${script}/bin/talk "$out/bin/talk"
|
||||
vendorHash = "sha256-8B1ubNy4sap3XV83lX93NvpH3z4BNloWgkM7OB4hglo=";
|
||||
|
||||
subPackages = ["cmd/talk"];
|
||||
|
||||
env.CGO_ENABLED = 0;
|
||||
|
||||
ldflags = [
|
||||
"-s"
|
||||
"-w"
|
||||
"-X"
|
||||
"main.version=${finalAttrs.version}"
|
||||
];
|
||||
|
||||
# The process-boundary tests start daemons and bind ports; not in the sandbox.
|
||||
doCheck = false;
|
||||
|
||||
# oto talks to PulseAudio/PipeWire directly and falls back to ALSA via
|
||||
# dlopen; espeak-ng is the OS voice, libnotify the toast.
|
||||
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [makeWrapper];
|
||||
postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||
wrapProgram $out/bin/talk \
|
||||
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [alsa-lib]} \
|
||||
--prefix PATH : ${lib.makeBinPath [espeak-ng libnotify]}
|
||||
'';
|
||||
|
||||
nativeInstallCheckInputs = [versionCheckHook];
|
||||
versionCheckProgramArg = "version";
|
||||
doInstallCheck = true;
|
||||
|
||||
passthru.updateScript = nix-update-script {};
|
||||
|
||||
meta = with lib; {
|
||||
description = "ElevenLabs TTS voice notifications with dismissable popup";
|
||||
homepage = "https://code.m3ta.dev/m3tam3re/nixpkgs";
|
||||
description = "Voice notifications for scripts and AI agents";
|
||||
homepage = "https://code.m3ta.dev/m3tam3re/talk";
|
||||
license = licenses.mit;
|
||||
platforms = platforms.linux;
|
||||
mainProgram = "talk";
|
||||
platforms = platforms.unix;
|
||||
};
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user