2024-02-13 14:15:27 +01:00
|
|
|
|
import gradio as gr
|
2024-02-14 17:49:51 +01:00
|
|
|
|
|
|
|
|
|
|
# import TTS
|
2024-02-13 14:15:27 +01:00
|
|
|
|
import os
|
2024-02-14 17:49:51 +01:00
|
|
|
|
|
|
|
|
|
|
# import torch
|
2024-02-13 14:15:27 +01:00
|
|
|
|
|
|
|
|
|
|
from .BaseTTSEngine import BaseTTSEngine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CoquiTTSEngine(BaseTTSEngine):
|
|
|
|
|
|
voices = [
|
|
|
|
|
|
"Claribel Dervla",
|
|
|
|
|
|
"Daisy Studious",
|
|
|
|
|
|
"Gracie Wise",
|
|
|
|
|
|
"Tammie Ema",
|
|
|
|
|
|
"Alison Dietlinde",
|
|
|
|
|
|
"Ana Florence",
|
|
|
|
|
|
"Annmarie Nele",
|
|
|
|
|
|
"Asya Anara",
|
|
|
|
|
|
"Brenda Stern",
|
|
|
|
|
|
"Gitta Nikolina",
|
|
|
|
|
|
"Henriette Usha",
|
|
|
|
|
|
"Sofia Hellen",
|
|
|
|
|
|
"Tammy Grit",
|
|
|
|
|
|
"Tanja Adelina",
|
|
|
|
|
|
"Vjollca Johnnie",
|
|
|
|
|
|
"Andrew Chipper",
|
|
|
|
|
|
"Badr Odhiambo",
|
|
|
|
|
|
"Dionisio Schuyler",
|
|
|
|
|
|
"Royston Min",
|
|
|
|
|
|
"Viktor Eka",
|
|
|
|
|
|
"Abrahan Mack",
|
|
|
|
|
|
"Adde Michal",
|
|
|
|
|
|
"Baldur Sanjin",
|
|
|
|
|
|
"Craig Gutsy",
|
|
|
|
|
|
"Damien Black",
|
|
|
|
|
|
"Gilberto Mathias",
|
|
|
|
|
|
"Ilkin Urbano",
|
|
|
|
|
|
"Kazuhiko Atallah",
|
|
|
|
|
|
"Ludvig Milivoj",
|
|
|
|
|
|
"Suad Qasim",
|
|
|
|
|
|
"Torcull Diarmuid",
|
|
|
|
|
|
"Viktor Menelaos",
|
|
|
|
|
|
"Zacharie Aimilios",
|
|
|
|
|
|
"Nova Hogarth",
|
|
|
|
|
|
"Maja Ruoho",
|
|
|
|
|
|
"Uta Obando",
|
|
|
|
|
|
"Lidiya Szekeres",
|
|
|
|
|
|
"Chandra MacFarland",
|
|
|
|
|
|
"Szofi Granger",
|
|
|
|
|
|
"Camilla Holmström",
|
|
|
|
|
|
"Lilya Stainthorpe",
|
|
|
|
|
|
"Zofija Kendrick",
|
|
|
|
|
|
"Narelle Moon",
|
|
|
|
|
|
"Barbora MacLean",
|
|
|
|
|
|
"Alexandra Hisakawa",
|
|
|
|
|
|
"Alma María",
|
|
|
|
|
|
"Rosemary Okafor",
|
|
|
|
|
|
"Ige Behringer",
|
|
|
|
|
|
"Filip Traverse",
|
|
|
|
|
|
"Damjan Chapman",
|
|
|
|
|
|
"Wulf Carlevaro",
|
|
|
|
|
|
"Aaron Dreschner",
|
|
|
|
|
|
"Kumar Dahl",
|
|
|
|
|
|
"Eugenio Mataracı",
|
|
|
|
|
|
"Ferran Simen",
|
|
|
|
|
|
"Xavier Hayasaka",
|
|
|
|
|
|
"Luis Moray",
|
|
|
|
|
|
"Marcos Rudaski",
|
|
|
|
|
|
]
|
|
|
|
|
|
name = "Coqui TTS"
|
|
|
|
|
|
description = "Coqui TTS engine."
|
|
|
|
|
|
languages = [
|
|
|
|
|
|
"en", # English
|
|
|
|
|
|
"es", # Spanish
|
|
|
|
|
|
"fr", # French
|
|
|
|
|
|
"de", # German
|
|
|
|
|
|
"it", # Italian
|
|
|
|
|
|
"pt", # Portuguese
|
|
|
|
|
|
"pl", # Polish
|
|
|
|
|
|
"tr", # Turkish
|
|
|
|
|
|
"ru", # Russian
|
|
|
|
|
|
"nl", # Dutch
|
|
|
|
|
|
"cs", # Czech
|
|
|
|
|
|
"ar", # Arabic
|
|
|
|
|
|
"zh-cn", # Chinese (Simplified)
|
|
|
|
|
|
"ja", # Japanese
|
|
|
|
|
|
"hu", # Hungarian
|
|
|
|
|
|
"ko", # Korean
|
|
|
|
|
|
"hi", # Hindi
|
|
|
|
|
|
]
|
2024-02-15 12:27:13 +01:00
|
|
|
|
num_options = 4
|
2024-02-13 14:29:49 +01:00
|
|
|
|
|
|
|
|
|
|
def __init__(self, options: list):
|
2024-02-13 14:15:27 +01:00
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
2024-02-13 14:29:49 +01:00
|
|
|
|
self.voice = options[0][0]
|
|
|
|
|
|
self.language = options[1][0]
|
2024-02-15 12:27:13 +01:00
|
|
|
|
self.to_force_duration = options[2][0]
|
|
|
|
|
|
self.duration = options[3]
|
2024-02-13 14:29:49 +01:00
|
|
|
|
|
2024-02-13 14:15:27 +01:00
|
|
|
|
os.environ["COQUI_TOS_AGREED"] = "1"
|
2024-02-14 17:49:51 +01:00
|
|
|
|
|
|
|
|
|
|
# self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
|
|
|
|
|
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
# self.tts.to(device)
|
2024-02-13 14:15:27 +01:00
|
|
|
|
|
|
|
|
|
|
def synthesize(self, text: str, path: str) -> str:
|
2024-02-14 17:49:51 +01:00
|
|
|
|
# self.tts.tts_to_file(text=text, file_path=path, lang=self.language, speaker=self.voice)
|
2024-02-15 12:27:13 +01:00
|
|
|
|
if self.to_force_duration:
|
|
|
|
|
|
self.force_duration(float(self.duration), path)
|
2024-02-14 17:49:51 +01:00
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def get_options(cls) -> list:
|
2024-02-15 12:27:13 +01:00
|
|
|
|
options = [
|
2024-02-14 17:49:51 +01:00
|
|
|
|
gr.Dropdown(
|
|
|
|
|
|
label="Voice",
|
|
|
|
|
|
choices=cls.voices,
|
|
|
|
|
|
max_choices=1,
|
|
|
|
|
|
value=cls.voices[0],
|
|
|
|
|
|
),
|
|
|
|
|
|
gr.Dropdown(
|
|
|
|
|
|
label="Language",
|
|
|
|
|
|
choices=cls.languages,
|
|
|
|
|
|
max_choices=1,
|
|
|
|
|
|
value=cls.languages[0],
|
|
|
|
|
|
),
|
|
|
|
|
|
]
|
2024-02-15 12:27:13 +01:00
|
|
|
|
|
|
|
|
|
|
duration_checkbox = gr.Checkbox(value=False)
|
|
|
|
|
|
duration = gr.Number(label="Duration", value=57, step=1, minimum=10, visible=False)
|
|
|
|
|
|
duration_switch = lambda x: gr.update(visible=x)
|
|
|
|
|
|
duration_checkbox.change(duration_switch, inputs=[duration_checkbox], outputs=[duration])
|
|
|
|
|
|
duration_checkbox_group = gr.CheckboxGroup([duration_checkbox], label="Force duration")
|
|
|
|
|
|
|
|
|
|
|
|
options.append(duration_checkbox_group)
|
|
|
|
|
|
options.append(duration)
|
|
|
|
|
|
return options
|