Skip to content

Instantly share code, notes, and snippets.

@didmar
Created February 21, 2026 17:27
Show Gist options
  • Select an option

  • Save didmar/4161d708d3a5e4a0946448623d9773b1 to your computer and use it in GitHub Desktop.

Select an option

Save didmar/4161d708d3a5e4a0946448623d9773b1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Speech transcript post-processing script, to use in Handy.
#
# Using either `claude` or `llm` (comment/uncomment below)
#
# Supports both Wayland an X11:
# - Wayland: install wl-clipboard
# - X11: install xclip
#
import sys
import os
import subprocess
import shutil
import logging
from datetime import datetime
if len(sys.argv) <= 1:
log.error('no argument provided, exiting')
sys.exit(1)
text = sys.argv[1]
prompt = 'Cleanup this speech-to-text transcript, just output the cleaned version and nothing else.'
try:
# Option A: Using Claude Code
# claude_path = shutil.which('claude') or os.path.expanduser('~/.local/bin/claude') # absolute path required, won't use PATH through Handy!
# result = subprocess.run(
# [claude_path,
# '--model', 'haiku', # fast and cheap, sufficient for text cleanup
# '--tools', '', # disable all built-in tools (no filesystem/shell access)
# '--strict-mcp-config', # ignore all MCP servers (no MCP tools either)
# '--no-session-persistence', # don't write session to disk
# '--no-chrome', # disable Claude in Chrome integration
# '--effort', 'low', # does not require efforts
# '--disable-slash-commands', # won't use skills
# '--system-prompt', prompt,
# '-p', text], # raw transcript as the sole user input
# capture_output=True, text=True
# )
# Option B: Using Simon Willison's llm CLI. Faster startup time than Claude Code.
llm_path = shutil.which('llm') or os.path.expanduser('~/.local/bin/llm') # absolute path required, won't use PATH through Handy!
result = subprocess.run(
[llm_path, '-m', 'gemini-flash-lite-latest', prompt + '\n\n' + text],
capture_output=True, text=True,
)
except:
result = None
cleaned = (result.stdout.strip() if result else None) or text # fall back to raw text on failure
if shutil.which('wl-copy'):
subprocess.run(['wl-copy'], input=cleaned, text=True,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
elif shutil.which('xclip'):
subprocess.run(['xclip', '-selection', 'clipboard'], input=cleaned, text=True,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
sys.exit('no clipboard tool found (install wl-clipboard or xclip)')
# Optional desktop notification
# subprocess.run(['notify-send', '--', f"Transcribed: {text}"], capture_output=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment