tejesh09 commited on
Commit
af8effb
·
verified ·
1 Parent(s): 77ccf4d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import soundfile as sf
4
+ import tempfile
5
+
6
+ # Streamlit page setup
7
+ st.set_page_config(page_title="Hugging Face Text-to-Speech", page_icon="🎤", layout="centered")
8
+ st.title("🎤 Text to Speech Converter (Hugging Face)")
9
+
10
+ # Text input from user
11
+ text = st.text_area("Enter the text you want to convert to speech:", height=150)
12
+
13
+ # Choose model
14
+ model_name = st.selectbox(
15
+ "Select a Hugging Face TTS model:",
16
+ ["suno/bark-small", "facebook/speecht5_tts", "espnet/kan-bayashi_ljspeech_vits"],
17
+ index=0
18
+ )
19
+
20
+ if st.button("Convert to Speech"):
21
+ if text.strip() == "":
22
+ st.warning("Please enter some text.")
23
+ else:
24
+ st.info("Generating speech... please wait ⏳")
25
+ tts = pipeline("text-to-speech", model=model_name)
26
+ output = tts(text)
27
+
28
+ # Get audio and sampling rate
29
+ audio = output["audio"]
30
+ sr = output["sampling_rate"]
31
+
32
+ # Save audio to a temporary file
33
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
34
+ sf.write(tmpfile.name, audio, sr)
35
+ audio_path = tmpfile.name
36
+
37
+ st.success("✅ Conversion complete!")
38
+ st.audio(audio_path, format="audio/wav")
39
+ st.download_button(
40
+ label="📥 Download Audio",
41
+ data=open(audio_path, "rb").read(),
42
+ file_name="tts_output.wav",
43
+ mime="audio/wav"
44
+ )