Views
No views yet

1git clone https://github.com/dangvansam/viet-tts.git
2cd viet-tts
3
4# (Optional) Install Python environment with conda, you could also use virtualenv
5conda create --name viettts python=3.10
6conda activate viettts
7
8# Install
9pip install -e . && pip cache purge1git clone https://github.com/dangvansam/viet-tts.git
2cd viet-tts
3
4# Build docker images
5docker compose build
6
7# Run with docker-compose - will create server at: http://localhost:8298
8docker compose up -d
9
10# Or run with docker run - will create server at: http://localhost:8298
11docker run -itd --gpu=alls -p 8298:8298 -v ./pretrained-models:/app/pretrained-models -n viet-tts-service viet-tts:latest viettts server --host 0.0.0.0 --port 8298| ID | Voice | Gender | Play Audio |
|---|---|---|---|
| 1 | nsnd-le-chuc | 👨 | |
| 2 | speechify_10 | 👩 | |
| 3 | atuan | 👨 | |
| 4 | speechify_11 | 👩 | |
| 5 | cdteam | 👨 | |
| 6 | speechify_12 | 👩 | |
| 7 | cross_lingual_prompt | 👩 | |
| 8 | speechify_2 | 👩 | |
| 9 | diep-chi | 👨 | |
| 10 | speechify_3 | 👩 | |
| 11 | doremon | 👨 | |
| 12 | speechify_4 | 👩 | |
| 13 | jack-sparrow | 👨 | |
| 14 | speechify_5 | 👩 | |
| 15 | nguyen-ngoc-ngan | 👩 | |
| 16 | speechify_6 | 👩 | |
| 17 | nu-nhe-nhang | 👩 | |
| 18 | speechify_7 | 👩 | |
| 19 | quynh | 👩 | |
| 20 | speechify_8 | 👩 | |
| 21 | speechify_9 | 👩 | |
| 22 | son-tung-mtp | 👨 | |
| 23 | zero_shot_prompt | 👩 | |
| 24 | speechify_1 | 👩 |
1# Usage
2viettts --help
3
4# Start API Server
5viettts server --host 0.0.0.0 --port 8298
6
7# List all built-in voices
8viettts show-voices
9
10# Synthesize speech from text with built-in voices
11viettts synthesis --text "Xin chào" --voice 0 --output test.wav
12
13# Clone voice from a local audio file
14viettts synthesis --text "Xin chào" --voice Download/voice.wav --output cloned.wav1# Set base_url and API key as environment variables
2export OPENAI_BASE_URL=http://localhost:8298
3export OPENAI_API_KEY=viet-tts # not use in current version1from pathlib import Path
2from openai import OpenAI
3
4client = OpenAI()
5
6output_file_path = Path(__file__).parent / "speech.wav"
7
8with client.audio.speech.with_streaming_response.create(
9 model='tts-1',
10 voice='cdteam',
11 input='Xin chào Việt Nam.',
12 speed=1.0,
13 response_format='wav'
14) as response:
15 response.stream_to_file('a.wav')1# Get all built-in voices
2curl --location http://0.0.0.0:8298/v1/voices
3
4# OpenAI format (bult-in voices)
5curl http://localhost:8298/v1/audio/speech \
6 -H "Authorization: Bearer viet-tts" \
7 -H "Content-Type: application/json" \
8 -d '{
9 "model": "tts-1",
10 "input": "Xin chào Việt Nam.",
11 "voice": "son-tung-mtp"
12 }' \
13 --output speech.wav
14
15# API with voice from local file
16curl --location http://0.0.0.0:8298/v1/tts \
17 --form 'text="xin chào"' \
18 --form 'audio_file=@"/home/viettts/Downloads/voice.mp4"' \
19 --output speech.wav1import fs from "fs";
2import path from "path";
3import OpenAI from "openai";
4
5const openai = new OpenAI();
6
7const speechFile = path.resolve("./speech.wav");
8
9async function main() {
10 const mp3 = await openai.audio.speech.create({
11 model: "tts-1",
12 voice: "1",
13 input: "Xin chào Việt Nam.",
14 });
15 console.log(speechFile);
16 const buffer = Buffer.from(await mp3.arrayBuffer());
17 await fs.promises.writeFile(speechFile, buffer);
18}
19main();