File size: 2,548 Bytes
d9d7e71
e3cbd88
d9d7e71
 
 
ed0756f
 
 
d9d7e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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()