Spaces:
Build error
Build error
Tauqeer Hassan commited on
Commit ·
06ea690
1
Parent(s): f32a8fe
first commit
Browse files- app.py +44 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio import Textbox, Radio, Audio
|
| 3 |
+
from gtts import gTTS
|
| 4 |
+
import pyttsx3
|
| 5 |
+
|
| 6 |
+
# Function to generate MP3 file using gTTS
|
| 7 |
+
def generate_mp3(text, language, filename):
|
| 8 |
+
tts = gTTS(text=text, lang=language)
|
| 9 |
+
tts.save(filename)
|
| 10 |
+
|
| 11 |
+
# Function to generate MP3 file using pyttsx3
|
| 12 |
+
def generate_mp3_pyttsx3(text, filename, voice):
|
| 13 |
+
audio_engine = pyttsx3.init()
|
| 14 |
+
audio_engine.setProperty('voice', voice)
|
| 15 |
+
audio_engine.save_to_file(text, filename)
|
| 16 |
+
audio_engine.runAndWait()
|
| 17 |
+
print("Done")
|
| 18 |
+
|
| 19 |
+
# Main function
|
| 20 |
+
def text_to_speech(text, language, english_voice):
|
| 21 |
+
filename = "output.mp3"
|
| 22 |
+
if language == "English":
|
| 23 |
+
if english_voice == "Female Voice 1":
|
| 24 |
+
english_voice = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0'
|
| 25 |
+
generate_mp3_pyttsx3(text,filename, english_voice)
|
| 26 |
+
elif english_voice == "Male Voice":
|
| 27 |
+
english_voice = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0'
|
| 28 |
+
generate_mp3_pyttsx3(text,filename, english_voice)
|
| 29 |
+
else:
|
| 30 |
+
generate_mp3(text, 'en', filename)
|
| 31 |
+
else:
|
| 32 |
+
generate_mp3(text, 'ur', filename)
|
| 33 |
+
return filename
|
| 34 |
+
|
| 35 |
+
# Gradio Interface
|
| 36 |
+
inputs = [
|
| 37 |
+
Textbox(lines=5, label="Enter Text"),
|
| 38 |
+
Radio(["English", "Urdu"], label="Select Language"),
|
| 39 |
+
Radio(["Female Voice 1", "Male Voice", "Female Voice 2"], label="Select English Voice")
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
outputs = Audio(label="Download MP3")
|
| 43 |
+
|
| 44 |
+
gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs, title="Text to Speech Converter").launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
gtts
|
| 3 |
+
pyttsx3
|