Skip to content

Nomannazir/f5-tts-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎙️ F5-TTS FastAPI Wrapper

Made with FastAPI Powered by PyTorch Model: F5-TTS License: MIT Codubi Tech

A lightweight FastAPI-based REST API that exposes the open-source F5-TTS voice synthesis model.
Generate speech, stream audio, and clone voices with simple API calls.


🚀 Features

  • 🎧 Text-to-Speech (/tts, /tts-fast)
  • 🔊 Real-time audio streaming (/tts-stream, /tts-stream-chunked)
  • ⚙️ Configurable speed, steps, silence removal, and CFG
  • 🧩 Easy to integrate in any web or SaaS app

🛠️ Setup

1️⃣ Clone the official F5-TTS repo

git clone https://github.com/SWivid/F5-TTS.git
cd F5-TTS

2️⃣ Add this FastAPI script

Copy or download app.py from this repo into the root of your F5-TTS folder.

3️⃣ Install dependencies

pip install -r requirements.txt

4️⃣ Run the API

uvicorn app:app --host 0.0.0.0 --port 8000

Then open in browser:
👉 http://localhost:8000/docs


🧪 Example Usage (Python)

import requests

url = "http://localhost:8000/tts"
files = {"ref_audio": open("ref.wav", "rb")}
data = {"gen_text": "Hello world, this is F5-TTS in action!"}

res = requests.post(url, files=files, data=data)
open("output.wav", "wb").write(res.content)

⚡ Example Usage (TypeScript / Node.js)

import fs from "fs";
import FormData from "form-data";
import axios from "axios";

const runTTS = async () => {
  const formData = new FormData();
  formData.append("ref_audio", fs.createReadStream("ref.wav"));
  formData.append("gen_text", "Hello world, this is F5-TTS from Node.js!");
  
  const response = await axios.post("http://localhost:8000/tts", formData, {
    headers: formData.getHeaders(),
    responseType: "arraybuffer",
  });

  fs.writeFileSync("output.wav", response.data);
  console.log("✅ Audio saved as output.wav");
};

runTTS().catch(console.error);

💡 Endpoints

Method Endpoint Description
GET /health Model/device info
POST /tts High-quality text-to-speech
POST /tts-fast Fast inference (lower quality)
POST /tts-stream Real-time WAV streaming
POST /tts-stream-chunked Chunked MP3 streaming
GET / Root status
GET /mock-audio.mp3 Sample mock audio (for dev)

⚡ Notes

  • Uses pretrained model: SWivid/F5-TTS/F5TTS_v1_Base
  • Auto-detects GPU (CUDA) if available
  • Output files saved to /generated folder

🧑‍💻 Author

Noman NazirLinkedin
AI-Powered Software & SaaS Solutions


📜 License

MIT License — Feel free to use, modify, and contribute!

About

Open-source FastAPI wrapper for F5-TTS. A powerful Text-to-Speech API with real-time voice cloning and streaming support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages