Piper Turkish Tts
import imageioffmpeg from pydub import AudioSegment AudioSegment.converter = imageioffmpeg.getffmpegexe()
Model source
- Kind
- Other
- File size
- 60.6 MB
- Version
- vRevision f7dfff9
- Updated
- Sep 19, 2026
- Downloads
- 492
- Source
- Hugging Face
Source description
# pip install piper-tts huggingface_hub pydub nltk imageio-ffmpeg
import imageio_ffmpeg
from pydub import AudioSegment
AudioSegment.converter = imageio_ffmpeg.get_ffmpeg_exe()
import time
from huggingface_hub import hf_hub_download
from pydub import AudioSegment
from piper import PiperVoice, SynthesisConfig
import nltk
nltk.download('punkt')
nltk.download('punkt_tab')
from nltk.tokenize import sent_tokenize
MODEL_PATH = hf_hub_download(
repo_id="99eren99/piper-turkish-tts",
filename="model.onnx"
)
CONFIG_PATH = hf_hub_download(
repo_id="99eren99/piper-turkish-tts",
filename="config.json"
)
MODEL = PiperVoice.load(MODEL_PATH,config_path=CONFIG_PATH, use_cuda=False)
# ==============================
# TTS FUNCTION
# ==============================
def generate(text, save_path, volume=1, length_scale=1.2, noise_scale=0.4, noise_w_scale=0.3,
silence_ms_duration_between_setences=400, normalize_audio=False):
if not text or not text.strip():
return None
text = text.replace("...",". ")
syn_config = SynthesisConfig(
volume=volume,
length_scale=length_scale,
noise_scale=noise_scale,
noise_w_scale=noise_w_scale,
normalize_audio=normalize_audio,
)
t0 = time.time()
first = True
combined = AudioSegment.silent(duration=0)
fade_ms = 5
silence = AudioSegment.silent(duration=silence_ms_duration_between_setences)
combined += silence
for sentence in sent_tokenize(text, language="turkish"):
for audio_chunk in MODEL.synthesize(sentence, syn_config=syn_config):
if first:
time_to_audio = "Time To First Bytes(seconds): " + str(time.time() - t0)
first = False
segment = AudioSegment(
data=audio_chunk.audio_int16_bytes,
sample_width=2,
frame_rate=22050,
channels=1
)
segment = segment.fade_in(fade_ms).fade_out(fade_ms)
combined += segment + silence
real_time_factor = "Real Time Factor: " + str((time.time() - t0) / combined.duration_seconds)
time_to_generate = "Total Time To Generate(seconds): "+str(time.time() - t0)
metrics = "\n".join([real_time_factor,time_to_audio,time_to_generate])
print(metrics)
combined.export(save_path, format="mp3", bitrate="320k")
generate("fanfinfon","out.mp3")
Sources
1 source
Sources
1 sourceVerified Aug 22
Model artifacts
1 artifact
Model artifacts
1 artifactSource excerpts
2 excerpts
Source excerpts
2 excerpts--- language: - tr pipeline_tag: text-to-speech --- ``` python # pip install piper-tts huggingface_hub pydub nltk imageio-ffmpeg import imageio_ffmpeg from pydub import AudioSegment AudioSegment.converter = imageio_ffmpeg.get_ffmpeg_exe() import time from huggingface_hub import hf_hub_download from pydub import AudioSegment from piper import PiperVoice, SynthesisConfig import nltk nltk.download('punkt') nltk.download('punkt_tab') from nltk.tokenize import sent_tokenize MODEL_PATH = hf_hub_download( repo_id="99eren99/piper-turkish-tts", filename="model.onnx" ) CONFIG_PATH = hf_hub_download( repo_id="99eren99/piper-turkish-tts", filename="config.json" ) MODEL = PiperVoice.load(MODEL_PATH,config_path=CONFIG_PATH, use_cuda=False) # ============================== # TTS FUNCTION # ============================== def generate(text, save_path, volume=1, length_scale=1.2, noise_scale=0.4, noise_w_scale=0.3, silence_ms_duration_between_setences=400, normalize_audio=False): if not text or not text.strip(): return None text = text.replace("...",". ") syn_config = SynthesisConfig( volume=volume, length_scale=length_scale, noise_scale=noise_scale, noise_w_scale=noise_w_scale, normalize_audio=normalize_audio, ) t0 = time.time() first = True combined = AudioSegment.silent(duration=0) fade_ms = 5 silence = AudioSegment.silent(duration=silence_ms_duration_between_setences) combined += silence for sentence in sent_tokenize(text, language="turkish"): for audio_chunk in MODEL.synthesize(sentence, syn_config=syn_config): if first: time_to_audio = "Time To First Bytes(seconds): " + str(time.time() - t0) first = False segment = AudioSegment( data=audio_chunk.audio_int16_bytes, sample_width=2, frame_rate=22050, channels=1 ) segment = segment.fade_in(fade_ms).fade_out(fade_ms) combined += segment + silence real_time_factor = "Real Time Factor: " + str((time.time() - t0) / combined.duration_seconds) time_to_generate = "Total Time To Generate(seconds): "+str(time.time() - t0) metrics = "\n".join([real_time_factor,time_to_audio,time_to_generate]) print(metrics) combined.export(save_path, format="mp3", bitrate="320k") generate("fanfinfon","out.mp3") ```
Source context: 492 downloads · 1 likes · Pipeline text-to-speech · Repo 99eren99/piper-turkish-tts
