Views
No views yet
float16.twi-g2p).1# 1. Clone StyleTTS2 repository
2git clone [https://github.com/yl4579/StyleTTS2.git](https://github.com/yl4579/StyleTTS2.git)
3cd StyleTTS2
4
5# 2. Install core requirements
6pip install munch torch torchaudio pydub pyyaml librosa nltk matplotlib \
7 accelerate transformers phonemizer einops einops-exts tqdm \
8 git+[https://github.com/resemble-ai/monotonic_align.git](https://github.com/resemble-ai/monotonic_align.git)
9
10# 3. Install Twi-specific tools & datasets
11pip install datasets git+[https://github.com/Ghana-NLP/twi-g2p.git](https://github.com/Ghana-NLP/twi-g2p.git)
12
13# 4. Install system dependencies (for espeak-ng fallback)
14sudo apt-get install -y espeak-nggenerate_twi.py inside the cloned StyleTTS2 folder. Ensure you have the checkpoint and config_ft.yml in the same directory.1import torch
2import yaml
3from twi_g2p.g2p import G2P
4from models import build_model
5from utils import *
6
7# Load device
8device = 'cuda' if torch.cuda.is_available() else 'cpu'
9
10# 1. Load Config
11config = yaml.safe_load(open("config_ft.yml"))
12
13# 2. Build Model
14# Note: Ensure the 'models.py' from the StyleTTS2 repo is present
15model = build_model(recursive_munch(config['model_params']), None)
16params = torch.load("epoch_2nd_00024.pth", map_location=device)
17
18# Load the weights into the model dictionary
19for key in model:
20 if key in params['net']:
21 model[key].load_state_dict(params['net'][key])
22_ = [model[key].eval().to(device) for key in model]
23
24# 3. Setup Phonemizer
25g2p = G2P()
26
27def synthesize(text, reference_wav_path):
28 # Convert Twi text to phonemes
29 phones = g2p.convert(text)
30 print(f"Synthesizing: {text}")
31 print(f"Phonemes: {phones}")
32
33 # Note: You will need the 'inference' helper function
34 # from the original StyleTTS2 notebook/script to generate the audio.
35 # wav = inference(text, ref_s, alpha=0.3, beta=0.7, diffusion_steps=5)
36 return phones