A web app that converts .txt files to speech. Upload a text file, get an MP3 back.
Browser ──POST /convert (multipart)──► Go HTTP server ──► OpenAI TTS API
◄──── MP3 download ─────────── ◄──── audio/mpeg
main.go— single-file Go HTTP server. Two routes:GET /— servesstatic/index.htmlPOST /convert— accepts a.txtfile (max 15 KB), splits the text into chunks of up to 4096 characters, calls the OpenAI TTS endpoint once per chunk, and returns the concatenated MP3 as a file download.
static/index.html— self-contained frontend (no build step). Handles drag-and-drop or click-to-upload, animates a fake progress bar while the API call runs, then presents a download link.
The server uses only the Go standard library (net/http, encoding/json, bytes). No external Go dependencies.
| Component | Detail |
|---|---|
| Language | Go 1.26 |
| TTS engine | OpenAI TTS — model tts-1, voice alloy |
| Output format | MP3 (audio/mpeg) |
| Input limit | 15 KB file size cap; text is split into 4096-character chunks and each is sent to the TTS API separately |
- Go 1.20+
- An OpenAI API key with access to the TTS endpoint
# Set your OpenAI API key
export OPENAI_API_KEY=sk-...
# Build and run
go build -o text2voice .
./text2voiceOr without building:
OPENAI_API_KEY=sk-... go run .The server listens on http://localhost:8080.
