NaseemTahir commited on
Commit
ff72d7d
·
verified ·
1 Parent(s): 26cccd6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from TTS.api import TTS
3
+ import torch
4
+ from io import BytesIO
5
+
6
+ # Initialize the TTS model
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=True, gpu=device == "cuda")
9
+
10
+ # App title
11
+ st.title("🐸 Coqui TTS - Text to Speech App")
12
+
13
+ # Text input
14
+ text = st.text_area("Enter the text to convert to speech", "Imagine being able to offer your clients curated travel insights at their fingertips.")
15
+
16
+ # File upload for voice cloning (optional)
17
+ speaker_wav = st.file_uploader("Upload a speaker audio file for voice cloning (optional)", type=["wav"])
18
+
19
+ # Submit button
20
+ if st.button("Generate Speech"):
21
+ if text.strip() == "":
22
+ st.warning("Please enter some text.")
23
+ else:
24
+ # Run TTS
25
+ st.text("Generating speech...")
26
+ try:
27
+ if speaker_wav is not None:
28
+ # Use voice cloning
29
+ wav = tts.tts(text=text, speaker_wav=speaker_wav)
30
+ else:
31
+ # Default voice
32
+ wav = tts.tts(text=text)
33
+
34
+ # Display audio player
35
+ st.audio(wav, format="audio/wav")
36
+
37
+ # Option to download the audio file
38
+ buffer = BytesIO()
39
+ buffer.write(wav)
40
+ buffer.seek(0)
41
+ st.download_button("Download Audio", buffer, file_name="output.wav", mime="audio/wav")
42
+ except Exception as e:
43
+ st.error(f"An error occurred: {e}")