Spaces:
Running
Running
Amelia-James
commited on
Commit
•
2a95377
1
Parent(s):
6325c8c
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
import streamlit as st
|
4 |
-
from groq import Groq
|
5 |
import tempfile
|
|
|
6 |
|
7 |
# Load environment variables
|
8 |
load_dotenv()
|
@@ -12,7 +13,7 @@ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
|
12 |
|
13 |
# Streamlit UI
|
14 |
st.title("Voice Cloning Application")
|
15 |
-
st.markdown("Clone your voice using
|
16 |
|
17 |
# Upload audio file
|
18 |
uploaded_file = st.file_uploader(
|
@@ -24,42 +25,50 @@ if uploaded_file is not None:
|
|
24 |
# Display uploaded audio
|
25 |
audio_format = uploaded_file.type.split('/')[-1]
|
26 |
st.audio(uploaded_file, format=f"audio/{audio_format}")
|
27 |
-
st.write("
|
28 |
|
29 |
# Save the uploaded file to a temporary location
|
30 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.' + audio_format) as temp_audio:
|
31 |
temp_audio.write(uploaded_file.read())
|
32 |
temp_audio_path = temp_audio.name
|
33 |
|
34 |
-
# Transcription Logic
|
35 |
try:
|
36 |
-
#
|
37 |
-
transcription_response = client.transcriptions.create(
|
38 |
-
|
39 |
-
model="whisper-large-v3"
|
|
|
40 |
)
|
41 |
|
42 |
-
# Extract the transcribed text
|
43 |
-
transcribed_text = transcription_response
|
44 |
st.success("Transcription completed!")
|
45 |
st.write("**Transcribed Text:**", transcribed_text)
|
46 |
|
47 |
-
#
|
48 |
st.markdown("---")
|
49 |
st.subheader("Generate Speech from Transcription")
|
50 |
tts_input = st.text_area("Enter text to generate speech:", value=transcribed_text)
|
51 |
|
52 |
if st.button("Generate Speech"):
|
53 |
if tts_input:
|
54 |
-
#
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
else:
|
57 |
st.warning("Please enter some text.")
|
58 |
|
59 |
except Exception as e:
|
60 |
-
st.error(f"Error during
|
61 |
finally:
|
62 |
-
# Clean up
|
63 |
os.remove(temp_audio_path)
|
64 |
|
65 |
# Footer
|
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
import streamlit as st
|
4 |
+
from groq import Groq
|
5 |
import tempfile
|
6 |
+
import requests # Use for calling APIs if Groq's SDK doesn't support transcription
|
7 |
|
8 |
# Load environment variables
|
9 |
load_dotenv()
|
|
|
13 |
|
14 |
# Streamlit UI
|
15 |
st.title("Voice Cloning Application")
|
16 |
+
st.markdown("Clone your voice using Whisper for transcription and TTS for voice generation.")
|
17 |
|
18 |
# Upload audio file
|
19 |
uploaded_file = st.file_uploader(
|
|
|
25 |
# Display uploaded audio
|
26 |
audio_format = uploaded_file.type.split('/')[-1]
|
27 |
st.audio(uploaded_file, format=f"audio/{audio_format}")
|
28 |
+
st.write("Processing your audio file...")
|
29 |
|
30 |
# Save the uploaded file to a temporary location
|
31 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.' + audio_format) as temp_audio:
|
32 |
temp_audio.write(uploaded_file.read())
|
33 |
temp_audio_path = temp_audio.name
|
34 |
|
|
|
35 |
try:
|
36 |
+
# Call transcription API (adjust as per Groq API documentation)
|
37 |
+
transcription_response = client.audio.transcriptions.create(
|
38 |
+
file=open(temp_audio_path, "rb"), # Use binary file for API
|
39 |
+
model="whisper-large-v3-turbo",
|
40 |
+
response_format="text" # Adjust format if needed
|
41 |
)
|
42 |
|
43 |
+
# Extract the transcribed text
|
44 |
+
transcribed_text = transcription_response # May vary; adjust based on API response
|
45 |
st.success("Transcription completed!")
|
46 |
st.write("**Transcribed Text:**", transcribed_text)
|
47 |
|
48 |
+
# Voice Cloning (TTS Integration)
|
49 |
st.markdown("---")
|
50 |
st.subheader("Generate Speech from Transcription")
|
51 |
tts_input = st.text_area("Enter text to generate speech:", value=transcribed_text)
|
52 |
|
53 |
if st.button("Generate Speech"):
|
54 |
if tts_input:
|
55 |
+
# Use a TTS system to generate audio (placeholder)
|
56 |
+
tts_response = requests.post(
|
57 |
+
"https://tts.api.url", # Replace with actual TTS API URL
|
58 |
+
json={"text": tts_input, "voice": "en-US-Wavenet-D"} # Adjust parameters
|
59 |
+
)
|
60 |
+
if tts_response.status_code == 200:
|
61 |
+
st.audio(tts_response.content, format="audio/mp3")
|
62 |
+
st.success("Speech generation successful!")
|
63 |
+
else:
|
64 |
+
st.error(f"Error in TTS: {tts_response.json()}")
|
65 |
else:
|
66 |
st.warning("Please enter some text.")
|
67 |
|
68 |
except Exception as e:
|
69 |
+
st.error(f"Error during processing: {e}")
|
70 |
finally:
|
71 |
+
# Clean up temporary file
|
72 |
os.remove(temp_audio_path)
|
73 |
|
74 |
# Footer
|