Files
storyteller-ml/tts/StyleTTS2/fakeyou_infer.py
T
2024-01-11 13:53:33 +05:30

42 lines
1.5 KiB
Python

# FakeYou StyleTTS 2 Inference
import argparse
import numpy as np
import soundfile as sf
from styletts2importable import compute_style, inference
from tortoise.utils.text import split_and_recombine_text
def clsynthesize(text_file_path, voice_path, vcsteps):
# Load the text from the file
with open(text_file_path, 'r', encoding="utf-8") as file:
text = file.read()
# Load the custom voice
custom_voice = compute_style(voice_path)
# Split and recombine long text into manageable chunks
texts = split_and_recombine_text(text)
audios = []
for t in texts:
# Generate audio for each text chunk
audios.append(inference(t, custom_voice, alpha=0.3, beta=0.7, diffusion_steps=vcsteps, embedding_scale=1))
return 24000, np.concatenate(audios)
def main():
parser = argparse.ArgumentParser(description='CLI for StyleTTS Voice Synthesis')
parser.add_argument('--input', type=str, required=True, help='Path to the text file')
parser.add_argument('--voice', type=str, required=True, help='Path to the custom voice audio file')
parser.add_argument('--vcsteps', type=int, required=True, help='Number of diffusion steps')
parser.add_argument('--output', type=str, required=True, help='Output path for the synthesized audio file')
args = parser.parse_args()
sample_rate, audio = clsynthesize(args.input, args.voice, args.vcsteps)
# Save the synthesized audio to the specified output path
sf.write(args.output, audio, sample_rate)
if __name__ == "__main__":
main()