Spaces:
Sleeping
Sleeping
| from gtts import gTTS | |
| from transformers import pipeline | |
| import gradio as gr | |
| import soundfile as sf | |
| narrator_en = pipeline("text-to-speech", model="facebook/mms-tts-eng" ) | |
| narrator_fr = pipeline("text-to-speech", model="facebook/mms-tts-fra") | |
| # 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 fonction | |
| def MMS_func(text, lang): | |
| if lang == 'en': | |
| narrated_text = narrator_en(text) | |
| sf.write("narrated_audio2.wav", narrated_text["audio"][0], narrated_text["sampling_rate"]) | |
| return 'narrated_audio2.wav' | |
| else: | |
| narrated_text = narrator_fr(text) | |
| sf.write("narrated_audio3.wav", narrated_text["audio"][0], narrated_text["sampling_rate"]) | |
| return 'narrated_audio3.wav' | |
| demo = gr.Blocks() | |
| # gtts interface | |
| gtts_iface = gr.Interface(fn = gtts_func, | |
| inputs = [gr.Textbox(label="Text", | |
| lines=6), gr.Textbox(label="language", | |
| lines=1)], | |
| outputs = 'audio', | |
| title = 'Text-to-speech gtts Application', | |
| description = 'This app allows you to narrate any english text by using gtts library' | |
| ) | |
| # MMS TTS english-french interface | |
| mms_iface = gr.Interface(fn = MMS_func, | |
| inputs = [gr.Textbox(label="Text", | |
| lines=6), gr.Textbox(label="language", | |
| lines=1)], | |
| outputs = 'audio', | |
| title = 'MMS english-french Text-to-speech Application', | |
| description = 'This app allows you to narrate any english or french text by using MMS text-to-speech of facebook' | |
| ) | |
| with demo: | |
| gr.TabbedInterface( | |
| [gtts_iface, | |
| mms_iface], | |
| # mms_fr_iface], | |
| ["gtts narrator", | |
| "MMS english-french narrator"]) | |
| demo.launch() |