Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gtts import gTTS
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
|
| 6 |
+
narrator_en = pipeline("text-to-speech", model="facebook/mms-tts-eng" )
|
| 7 |
+
narrator_fr = pipeline("text-to-speech", model="facebook/mms-tts-fra")
|
| 8 |
+
|
| 9 |
+
# gtts fonction
|
| 10 |
+
def gtts_func(text, lang):
|
| 11 |
+
myobj = gTTS(text=text, lang=lang, slow=False)
|
| 12 |
+
myobj.save("narrated_audio1.wav")
|
| 13 |
+
return 'narrated_audio1.wav'
|
| 14 |
+
# MMS TTS fonction
|
| 15 |
+
def MMS_func(text, lang):
|
| 16 |
+
if lang == 'en':
|
| 17 |
+
narrated_text = narrator_en(text)
|
| 18 |
+
sf.write("narrated_audio2.wav", narrated_text["audio"][0], narrated_text["sampling_rate"])
|
| 19 |
+
return 'narrated_audio2.wav'
|
| 20 |
+
else:
|
| 21 |
+
narrated_text = narrator_fr(text)
|
| 22 |
+
sf.write("narrated_audio3.wav", narrated_text["audio"][0], narrated_text["sampling_rate"])
|
| 23 |
+
return 'narrated_audio3.wav'
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
demo = gr.Blocks()
|
| 27 |
+
# gtts interface
|
| 28 |
+
gtts_iface = gr.Interface(fn = gtts_func,
|
| 29 |
+
inputs = [gr.Textbox(label="Text",
|
| 30 |
+
lines=6), gr.Textbox(label="language",
|
| 31 |
+
lines=1)],
|
| 32 |
+
outputs = 'audio',
|
| 33 |
+
title = 'Text-to-speech gtts Application',
|
| 34 |
+
description = 'This app allows you to narrate any english text by using gtts library'
|
| 35 |
+
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# MMS TTS english-french interface
|
| 39 |
+
mms_iface = gr.Interface(fn = MMS_func,
|
| 40 |
+
inputs = [gr.Textbox(label="Text",
|
| 41 |
+
lines=6), gr.Textbox(label="language",
|
| 42 |
+
lines=1)],
|
| 43 |
+
outputs = 'audio',
|
| 44 |
+
title = 'MMS english-french Text-to-speech Application',
|
| 45 |
+
description = 'This app allows you to narrate any english or french text by using MMS text-to-speech of facebook'
|
| 46 |
+
|
| 47 |
+
)
|
| 48 |
+
with demo:
|
| 49 |
+
gr.TabbedInterface(
|
| 50 |
+
[gtts_iface,
|
| 51 |
+
mms_iface],
|
| 52 |
+
# mms_fr_iface],
|
| 53 |
+
["gtts narrator",
|
| 54 |
+
"MMS english-french narrator"])
|
| 55 |
+
|
| 56 |
+
demo.launch()
|