Download app.py from akazmi/hackaton2: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/akazmi/hackaton2/resolve/main/app.py
- Command line
-
hf download hf://spaces/akazmi/hackaton2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/akazmi/hackaton2/resolve/main/app.py
1.02 kB
| import streamlit as st | |
| from gtts import gTTS | |
| import pyttsx3 | |
| import os | |
| # Function to use Google Text-to-Speech (gTTS) | |
| def gtts_text_to_speech(text): | |
| tts = gTTS(text=text, lang='en', slow=False) | |
| tts.save("output.mp3") | |
| return "output.mp3" | |
| # Function to use pyttsx3 (Offline TTS) | |
| def pyttsx3_text_to_speech(text): | |
| engine = pyttsx3.init() | |
| engine.save_to_file(text, "output.mp3") | |
| engine.runAndWait() | |
| return "output.mp3" | |
| # Streamlit UI | |
| st.title("Text-to-Speech Converter") | |
| # Input text | |
| user_input = st.text_area("Enter text:", "Hello, how can I assist you today?") | |
| # Select TTS option | |
| tts_option = st.radio("Choose Text-to-Speech Method", ("Google TTS", "Offline TTS")) | |
| # Button to convert to speech | |
| if st.button("Convert to Speech"): | |
| if tts_option == "Google TTS": | |
| output_file = gtts_text_to_speech(user_input) | |
| else: | |
| output_file = pyttsx3_text_to_speech(user_input) | |
| st.audio(output_file, format="audio/mp3") | |
| st.success("Speech generated successfully!") | |