"""Pocket TTS Turkish demo: type Turkish text, pick a voice and an emotion, listen.""" import gradio as gr import numpy as np from pocket_tts_turkish import TurkishTTS MODEL = "wite-tech/pocket-tts-turkish" MAX_CHARS = 600 VOICES = [ ("female_1 (recommended): bright and energetic", "female_1"), ("female_2: warm, clear and friendly", "female_2"), ("female_3: confident, clear articulation", "female_3"), ("male_1: calm and deep", "male_1"), ("male_2: energetic and bright", "male_2"), ("male_3: confident, crisp articulation", "male_3"), ] EMOTIONS = [ ("neutral", "neutral"), ("mutlu (happy)", "mutlu"), ("üzgün (sad)", "üzgün"), ("kızgın (angry)", "kızgın"), ("şaşkın (surprised)", "şaşkın"), ("sakin (calm)", "sakin"), ] EXAMPLES = [ "Merhaba, size nasıl yardımcı olabilirim?", "Randevunuz 12.11.2026 Perşembe günü saat 09:45'te. Lütfen 15 dakika önce hazır olun.", "Bize 0212 555 12 34 numaralı hattan, hafta içi 08:30-17:30 arasında ulaşabilirsiniz.", "Siparişinizin toplam tutarı 1.249,90 TL. Kargo ücreti ise 49,90 TL olarak eklendi.", "Yarın İstanbul'da hava parçalı bulutlu, sıcaklık 18 ile 24 °C arasında olacak.", "Küçük bir sahil kasabasında yaşayan yaşlı bir balıkçı, her sabah güneş doğmadan denize açılırdı. " "Bir gün ağına takılan eski bir şişenin içinde bir mektup buldu.", ] tts = TurkishTTS.from_pretrained(MODEL, device="cpu") tts.generate("Merhaba.") def synthesize(text: str, voice: str, emotion: str): """Speak the text with the chosen voice and emotion; return 24 kHz audio.""" text = (text or "").strip() if not text: raise gr.Error("Please enter some Turkish text.") if len(text) > MAX_CHARS: raise gr.Error(f"Please keep the text under {MAX_CHARS} characters.") try: audio = tts.generate(text, voice=voice, emotion=None if emotion == "neutral" else emotion) except ValueError as e: raise gr.Error(str(e)) from e return tts.sample_rate, (np.clip(audio, -1.0, 1.0) * 32767).astype(np.int16) with gr.Blocks(title="Pocket TTS Turkish") as demo: gr.Markdown( "# Pocket TTS Turkish\n" "Turkish text-to-speech that runs faster than real time on a CPU.\n\n" "[Model card](https://huggingface.co/wite-tech/pocket-tts-turkish) | " "[Python package](https://github.com/witetech/pocket-tts-turkish)" ) with gr.Row(): with gr.Column(): text = gr.Textbox(label="Text", lines=5, max_length=MAX_CHARS, value=EXAMPLES[0]) voice = gr.Dropdown(label="Voice", choices=VOICES, value="female_1") emotion = gr.Dropdown(label="Emotion", choices=EMOTIONS, value="neutral") button = gr.Button("Generate", variant="primary") with gr.Column(): audio = gr.Audio(label="Speech", type="numpy", interactive=False) gr.Examples(examples=[[t] for t in EXAMPLES], inputs=[text], cache_examples=False) gr.Markdown( "The demo uses the six built-in voices, which are synthetic. The Python package can also clone a " "voice from a recording; only clone a voice with the consent of the person it belongs to." ) button.click(synthesize, inputs=[text, voice, emotion], outputs=[audio], concurrency_limit=1) demo.queue(max_size=20).launch()