Skip to main content

Prerequisites

Sign up for a free Fish Audio account to get started with our API.
  1. Sign up on fish.audio
  2. Fill in your details to create an account, complete steps to verify your account.
  3. Log in to your account and open Get Started
Once you have an account, you’ll need an API key to authenticate your requests.
  1. Log in and open Get Started
  2. Click “Get your API key”: the key is created in one click and shown only once
  3. Copy your key and store it securely
Keep your API key secret! Never commit it to version control or share it publicly.
This recipe needs 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
Play 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.
Long text is generated in several chunks. The SDK already places every segment on the timeline of the complete audio, so you don’t need to add chunk_audio_offset_sec yourself as the API reference describes for raw requests.