Coqui / app.py
tayyardurden's picture
Upload 2 files
3bc0ed3 verified
from TTS.api import TTS
import streamlit as st
import time
import os
os.environ['COQUI_TOS_AGREED'] = '1'
os.environ['BARK_TOS_AGREED'] = '1'
st.header("Bas Konuş")
# Initialize TTS object when the page is loaded
@st.cache_resource()
def model_coqui():
device = "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
return tts # return the tts object
# @st.cache_resource()
def model_bark():
device = "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/bark").to(device)
return tts
col1, col2 = st.columns(2)
with col1:
sentence = st.text_area("Konuşmak istediğiniz metni girin")
with col2:
language = st.selectbox("Dil Seçin", ["Ceylin", "Funda"])
if language == "Ceylin":
speaker_wav = "sounds/glinda.mp3"
else:
speaker_wav = "sounds/alp.mp3"
speaker=st.button("Seslendir")
if speaker:
col11, col22 = st.columns(2)
with col11:
tts_coqui = model_coqui()
start_time_coqui = time.time() # Start the timer
output_path_coqui = tts_coqui.tts_to_file(text=sentence, speaker_wav=speaker_wav ,language="tr")
end_time = time.time() # End the timer
execution_time = round(end_time - start_time_coqui,2) # Calculate the time taken
st.write(f"Coqui için tamamlanma süresi: {execution_time} saniye") # Display the time taken
st.audio(output_path_coqui, format="audio/mp3")
with col22:
tts_bark = model_bark()
speaker_wav_2 = "speaker_embeddings/tr_speaker_0"
start_time_bark = time.time()
output_path_bark = tts_bark.tts_to_file(text=sentence, speaker_wav=speaker_wav_2)
end_time = time.time()
execution_time = round(end_time - start_time_bark,2)
st.write(f"Bark içi tamamlanma süresi: {execution_time} saniye")
st.audio(output_path_bark, format="audio/mp3")