Spaces:
Sleeping
Sleeping
Revert back 24h (wrong repo commit)
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import torch
|
|
| 6 |
|
| 7 |
CUDA = torch.cuda.is_available()
|
| 8 |
|
| 9 |
-
REPO_ID = "
|
| 10 |
|
| 11 |
VOICE_CONVERSION_MODELS = {
|
| 12 |
'freevc24': 'voice_conversion_models/multilingual/vctk/freevc24',
|
|
@@ -14,26 +14,17 @@ VOICE_CONVERSION_MODELS = {
|
|
| 14 |
'openvoice_v2': 'voice_conversion_models/multilingual/multi-dataset/openvoice_v2',
|
| 15 |
}
|
| 16 |
|
| 17 |
-
my_title = "
|
| 18 |
-
my_description = "
|
| 19 |
-
|
| 20 |
-
# Load speakers from local speakers.pth
|
| 21 |
-
speakers_dict = torch.load('speakers.pth', map_location='cpu')
|
| 22 |
-
SPEAKER_IDS = list(speakers_dict.keys())
|
| 23 |
-
|
| 24 |
-
# Create mapping: "Speaker 1" -> actual hash ID
|
| 25 |
-
SPEAKER_CHOICES = [f"Speaker {i+1}" for i in range(len(SPEAKER_IDS))]
|
| 26 |
-
SPEAKER_MAP = {f"Speaker {i+1}": SPEAKER_IDS[i] for i in range(len(SPEAKER_IDS))}
|
| 27 |
|
| 28 |
my_examples = [
|
| 29 |
-
["
|
| 30 |
-
["
|
| 31 |
-
["
|
| 32 |
]
|
| 33 |
|
| 34 |
my_inputs = [
|
| 35 |
-
gr.Textbox(lines=5, label="Text
|
| 36 |
-
gr.Dropdown(label="Speaker", choices=SPEAKER_CHOICES, value="Speaker 1"),
|
| 37 |
gr.Checkbox(label="Split Sentences", value=False),
|
| 38 |
gr.Audio(type="filepath", label="Speaker audio for voice cloning (optional)"),
|
| 39 |
gr.Dropdown(label="Voice Conversion Model", choices=list(VOICE_CONVERSION_MODELS.keys())),
|
|
@@ -41,19 +32,19 @@ my_inputs = [
|
|
| 41 |
|
| 42 |
my_outputs = gr.Audio(type="filepath", label="Output Audio", autoplay=True)
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
api = TTS(model_path=best_model_path, config_path=
|
| 48 |
|
| 49 |
# pre-download voice conversion models
|
| 50 |
for model in VOICE_CONVERSION_MODELS.values():
|
| 51 |
api.load_vc_model_by_name(model, gpu=CUDA)
|
| 52 |
|
| 53 |
-
def tts(text: str,
|
| 54 |
-
#
|
| 55 |
-
speaker_id = SPEAKER_MAP[speaker_name]
|
| 56 |
-
|
| 57 |
text = text.replace("\n", ". ")
|
| 58 |
text = text.replace("(", ",")
|
| 59 |
text = text.replace(")", ",")
|
|
@@ -62,9 +53,9 @@ def tts(text: str, speaker_name: str, split_sentences: bool = False, speaker_wav
|
|
| 62 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
| 63 |
if speaker_wav:
|
| 64 |
api.load_vc_model_by_name(VOICE_CONVERSION_MODELS[voice_cv_model], gpu=CUDA)
|
| 65 |
-
api.tts_with_vc_to_file(text, speaker_wav=speaker_wav, file_path=fp.name, split_sentences=split_sentences
|
| 66 |
else:
|
| 67 |
-
api.tts_to_file(text, file_path=fp.name, split_sentences=split_sentences
|
| 68 |
|
| 69 |
return fp.name
|
| 70 |
|
|
|
|
| 6 |
|
| 7 |
CUDA = torch.cuda.is_available()
|
| 8 |
|
| 9 |
+
REPO_ID = "collectivat/catotron-ona"
|
| 10 |
|
| 11 |
VOICE_CONVERSION_MODELS = {
|
| 12 |
'freevc24': 'voice_conversion_models/multilingual/vctk/freevc24',
|
|
|
|
| 14 |
'openvoice_v2': 'voice_conversion_models/multilingual/multi-dataset/openvoice_v2',
|
| 15 |
}
|
| 16 |
|
| 17 |
+
my_title = "Catotron Text-to-Speech with Voice Conversion"
|
| 18 |
+
my_description = "This space allows speaker conversion on Fast Speech based 馃惛 [Catotron](https://huggingface.co/collectivat/catotron-ona)."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
my_examples = [
|
| 21 |
+
["Catotron, s铆ntesi de la parla obert i lliure en catal脿.", True, None, 'freevc24'],
|
| 22 |
+
["Leonor Ferrer Girabau va ser una delineant, mestra i activista barcelonina, nascuda al carrer actual de la Conc貌rdia del Poble-sec, que es va convertir en la primera dona a obtenir el t铆tol de delineant a Catalunya i a l'estat.", True, None, 'freevc24'],
|
| 23 |
+
["S'espera un dia anticicl貌nic amb temperatures suaus i vent fluix.", False, None, 'freevc24']
|
| 24 |
]
|
| 25 |
|
| 26 |
my_inputs = [
|
| 27 |
+
gr.Textbox(lines=5, label="Input Text"),
|
|
|
|
| 28 |
gr.Checkbox(label="Split Sentences", value=False),
|
| 29 |
gr.Audio(type="filepath", label="Speaker audio for voice cloning (optional)"),
|
| 30 |
gr.Dropdown(label="Voice Conversion Model", choices=list(VOICE_CONVERSION_MODELS.keys())),
|
|
|
|
| 32 |
|
| 33 |
my_outputs = gr.Audio(type="filepath", label="Output Audio", autoplay=True)
|
| 34 |
|
| 35 |
+
best_model_path = hf_hub_download(repo_id=REPO_ID, filename="fast-speech_best_model.pth")
|
| 36 |
+
config_path = hf_hub_download(repo_id=REPO_ID, filename="fast-speech_config.json")
|
| 37 |
+
vocoder_model = hf_hub_download(repo_id=REPO_ID, filename="ljspeech--hifigan_v2_model_file.pth")
|
| 38 |
+
vocoder_config = hf_hub_download(repo_id=REPO_ID, filename="ljspeech--hifigan_v2_config.json")
|
| 39 |
|
| 40 |
+
api = TTS(model_path=best_model_path, config_path=config_path, vocoder_path=vocoder_model, vocoder_config_path=vocoder_config).to("cuda" if CUDA else "cpu")
|
| 41 |
|
| 42 |
# pre-download voice conversion models
|
| 43 |
for model in VOICE_CONVERSION_MODELS.values():
|
| 44 |
api.load_vc_model_by_name(model, gpu=CUDA)
|
| 45 |
|
| 46 |
+
def tts(text: str, split_sentences: bool = False, speaker_wav: str = None, voice_cv_model: str = 'freevc24'):
|
| 47 |
+
# replace oov characters
|
|
|
|
|
|
|
| 48 |
text = text.replace("\n", ". ")
|
| 49 |
text = text.replace("(", ",")
|
| 50 |
text = text.replace(")", ",")
|
|
|
|
| 53 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
| 54 |
if speaker_wav:
|
| 55 |
api.load_vc_model_by_name(VOICE_CONVERSION_MODELS[voice_cv_model], gpu=CUDA)
|
| 56 |
+
api.tts_with_vc_to_file(text, speaker_wav=speaker_wav, file_path=fp.name, split_sentences=split_sentences)
|
| 57 |
else:
|
| 58 |
+
api.tts_to_file(text, file_path=fp.name, split_sentences=split_sentences)
|
| 59 |
|
| 60 |
return fp.name
|
| 61 |
|