-
Notifications
You must be signed in to change notification settings - Fork 1
/
voice_over.py
25 lines (22 loc) · 922 Bytes
/
voice_over.py
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
import streamlit as st
from app import *
import gtts
talking_languages = gtts.lang.tts_langs()
def get_tts_lang_code(language):
for code in talking_languages:
if language in talking_languages[code]:
return code
return 'Not Supported'
@__cached__
def google_tts_talk(content, language):
if get_tts_lang_code(language) == 'Not supported':
return f"<p>Speech is not yet implemented for {language}</p>"
sound_file = BytesIO()
tts = gtts.gTTS(content, lang='en', slow=False)
tts.write_to_fp(sound_file)
st.audio(sound_file)
# audio_base64 = base64.b64encode(sound_file).decode("utf-8")
audio_base64 = base64.b64encode(sound_file.getvalue())
return f'<audio autoplay="true" src="data:audio/wav;base64,{audio_base64}">'
st.header("sggggggggggg")
st.markdown(google_tts_talk("Hi i am america", 'English'), unsafe_allow_html = True)