-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_to_speech_app.py
49 lines (36 loc) · 1.4 KB
/
text_to_speech_app.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# STREAMLIT VERSION OF TEXT TO SPEECH APPLICATION
import streamlit as st
import os
from google.cloud import texttospeech_v1
from google.cloud import texttospeech
# Set Google Cloud credentials
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'sa_text_demo.json'
# Initialize Streamlit app
st.title("Text to Speech App")
text = st.text_area("Enter the text to convert to speech")
if st.button("Convert to Speech"):
client = texttospeech_v1.TextToSpeechClient()
synthesis_input = texttospeech_v1.SynthesisInput(text=text)
voice1 = texttospeech_v1.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech_v1.SsmlVoiceGender.MALE
)
audio_config = texttospeech_v1.AudioConfig(
audio_encoding=texttospeech_v1.AudioEncoding.MP3
)
response = client.synthesize_speech(
input=synthesis_input,
voice=voice1,
audio_config=audio_config
)
audio_file = response.audio_content
audio = st.audio(audio_file, format="audio/wav")
# with open("audio.wav", "rb") as file:
# btn = st.download_button(
# label="Download Audio File",
# data=file,
# file_name="audio.wav",
# mime="audio/wav"
# )
if __name__ == '__main__':
st.write("Enter the text and click the 'Convert to Speech' button to synthesize speech.")