File size: 1,543 Bytes
3f53728
a13c70d
11fdcf5
 
 
820c332
 
11fdcf5
 
 
 
 
a13c70d
3f53728
a13c70d
820c332
d3b49fc
820c332
 
 
 
d3b49fc
 
 
820c332
d3b49fc
 
 
820c332
d3b49fc
820c332
 
 
 
d3b49fc
820c332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a13c70d
d3b49fc
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import spaces
import gradio as gr
import torch
from TTS.api import TTS
import os
import json

os.environ["COQUI_TOS_AGREED"] = "1"

device = "cuda"

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

@spaces.GPU(enable_queue=True)
def clone(text, audio):
    # Generowanie mowy
    wav = tts.tts(text=text, speaker_wav=audio, language="pl")
    
    # Zapisywanie pliku audio
    tts.save_wav(wav, file_path="./output.wav")
    
    # Uzyskanie informacji o fonemach
    phonemes_info = tts.synthesizer.get_phonemes(text, language="pl")
    
    # Przygotowanie informacji o fonemach
    phonemes_data = []
    for phoneme, duration in phonemes_info:
        phonemes_data.append({
            "phoneme": phoneme,
            "duration": float(duration)
        })
    
    # Zapisywanie informacji o fonemach do pliku JSON
    with open("./phonemes_info.json", "w", encoding="utf-8") as f:
        json.dump(phonemes_data, f, ensure_ascii=False, indent=2)
    
    return "./output.wav", "./phonemes_info.json"

# Interfejs Gradio
iface = gr.Interface(
    fn=clone, 
    inputs=[
        gr.Textbox(label='Tekst do syntezy'),
        gr.Audio(type='filepath', label='Plik audio z głosem referencyjnym')
    ], 
    outputs=[
        gr.Audio(type='filepath', label='Zsyntezowana mowa'),
        gr.File(label='Informacje o fonemach (JSON)')
    ],
    title='Klonowanie Głosu z Informacjami o Fonemach',
    theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate")
)

iface.launch(share=True)