Nick088 commited on
Commit
ecfd6dc
β€’
1 Parent(s): a9fd765

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gtts import gTTS
3
+ import io
4
+ import os
5
+ import librosa
6
+ import soundfile as sf
7
+
8
+ def text_to_speech(text, language_accent, pitch):
9
+ lang, tld = language_tld_map[language_accent].split(',')
10
+
11
+ # create the text-to-speech audio
12
+ tts = gTTS(text, lang=lang, tld=tld)
13
+ tts.save('gtts.wav')
14
+
15
+ # Load the audio file
16
+ y, sr = librosa.load('gtts.wav')
17
+
18
+ # Specify the number of semitones to shift
19
+ new_y = librosa.effects.pitch_shift(y=y, sr=sr, n_steps=pitch)
20
+
21
+ sf.write("generated_gtts.wav", new_y, sr)
22
+
23
+ # return the generated audio
24
+ return 'generated_gtts.wav'
25
+
26
+
27
+ language_tld_map = {
28
+ "English_Australia": "en,com.au",
29
+ "English_United_Kingdom": "en,co.uk",
30
+ "English_United_States": "en,com",
31
+ "English_Canada": "en,ca",
32
+ "English_Nigerian": "en,com.ng",
33
+ "English_Ireland": "en,ie",
34
+ "English_South Africa": "en,co.za",
35
+ "French_Canada": "fr,ca",
36
+ "French_France": "fr,fr",
37
+ "Mandarin_China_Mainland": "zh-CN,com",
38
+ "Mandarin_Taiwan": "zh-TW,com",
39
+ "Portuguese_Brazil": "pt,com.br",
40
+ "Portuguese_Portugal": "pt,pt",
41
+ "Spanish_Mexico": "es,com.mx",
42
+ "Spanish_Spain": "es,es",
43
+ "Spanish_United_States": "es,com"
44
+ }
45
+
46
+ # create the Gradio interface
47
+ iface = gr.Interface(fn=text_to_speech,
48
+ inputs=[gr.Textbox(lines=10, label="Enter your text here:"),
49
+ gr.Dropdown(choices=list(language_tld_map.keys()), label="Select Language & Accent:", value="English_United_Kingdom", type="value"),
50
+ gr.Number(label="Pitch", value=0, type="value")],
51
+ outputs=[gr.Audio(label="Audio")],
52
+ allow_flagging="never")
53
+
54
+ iface.launch(enable_queue=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gTTS
2
+ librosa
3
+ soundfile