|
|
import os |
|
|
import gradio as gr |
|
|
import torch |
|
|
from TTS.api import TTS |
|
|
import spaces |
|
|
import tempfile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from TTS.tts.configs.xtts_config import XttsConfig |
|
|
from TTS.tts.models.xtts import Xtts, XttsAudioConfig, XttsArgs |
|
|
from TTS.config.shared_configs import BaseDatasetConfig |
|
|
|
|
|
|
|
|
SAFE_GLOBALS = [XttsConfig, XttsAudioConfig, Xtts, BaseDatasetConfig, XttsArgs] |
|
|
|
|
|
|
|
|
torch.serialization.add_safe_globals(SAFE_GLOBALS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os.environ["COQUI_TOS_AGREED"] = "1" |
|
|
|
|
|
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu" |
|
|
|
|
|
print(f"Kullanılan Cihaz: {device}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REFERENCE_AUDIO_PATH = "audio/reference.wav" |
|
|
|
|
|
|
|
|
if not os.path.exists(REFERENCE_AUDIO_PATH): |
|
|
print(f"UYARI: Referans ses dosyası bulunamadı: {REFERENCE_AUDIO_PATH}") |
|
|
print("Lütfen Space'inize 'audio' adında bir klasör oluşturun ve içine 'reference.wav' adında bir ses dosyası yükleyin.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2") |
|
|
tts.to(device) |
|
|
print("TTS modeli başarıyla yüklendi.") |
|
|
except Exception as e: |
|
|
|
|
|
print(f"KRİTİK HATA: TTS modeli yüklenemedi. Hata: {e}") |
|
|
raise e |
|
|
|
|
|
|
|
|
|
|
|
@spaces.GPU |
|
|
def clone(text, language): |
|
|
""" |
|
|
Verilen ses dosyasından sesi klonlar ve metni bu sesle seslendirir. |
|
|
Bu fonksiyon artık sabit bir referans ses dosyası kullanır. |
|
|
""" |
|
|
if not text or not language: |
|
|
gr.Warning("Lütfen metin ve dil seçimi alanlarını doldurun.") |
|
|
return gr.update(value=None) |
|
|
|
|
|
|
|
|
if not os.path.exists(REFERENCE_AUDIO_PATH): |
|
|
error_msg = f"Referans ses dosyası bulunamadı: {REFERENCE_AUDIO_PATH}" |
|
|
gr.Error(error_msg) |
|
|
print(error_msg) |
|
|
return gr.update(value=None) |
|
|
|
|
|
try: |
|
|
|
|
|
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_wav_file: |
|
|
output_path = temp_wav_file.name |
|
|
|
|
|
print(f"Ses klonlama başlatıldı. Metin: '{text}', Dil: '{language}'") |
|
|
|
|
|
|
|
|
tts.tts_to_file(text=text, speaker_wav=REFERENCE_AUDIO_PATH, language=language.lower(), file_path=output_path) |
|
|
|
|
|
print(f"Ses dosyası başarıyla oluşturuldu: {output_path}") |
|
|
|
|
|
|
|
|
return gr.update(value=output_path) |
|
|
|
|
|
except Exception as e: |
|
|
error_message = f"Ses klonlama sırasında bir hata oluştu: {e}" |
|
|
print(error_message) |
|
|
gr.Error(error_message) |
|
|
return gr.update(value=None) |
|
|
|
|
|
|
|
|
with gr.Blocks(title="Gelişmiş Ses Klonlama", theme=gr.themes.Soft(primary_hue="teal")) as demo: |
|
|
gr.Markdown( |
|
|
""" |
|
|
# 🎤 Gelişmiş Ses Klonlama |
|
|
**Vortex Tarafından Geliştirilmiştir** |
|
|
|
|
|
Bu uygulama, ses klonlama için **xtts_v2** modelini kullanır. |
|
|
*Sadece ticari olmayan kullanım içindir.* |
|
|
|
|
|
[Coqui Kamu Modeli Lisansı](https://coqui.ai/cpml) |
|
|
--- |
|
|
""" |
|
|
) |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(scale=2): |
|
|
text_input = gr.Textbox( |
|
|
label="Seslendirilecek Metin", |
|
|
placeholder="Klonlanmış sesin söylemesini istediğiniz metni buraya yazın...", |
|
|
lines=5 |
|
|
) |
|
|
|
|
|
language_input = gr.Dropdown( |
|
|
label="Dil", |
|
|
choices=["tr", "en", "es", "fr", "de", "it", "pt", "pl", "ru", "zh-cn", "ja", "ko"], |
|
|
value="tr" |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clone_button = gr.Button("Sesi Klonla", variant="primary") |
|
|
|
|
|
with gr.Column(scale=1): |
|
|
output_audio = gr.Audio( |
|
|
label="Klonlanmış Ses Çıktısı" |
|
|
) |
|
|
|
|
|
gr.Markdown( |
|
|
""" |
|
|
--- |
|
|
❤️ Bu uygulamayı faydalı bulduysanız, lütfen bir beğeni bırakmayı düşünün! |
|
|
""" |
|
|
) |
|
|
|
|
|
clone_button.click( |
|
|
fn=clone, |
|
|
|
|
|
|
|
|
inputs=[text_input, language_input], |
|
|
|
|
|
outputs=[output_audio], |
|
|
queue=True |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
demo.launch() |
|
|
|