FastAPI Server Implementation for Bilibili Index TTS
Python
25
21 commits
updated Apr 13, 2025
This repository provides a FastAPI implementation for serving the IndexTTS text-to-speech model through a RESTful API. It allows you to generate high-quality speech from text using a range of voice references.
git clone https://github.com/index-tts/index-tts.git
cd index-tts
Before installing the IndexTTS package, you need to install PyTorch with support for your specific GPU. This is crucial for optimal performance.
# For CUDA 12.6
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cu126
# For CUDA 12.4
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cu124
# For CUDA 11.8
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cu118
# For ROCm
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install torch==2.6.0 torchaudio
After installing PyTorch with the correct configuration, install the IndexTTS package:
pip install -e .
Download the required model files using one of the following methods:
# Using huggingface-cli
export HF_ENDPOINT="https://hf-mirror.com" # Optional, for faster downloads in some regions
huggingface-cli download IndexTeam/Index-TTS \
bigvgan_discriminator.pth bigvgan_generator.pth bpe.model dvae.pth gpt.pth unigram_12000.vocab \
--local-dir checkpoints
OR
# Using wget
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/bigvgan_discriminator.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/bigvgan_generator.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/bpe.model -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/dvae.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/gpt.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/unigram_12000.vocab -P checkpoints
Install the additional dependencies required for the FastAPI service:
pip install -r requirements.txt
Before using the API, you need to set up voice reference files:
Create a characters directory in the project root:
mkdir -p characters
Add WAV files containing voice samples to this directory. Each file should:
alex.wav, female1.wav)Run the FastAPI service using the provided run.py script:
python run.py
By default, the server will listen on all interfaces (0.0.0.0) on port 8000.
You can customize the server behavior with these command-line arguments:
python run.py --host 127.0.0.1 --port 9000 --log-level debug --reload
Available options:
--host: Host to bind to (default: 0.0.0.0)--port: Port to bind to (default: 8000)--reload: Enable auto-reload for development--log-level: Set logging level (default: info)--no-fp16: Disable FP16 precision (use for compatibility with older GPUs)--device: Specify device to use (cpu, cuda, cuda:0, mps)Endpoint: POST /v1/audio/speech
Headers:
Authorization: Bearer <your_token>Content-Type: application/jsonRequest Body:
{
"model": "IndexTTS",
"input": "Hello, this is a test message for IndexTTS.",
"voice": "alex",
"response_format": "mp3",
"sample_rate": 24000,
"stream": false,
"speed": 1.0,
"gain": 0.0
}
Parameters:
model: Always "IndexTTS"input: Text to synthesizevoice: Voice identifier (filename without extension in the characters directory)response_format: Output audio format (mp3, wav, or ogg)sample_rate: Output sample rate in Hzstream: Whether to stream the responsespeed: Speech speed factor (1.0 = normal)gain: Audio gain in dB (0.0 = normal)A sample client is provided in client_example.py:
python client_example.py \
--text "Hello, this is a test message for IndexTTS." \
--voice alex \
--output output.mp3 \
--format mp3 \
--sample-rate 24000
curl -X POST "http://localhost:8000/v1/audio/speech" \
-H "Authorization: Bearer test_token" \
-H "Content-Type: application/json" \
-d '{
"model": "IndexTTS",
"input": "Hello, this is a test message for IndexTTS.",
"voice": "alex",
"response_format": "mp3",
"sample_rate": 24000,
"stream": false,
"speed": 1.0,
"gain": 0.0
}' \
--output output.mp3
--no-fp16 flag.python -c "import torch; print(torch.version.cuda)".Authorization header with a valid token.This FastAPI implementation is provided according to the license terms of the original IndexTTS project. Please refer to the license files in the original repository for more information.
This FastAPI service is built on top of the IndexTTS text-to-speech system developed by the bilibili Index Team. The original repository and research paper can be found at:
Python
94.8%
Cuda
3.0%
C
2.0%
FastAPI Server Implementation for Bilibili Index TTS
Python
25
21 commits
updated Apr 13, 2025
This repository provides a FastAPI implementation for serving the IndexTTS text-to-speech model through a RESTful API. It allows you to generate high-quality speech from text using a range of voice references.
git clone https://github.com/index-tts/index-tts.git
cd index-tts
Before installing the IndexTTS package, you need to install PyTorch with support for your specific GPU. This is crucial for optimal performance.
# For CUDA 12.6
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cu126
# For CUDA 12.4
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cu124
# For CUDA 11.8
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cu118
# For ROCm
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4
pip install torch==2.6.0 torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install torch==2.6.0 torchaudio
After installing PyTorch with the correct configuration, install the IndexTTS package:
pip install -e .
Download the required model files using one of the following methods:
# Using huggingface-cli
export HF_ENDPOINT="https://hf-mirror.com" # Optional, for faster downloads in some regions
huggingface-cli download IndexTeam/Index-TTS \
bigvgan_discriminator.pth bigvgan_generator.pth bpe.model dvae.pth gpt.pth unigram_12000.vocab \
--local-dir checkpoints
OR
# Using wget
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/bigvgan_discriminator.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/bigvgan_generator.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/bpe.model -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/dvae.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/gpt.pth -P checkpoints
wget https://huggingface.co/IndexTeam/Index-TTS/resolve/main/unigram_12000.vocab -P checkpoints
Install the additional dependencies required for the FastAPI service:
pip install -r requirements.txt
Before using the API, you need to set up voice reference files:
Create a characters directory in the project root:
mkdir -p characters
Add WAV files containing voice samples to this directory. Each file should:
alex.wav, female1.wav)Run the FastAPI service using the provided run.py script:
python run.py
By default, the server will listen on all interfaces (0.0.0.0) on port 8000.
You can customize the server behavior with these command-line arguments:
python run.py --host 127.0.0.1 --port 9000 --log-level debug --reload
Available options:
--host: Host to bind to (default: 0.0.0.0)--port: Port to bind to (default: 8000)--reload: Enable auto-reload for development--log-level: Set logging level (default: info)--no-fp16: Disable FP16 precision (use for compatibility with older GPUs)--device: Specify device to use (cpu, cuda, cuda:0, mps)Endpoint: POST /v1/audio/speech
Headers:
Authorization: Bearer <your_token>Content-Type: application/jsonRequest Body:
{
"model": "IndexTTS",
"input": "Hello, this is a test message for IndexTTS.",
"voice": "alex",
"response_format": "mp3",
"sample_rate": 24000,
"stream": false,
"speed": 1.0,
"gain": 0.0
}
Parameters:
model: Always "IndexTTS"input: Text to synthesizevoice: Voice identifier (filename without extension in the characters directory)response_format: Output audio format (mp3, wav, or ogg)sample_rate: Output sample rate in Hzstream: Whether to stream the responsespeed: Speech speed factor (1.0 = normal)gain: Audio gain in dB (0.0 = normal)A sample client is provided in client_example.py:
python client_example.py \
--text "Hello, this is a test message for IndexTTS." \
--voice alex \
--output output.mp3 \
--format mp3 \
--sample-rate 24000
curl -X POST "http://localhost:8000/v1/audio/speech" \
-H "Authorization: Bearer test_token" \
-H "Content-Type: application/json" \
-d '{
"model": "IndexTTS",
"input": "Hello, this is a test message for IndexTTS.",
"voice": "alex",
"response_format": "mp3",
"sample_rate": 24000,
"stream": false,
"speed": 1.0,
"gain": 0.0
}' \
--output output.mp3
--no-fp16 flag.python -c "import torch; print(torch.version.cuda)".Authorization header with a valid token.This FastAPI implementation is provided according to the license terms of the original IndexTTS project. Please refer to the license files in the original repository for more information.
This FastAPI service is built on top of the IndexTTS text-to-speech system developed by the bilibili Index Team. The original repository and research paper can be found at:
Python
94.8%
Cuda
3.0%
C
2.0%