Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
import av
|
4 |
import whisper
|
5 |
import openai
|
|
|
6 |
import tempfile
|
7 |
import os
|
8 |
-
from gtts import gTTS
|
9 |
-
from pydub import AudioSegment
|
10 |
|
11 |
# Set your API Key (Groq-compatible)
|
12 |
openai.api_key = os.getenv("GROQ_API_KEY", "your-groq-api-key")
|
@@ -18,30 +16,17 @@ st.title("ποΈ Voice-to-Voice Conversational App")
|
|
18 |
|
19 |
st.info("π€ Record your voice and click 'Stop' to process:")
|
20 |
|
21 |
-
|
22 |
-
key="example",
|
23 |
-
mode=WebRtcMode.SENDRECV,
|
24 |
-
audio_receiver_size=1024,
|
25 |
-
media_stream_constraints={"audio": True, "video": False},
|
26 |
-
)
|
27 |
-
|
28 |
-
if "audio_bytes" not in st.session_state:
|
29 |
-
st.session_state.audio_bytes = b""
|
30 |
-
|
31 |
-
if webrtc_ctx.audio_receiver:
|
32 |
-
audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=1)
|
33 |
-
for frame in audio_frames:
|
34 |
-
st.session_state.audio_bytes += frame.to_ndarray().tobytes()
|
35 |
|
36 |
-
if
|
37 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
st.audio(
|
42 |
|
43 |
st.info("π Transcribing...")
|
44 |
-
result = model.transcribe(
|
45 |
user_input = result["text"]
|
46 |
st.success(f"You said: {user_input}")
|
47 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit_mic import st_mic
|
|
|
3 |
import whisper
|
4 |
import openai
|
5 |
+
from gtts import gTTS
|
6 |
import tempfile
|
7 |
import os
|
|
|
|
|
8 |
|
9 |
# Set your API Key (Groq-compatible)
|
10 |
openai.api_key = os.getenv("GROQ_API_KEY", "your-groq-api-key")
|
|
|
16 |
|
17 |
st.info("π€ Record your voice and click 'Stop' to process:")
|
18 |
|
19 |
+
audio_data = st_mic()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
if audio_data:
|
22 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
23 |
+
tmp.write(audio_data)
|
24 |
+
tmp_path = tmp.name
|
25 |
|
26 |
+
st.audio(tmp_path)
|
27 |
|
28 |
st.info("π Transcribing...")
|
29 |
+
result = model.transcribe(tmp_path)
|
30 |
user_input = result["text"]
|
31 |
st.success(f"You said: {user_input}")
|
32 |
|