Skip to content

Instantly share code, notes, and snippets.

@hasenbalg
Created January 26, 2026 07:18
Show Gist options
  • Select an option

  • Save hasenbalg/1e9e86311d868fade1b48be4f40bb054 to your computer and use it in GitHub Desktop.

Select an option

Save hasenbalg/1e9e86311d868fade1b48be4f40bb054 to your computer and use it in GitHub Desktop.
tts wayland
#!/usr/bin/env bash
# install gtts
PIDFILE="/tmp/tts_reader.pid"
TMPFILE="/tmp/tts_audio.mp3"
# Stop if already running
if [ -f "$PIDFILE" ]; then
kill "$(cat "$PIDFILE")" 2>/dev/null
rm "$PIDFILE"
exit 0
fi
# Read selected text
TEXT="$(wl-paste --primary)"
[ -z "$TEXT" ] && TEXT="$(wl-paste)"
[ -z "$TEXT" ] && exit 0
# Generate MP3
gtts-cli "$TEXT" --output "$TMPFILE"
# Play it
mpv --no-terminal "$TMPFILE" &
PID=$!
echo "$PID" > "$PIDFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment