Hướng dẫn cài Coqui TTS

  1. Cài python
Python Releases for Windows
The official home of the Python Programming Language

Bạn có thể cài nhiều bản python cùng lúc.

Bật cmd chạy 2 lệnh sau:

python -m pip install --upgrade pip
pip install --upgrade virtualenv
  1. Cài TTS
GitHub - coqui-ai/TTS: 🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production
🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production - coqui-ai/TTS
Hướng dẫn trên trang chủ

Ở trang chủ khuyên dùng python >= 3.9, < 3.12 nên mình chọn 3.11

Để cho tiện bạn nên tạo một môi trường ảo.

mkdir coqui_tts
cd coqui_tts
virtualenv py311 --python=python311
.\py311\Scripts\activate
Bạn đang ở môi trường py311

Giờ thì chạy lệnh install như ở trang chủ:

pip install TTS
Khá lâu đấy!
Báo lỗi thiếu build tools.

Nếu gặp lỗi trên bạn vào cái link này rồi cài:

Chọn cái C++. (Bỏ cái Winows 11 SDK đi cho nhẹ)Cài xong thì chạy lại cái pip install TTS.
Cài xong.
  1. CUDA

Nếu bạn dùng card NVDIA thì cài thêm cái này để dùng CUDA cho nhanh. Không thì bỏ qua, lúc này sẽ chạy bằng CPU chậm hơn.

Bạn cũng cần cài lại torch.

pip uninstall torch
pip install torch --index-url https://download.pytorch.org/whl/cu118
CUDA Toolkit 12.1 Downloads
Get the latest feature updates to NVIDIA’s proprietary compute stack.
  1. Chạy thử

Tạo folder output

mkdir output

Tạo một file test.py

import torch
from TTS.api import TTS

text = """ a deep learning toolkit for Text-to-Speech, battle-tested in research and production """
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
print(device)
# List available 🐸TTS models

tts = TTS("tts_models/en/ljspeech/fast_pitch").to(device)
tts.tts_to_file(text, file_path="output/output.wav")

Chạy thử

python test.py
Lần đầu chạy sẽ phải download model về.
Nghe thử
audio-thumbnail
Output
0:00
/6.026304

Bạn có thể thử các model khác ở đây

tts --list_models