vakodiya commited on
Commit
ca7863d
1 Parent(s): e872cbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -30
app.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import io
5
  import wave
6
  import requests
7
- from audio_processor import process_audio
8
 
9
 
10
  # Initialize Streamlit app layout
@@ -14,35 +14,25 @@ def audio_callback(frame):
14
  # Get raw audio data from the frame
15
  audio_data = frame.to_ndarray().astype(np.int16)
16
 
17
- # Save audio data to a WAV file
18
- with io.BytesIO() as wav_buffer:
19
- with wave.open(wav_buffer, 'wb') as wav_file:
20
- wav_file.setnchannels(1) # Mono
21
- wav_file.setsampwidth(2) # 16-bit
22
- wav_file.setframerate(16000) # Sample rate
23
- wav_file.writeframes(audio_data.tobytes())
24
- wav_buffer.seek(0)
25
- audio_bytes = wav_buffer.read()
26
-
27
- # Convert audio to text
28
- transcription = process_audio(audio_bytes)
29
-
30
- # Display the transcription
31
- st.write("Transcription:", transcription)
32
-
33
- API_URL = "https://eaa0-34-74-179-199.ngrok-free.app/generate"
34
- # Optionally, send the transcription to an API
35
- headers = {
36
- "Content-Type": "application/json"
37
- }
38
- payload = {
39
- "prompt": transcription
40
- }
41
- response = requests.post(API_URL, json=payload, headers=headers)
42
- if response.status_code == 200:
43
- st.write("Assistant:", response.json())
44
- else:
45
- st.write("Error:", response.status_code, response.text)
46
 
47
 
48
  webrtc_ctx = webrtc_streamer(
 
4
  import io
5
  import wave
6
  import requests
7
+ from audio_to_text import audio_to_text
8
 
9
 
10
  # Initialize Streamlit app layout
 
14
  # Get raw audio data from the frame
15
  audio_data = frame.to_ndarray().astype(np.int16)
16
 
17
+ # Convert audio to text
18
+ transcription = audio_to_text(audio_data)
19
+
20
+ # Display the transcription
21
+ st.write("Transcription:", transcription)
22
+
23
+ API_URL = "https://eaa0-34-74-179-199.ngrok-free.app/generate"
24
+ # Optionally, send the transcription to an API
25
+ headers = {
26
+ "Content-Type": "application/json"
27
+ }
28
+ payload = {
29
+ "prompt": transcription
30
+ }
31
+ response = requests.post(API_URL, json=payload, headers=headers)
32
+ if response.status_code == 200:
33
+ st.write("Assistant:", response.json())
34
+ else:
35
+ st.write("Error:", response.status_code, response.text)
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  webrtc_ctx = webrtc_streamer(