Prerequisites
Create a Fish Audio account
Create a Fish Audio account
Sign up for a free Fish Audio account to get started with our API.
- Sign up on fish.audio
- Fill in your details to create an account, complete steps to verify your account.
- Log in to your account and open Get Started
Get your API key
Get your API key
Once you have an account, you’ll need an API key to authenticate your requests.
- Log in and open Get Started
- Click “Get your API key”: the key is created in one click and shown only once
- Copy your key and store it securely
fish-audio-sdk 1.6.0 or later: pip install -U fish-audio-sdk.
Recipe
tts.convert_with_timestamps() returns the audio together with timed segments, so the captions match the generated speech exactly. Segments are word-level (one character in Chinese and Japanese) and carry no punctuation, so the recipe groups consecutive segments into caption-sized cues before it writes them. Segment start / end are in seconds; SRT wants HH:MM:SS,mmm (comma), WebVTT wants HH:MM:SS.mmm (dot).
The recipe starts a new cue after a pause longer than 0.6 seconds, or when the cue would grow past 42 characters or 6 seconds. It joins words with a space, except between Chinese or Japanese characters. A segment can have start equal to end, so a cue with no duration gets a short one that ends no later than the next cue starts. If the next cue starts at the same millisecond, that cue is moved 1 ms later, so every cue ends after it starts and cues never overlap.
Python
narration.mp3 with narration.vtt as its text track, or load narration.srt next to it in a video editor. Tune MAX_CHARS, MAX_MS, and MAX_GAP_MS for your player and audience.
Captions show the words as they were spoken after text normalization, without punctuation: $42.50 becomes the two words 42 and 50, not the text you sent. To show your original wording, keep your own sentences and use the segment times only to decide when each sentence starts and ends.
Related
- Text to Speech: word timestamps
- Transcribe audio to SRT/VTT captions, the same cues from a recording instead of generated speech
- Text to Speech Stream with Timestamps API

