-
Notifications
You must be signed in to change notification settings - Fork 14
/
generate_voices.py
31 lines (24 loc) · 962 Bytes
/
generate_voices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from supervoice_valle import Supervoice, Tokenizer
from encodec import EncodecModel
from pathlib import Path
import torch
# Load tokenizer
tokenizer = Tokenizer("./tokenizer_text.model")
# Load encodec
encodec_model = EncodecModel.encodec_model_24khz()
encodec_model.set_target_bandwidth(6.0)
# We don't need a real model for this task
model = Supervoice(None, None, encodec_model, None, tokenizer)
# Find all wav files in the voices directory
wav_files = list(Path('voices').glob('*.flac'))
wav_files = [f.stem for f in wav_files]
# Generate voices
for id in wav_files:
print(f"Processing {id}")
with open("./voices/" + id + ".txt", 'r') as f:
text = f.read().strip()
created_voice = model.create_voice(audio = "./voices/" + id + ".flac", text = text)
torch.save(created_voice, f"./voices/{id}.pt")
# Generate index file
with open("supervoice_valle/voices_gen.py", "w") as f:
f.write(f"available_voices = {wav_files}")