How to Automate Text to Speech with the Fish Audio API
The Fish Audio API lets you generate speech from code, so you can batch a folder of scripts into audio files or wire voice into an app. It uses a simple REST call with an API key, and there is an official Python SDK that wraps the same endpoint.
Do this after you already have a cloned or selected voice in the web app. The API needs a voice reference ID, which the dashboard shows for every voice you own or bookmark.
How do you get a Fish Audio API key?
Sign in, open your account settings, and look for the API keys section. Generate a key and copy it once — treat it like a password. Store it in an environment variable rather than pasting it into scripts you might share.
How do you generate speech with Python?
Install the SDK, then make a call with three inputs: text, a voice reference ID, and an output format.
pip install fish-audio-sdk(or use plainrequestsagainst the REST endpoint).- Set
FISH_API_KEYin your environment. - Load your text, pass the voice ID, and request
mp3. - Write the returned bytes to a file per script.
A batch loop over 50 short scripts typically finishes in a couple of minutes on the hosted API.
What are the rate limits and costs?
The API meters usage by characters, same as the web app. A request can hold long text, but splitting into paragraph-sized chunks improves stability and lets you retry only the failed piece. Costs scale with characters generated; heavy volumes justify a paid plan over the free cap.
How do you handle long scripts and errors?
Chunk by paragraph, keep a list of finished files, and skip any chunk already on disk. Retry a failed chunk two or three times with a short delay before moving on. Log the voice ID and text length per file so you can trace a bad render later.
When should you use the API over the web app?
Use the API when the work is repetitive and volume is high — podcast pipelines, e-learning narration, localization. Stay in the web app for one-off clips, since tweaking a line there is faster than re-running a script. The API has no live preview, so expect to listen to output files during setup.
Key Takeaways
- The Fish Audio API generates speech from code using an API key and a voice reference ID.
- Install the Python SDK or call the REST endpoint directly.
- Meter usage is by characters, matching the web app.
- Chunk long text and retry only failed pieces.
- Best for batch narration and localization, not one-off tweaks.
Last updated October 2026. Tool details at Fish Audio.
