text-to-speech
Turns text into an audio file via OpenAI's speech API. The key lives in the
macOS Keychain (service openai-api-key, account openai-tts) — the script
reads it automatically, so nothing is hardcoded.
How to run it
python3 ~/.claude/skills/text-to-speech/scripts/tts.py "TEXT HERE"
The script prints the saved file path on stdout (one line). After it returns:
- Surface the file to the user with
SendUserFile so they can grab it.
- Offer to play it, or pass
--play to play it immediately via afplay.
Input options (pick one)
Common flags
| Flag |
Default |
Notes |
-v, --voice |
alloy |
alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse |
-m, --model |
gpt-4o-mini-tts |
also tts-1 (fast) / tts-1-hd (higher quality) |
--format |
mp3 |
mp3, opus, aac, flac, wav, pcm |
-i, --instructions |
— |
tone/style steer, e.g. -i "warm, slow, like a bedtime story" (gpt-4o-mini-tts only) |
--speed |
1.0 |
0.25–4.0; best on tts-1 / tts-1-hd |
-o, --out |
~/Desktop/tts-<timestamp>.mp3 |
output path |
--play |
off |
play immediately after saving |
alloy is the plain, neutral "generic ChatGPT" voice — the default. Only change
it if the user asks for a different tone.
Notes
- Standard library only — no pip install needed.
- Key precedence:
OPENAI_API_KEY env var, then Keychain. Rotate the stored key with:
security add-generic-password -a openai-tts -s openai-api-key -w 'sk-...' -U
- Errors (bad key, unknown voice/model) are printed as
ERROR <code>: <detail>.
1---2name: text-to-speech3description: Convert a blob of text into spoken audio using OpenAI's text-to-speech (a generic ChatGPT-style voice) and hand the audio file back. Use when the user gives text and asks to "read this aloud", "make audio of this", "text to speech", "TTS this", "narrate this", "turn this into an mp3/voiceover", or invokes /text-to-speech. Produces an audio file (mp3 by default) saved to the Desktop.4---56# text-to-speech78Turns text into an audio file via OpenAI's speech API. The key lives in the9macOS Keychain (service `openai-api-key`, account `openai-tts`) — the script10reads it automatically, so nothing is hardcoded.1112## How to run it1314```bash15python3 ~/.claude/skills/text-to-speech/scripts/tts.py "TEXT HERE"16```1718The script prints the saved file path on stdout (one line). After it returns:191. Surface the file to the user with `SendUserFile` so they can grab it.202. Offer to play it, or pass `--play` to play it immediately via `afplay`.2122### Input options (pick one)23- Inline: `tts.py "Hello world"`24- From a file: `tts.py -f /path/to/notes.txt`25- From stdin (best for large blobs — avoids shell-quoting issues):26 ```bash27 cat notes.txt | python3 ~/.claude/skills/text-to-speech/scripts/tts.py --play28 ```29 When the text is long, has quotes/newlines, or comes from another file, prefer30 writing it to a temp file and using `-f`, or piping via stdin.3132### Common flags33| Flag | Default | Notes |34|---|---|---|35| `-v, --voice` | `alloy` | alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse |36| `-m, --model` | `gpt-4o-mini-tts` | also `tts-1` (fast) / `tts-1-hd` (higher quality) |37| `--format` | `mp3` | mp3, opus, aac, flac, wav, pcm |38| `-i, --instructions` | — | tone/style steer, e.g. `-i "warm, slow, like a bedtime story"` (gpt-4o-mini-tts only) |39| `--speed` | `1.0` | 0.25–4.0; best on tts-1 / tts-1-hd |40| `-o, --out` | `~/Desktop/tts-<timestamp>.mp3` | output path |41| `--play` | off | play immediately after saving |4243`alloy` is the plain, neutral "generic ChatGPT" voice — the default. Only change44it if the user asks for a different tone.4546## Notes47- Standard library only — no pip install needed.48- Key precedence: `OPENAI_API_KEY` env var, then Keychain. Rotate the stored key with:49 `security add-generic-password -a openai-tts -s openai-api-key -w 'sk-...' -U`50- Errors (bad key, unknown voice/model) are printed as `ERROR <code>: <detail>`.