Upload app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pyttsx3
|
3 |
from gtts import gTTS
|
4 |
from io import BytesIO
|
5 |
|
@@ -15,31 +14,11 @@ def tts_gtts(text):
|
|
15 |
return mp3_fp
|
16 |
|
17 |
|
18 |
-
# https://github.com/nateshmbhat/pyttsx3
|
19 |
-
# https://pyttsx3.readthedocs.io/en/latest/
|
20 |
-
#
|
21 |
-
def tts_pyttsx3(text, gender="F"):
|
22 |
-
mp3_fp = BytesIO()
|
23 |
-
engine = pyttsx3.init()
|
24 |
-
gender_idx = 1
|
25 |
-
if gender == "M":
|
26 |
-
gender_idx = 0
|
27 |
-
voices = engine.getProperty('voices') # details of current voice
|
28 |
-
engine.setProperty('voice', voices[gender_idx].id) # 0 for male and 1 for female
|
29 |
-
engine.save_to_file(text, mp3_fp)
|
30 |
-
engine.runAndWait()
|
31 |
-
return mp3_fp
|
32 |
-
|
33 |
-
|
34 |
def pronounce(text, gender=None):
|
35 |
if len(text) > 0:
|
36 |
data1 = tts_gtts(text)
|
37 |
st.text('gTTS (gender not supported):')
|
38 |
st.audio(data1, format="audio/wav", start_time=0)
|
39 |
-
if gender is None and gender is not None: # pyttsx3 not working with streamlit
|
40 |
-
data2 = tts_pyttsx3(text, gender)
|
41 |
-
st.text('pyttsx3:')
|
42 |
-
st.audio(data2, format="audio/wav", start_time=0)
|
43 |
|
44 |
|
45 |
def main():
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from gtts import gTTS
|
3 |
from io import BytesIO
|
4 |
|
|
|
14 |
return mp3_fp
|
15 |
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def pronounce(text, gender=None):
|
18 |
if len(text) > 0:
|
19 |
data1 = tts_gtts(text)
|
20 |
st.text('gTTS (gender not supported):')
|
21 |
st.audio(data1, format="audio/wav", start_time=0)
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
def main():
|