Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import gradio as gr
|
|
| 3 |
import torch
|
| 4 |
from TTS.api import TTS
|
| 5 |
import os
|
|
|
|
|
|
|
| 6 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 7 |
|
| 8 |
device = "cuda"
|
|
@@ -11,12 +13,40 @@ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
|
| 11 |
|
| 12 |
@spaces.GPU(enable_queue=True)
|
| 13 |
def clone(text, audio):
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
iface = gr.Interface(fn=clone,
|
| 18 |
-
inputs=[gr.Textbox(label='Text'),gr.Audio(type='filepath', label='Voice reference audio file')],
|
| 19 |
-
outputs=gr.Audio(type='filepath'),
|
| 20 |
-
title='Voice Clone',
|
| 21 |
-
theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"))
|
| 22 |
iface.launch()
|
|
|
|
| 3 |
import torch
|
| 4 |
from TTS.api import TTS
|
| 5 |
import os
|
| 6 |
+
import json
|
| 7 |
+
|
| 8 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 9 |
|
| 10 |
device = "cuda"
|
|
|
|
| 13 |
|
| 14 |
@spaces.GPU(enable_queue=True)
|
| 15 |
def clone(text, audio):
|
| 16 |
+
# Generowanie mowy
|
| 17 |
+
wav, alignment, text_info, _ = tts.tts(text=text, speaker_wav=audio, language="pl", return_type="dict")
|
| 18 |
+
|
| 19 |
+
# Zapisywanie pliku audio
|
| 20 |
+
tts.save_wav(wav, file_path="./output.wav")
|
| 21 |
+
|
| 22 |
+
# Przygotowanie informacji o fonemach
|
| 23 |
+
phonemes_info = []
|
| 24 |
+
for phoneme, start, end in zip(text_info["phonemes"], alignment["align_durations"], alignment["align_durations_cumsum"]):
|
| 25 |
+
phonemes_info.append({
|
| 26 |
+
"phoneme": phoneme,
|
| 27 |
+
"start": float(start),
|
| 28 |
+
"end": float(end)
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
# Zapisywanie informacji o fonemach do pliku JSON
|
| 32 |
+
with open("./phonemes_info.json", "w", encoding="utf-8") as f:
|
| 33 |
+
json.dump(phonemes_info, f, ensure_ascii=False, indent=2)
|
| 34 |
+
|
| 35 |
+
return "./output.wav", "./phonemes_info.json"
|
| 36 |
+
|
| 37 |
+
# Interfejs Gradio
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=clone,
|
| 40 |
+
inputs=[
|
| 41 |
+
gr.Textbox(label='Tekst do syntezy'),
|
| 42 |
+
gr.Audio(type='filepath', label='Plik audio z głosem referencyjnym')
|
| 43 |
+
],
|
| 44 |
+
outputs=[
|
| 45 |
+
gr.Audio(type='filepath', label='Zsyntezowana mowa'),
|
| 46 |
+
gr.File(label='Informacje o fonemach (JSON)')
|
| 47 |
+
],
|
| 48 |
+
title='Klonowanie Głosu z Informacjami o Fonemach',
|
| 49 |
+
theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate")
|
| 50 |
+
)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
iface.launch()
|