File size: 1,404 Bytes
a5c86e8
 
1d2e2ec
 
5457abc
1d2e2ec
 
 
a5c86e8
9b2107c
 
 
 
 
9ec632b
9b2107c
 
5e91596
9b2107c
 
 
 
 
 
 
 
2027d9d
e06517d
f151e5d
8412594
543bb48
9ac4871
9b2107c
 
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
32
33
34
import subprocess

# Run the setup.py install command
try:
    subprocess.run(['python', 'setup.py', 'install', '--user'], check=True)
    print("Installation successful.")
except subprocess.CalledProcessError as e:
    print(f"Installation failed with error: {e}")

import gradio as gr
import torch
from TTS.api import TTS

# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"

# Init TTS
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)

def voice_clone(text: str, speaker_wav: str, language: str):
    # Run TTS
    print("Speaker wav:", speaker_wav)
    tts.tts_to_file(text=text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
    return "output.wav"

iface = gr.Interface(fn=voice_clone, 
                     inputs=[gr.Textbox(lines=2, placeholder="Введите текст, чтобы озвучить...", label="Текст"),
                             gr.Audio(type="filepath", label="Загрузить аудиофайл"),
                             gr.Radio(['ru', 'en', 'zh-cn', 'ja', 'de', 'fr', 'it', 'pt', 'pl', 'tr', 'ko', 'nl', 'cs', 'ar', 'es', 'hu'], label="Выбрать язык"),
                            ],
                     outputs=gr.Audio(type="filepath", label="Сгенерированный аудиофайл"), 
                     title="Клонированние голоса")

iface.launch()