Downloads · 30 days
924
35% of all-time downloads
99eren99/piper-turkish-tts
piper-turkish-tts is a text-to-speech model from 99eren99. Use it when you need text read aloud.
Downloads · 30 days
924
35% of all-time downloads
All-time downloads
2.7K
Public
Repo size
63.5 MB
Likes
5
Trending 1
Click a slice to open those files.
.onnx63.5 MB · 100%
From the Hugging Face model README
# 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("...",". ").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")