This guide will walk you through generating your first text-to-speech audio with Fish Audio. By the end, you’ll have converted text into natural-sounding speech using our API.
Store your API key as an environment variable (recommended approach):
export FISH_API_KEY="replace_me"
2
Make the TTS request
Run this cURL command to generate your first speech:
curl -X POST https://api.fish.audio/v1/tts \ -H "Authorization: Bearer $FISH_API_KEY" \ -H "Content-Type: application/json" \ -H "model: s2-pro" \ -d '{ "text": "Hello! Welcome to Fish Audio. This is my first AI-generated voice.", "format": "mp3" }' \ --output welcome.mp3
3
Play your audio
The audio has been saved as welcome.mp3. You can play it by:
Double-clicking the file or opening it in any media player
Or using the command line:
# On macOSafplay welcome.mp3# On Linuxmpg123 welcome.mp3# On Windowsstart welcome.mp3
1
Install the SDK
pip install fish-audio-sdk
2
Generate speech
Create a Python script:
from fishaudio import FishAudiofrom fishaudio.utils import save# Initialize with your API keyclient = FishAudio(api_key="your_api_key_here")# Generate speechaudio = client.tts.convert(text="Hello! Welcome to Fish Audio.")save(audio, "welcome.mp3")print("✓ Audio saved to welcome.mp3")
3
Run the script
python generate_speech.py
4
Play your audio
The audio has been saved as welcome.mp3. You can play it by:
Double-clicking the file or opening it in any media player
Or using the command line:
# On macOSafplay welcome.mp3# On Linuxmpg123 welcome.mp3# On Windowsstart welcome.mp3
1
Install the SDK
npm install fish-audio
2
Generate speech
Create a JavaScript script:
import { FishAudioClient } from "fish-audio";import { writeFile } from "fs/promises";const fishAudio = new FishAudioClient({ apiKey: process.env.FISH_API_KEY });const audio = await fishAudio.textToSpeech.convert({ text: "Hello, world!",});const buffer = Buffer.from(await new Response(audio).arrayBuffer());await writeFile("welcome.mp3", buffer);console.log("✓ Audio saved to welcome.mp3");
3
Run the script
node generate_speech.mjs
4
Play your audio
The audio has been saved as welcome.mp3. You can play it by:
Double-clicking the file or opening it in any media player
Or using the command line:
# On macOSafplay welcome.mp3# On Linuxmpg123 welcome.mp3# On Windowsstart welcome.mp3
The examples above use the default voice. To use a different voice, add the reference_id parameter with a model ID from fish.audio. You can find the model ID in the URL or use the copy button when viewing any voice.Choose a voice to try:
curl -X POST https://api.fish.audio/v1/tts \ -H "Authorization: Bearer $FISH_API_KEY" \ -H "Content-Type: application/json" \ -H "model: s2" \ -d '{ "text": "This is a custom voice from Fish Audio! You can explore hundreds of different voices on the platform, or even create your own.", "reference_id": "'"$REFERENCE_ID"'", "format": "mp3" }' \ --output custom_voice.mp3
import osfrom fishaudio import FishAudiofrom fishaudio.utils import saveclient = FishAudio(api_key="your_api_key_here")# Generate speech with custom voiceaudio = client.tts.convert( text="This is a custom voice from Fish Audio! You can explore hundreds of different voices on the platform, or even create your own.", reference_id=os.environ.get("REFERENCE_ID"))save(audio, "custom_voice.mp3")
import { FishAudioClient } from "fish-audio";import { writeFile } from "fs/promises";const fishAudio = new FishAudioClient({ apiKey: process.env.FISH_API_KEY });const audio = await fishAudio.textToSpeech.convert({ text: "This is a custom voice from Fish Audio! You can explore hundreds of different voices on the platform, or even create your own.", reference_id: process.env.REFERENCE_ID,});const buffer = Buffer.from(await new Response(audio).arrayBuffer());await writeFile("custom_voice.mp3", buffer);console.log("✓ Audio saved to custom_voice.mp3");