greykingreys's picture
Update app.py
e3cbd88 verified
from gtts import gTTS
from transformers import pipeline
import soundfile as sf
# importer gradio
import gradio as gr
narrator_en = pipeline("text-to-speech", model="facebook/mms-tts-eng" )
narrator_fr = pipeline("text-to-speech", model="facebook/mms-tts-fra")
# Créer les blocs
demo = gr.Blocks(theme='NoCrypt/miku')
import soundfile as sf
# gtts fonction
def gtts_func(text, lang):
myobj = gTTS(text=text, lang=lang, slow=False)
myobj.save("narrated_audio1.wav")
return 'narrated_audio1.wav'
# MMS TTS english fonction
def MMS_en_func(text):
narrated_text = narrator_en(text)
sf.write("narrated_audio2.wav", narrated_text["audio"][0], narrated_text["sampling_rate"])
return 'narrated_audio2.wav'
# MMS TTS french fonction
def MMS_fr_func(text):
narrated_text = narrator_fr(text)
sf.write("narrated_audio3.wav", narrated_text["audio"][0], narrated_text["sampling_rate"])
return 'narrated_audio3.wav'
# gtts interface
import joblib
languages = joblib.load('languages.joblib')
gtts_iface = gr.Interface(fn = gtts_func,
inputs = [gr.Textbox(label="Text",
lines=6), gr.Dropdown(choices= languages, label="language")],
outputs = 'audio',
cache_examples = True,
title = 'Text-to-speech gtts Application',
description = 'This app allows you to narrate any english text by using gtts library'
)
# MMS TTS english interface
mms_en_iface = gr.Interface(fn = MMS_en_func,
inputs = gr.Textbox(label="Text",
lines=6),
outputs = 'audio',
title = 'MMS english Text-to-speech Application',
description = 'This app allows you to narrate any english text by using MMS english text-to-speech of facebook'
)
# MMS TTS french interface
mms_fr_iface = gr.Interface(fn = MMS_fr_func,
inputs = gr.Textbox(label="Text",
lines=6),
outputs = 'audio',
title = 'MMS french Text-to-speech Application',
description = 'This app allows you to narrate any english text by using MMS french text-to-speech of facebook'
)
with demo:
gr.TabbedInterface(
[gtts_iface,
mms_en_iface,
mms_fr_iface],
["gtts narrator",
"MMS english narrator",
"MMS french narrator"])
demo.launch()