vakodiya commited on
Commit
a205074
1 Parent(s): 30a9a6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import streamlit as st
2
  import numpy as np
3
  import io
 
4
  import wave
5
  import requests
6
  from audio_to_text import audio_to_text
7
  from streamlit_mic_recorder import mic_recorder
8
 
 
 
 
9
  # Initialize Streamlit app layout
10
  st.title("Microphone Input in Streamlit")
11
 
@@ -20,12 +24,13 @@ audio = mic_recorder(
20
  # Check if audio is recorded
21
  if audio:
22
  st.audio(audio['bytes'], format='audio/wav')
23
-
24
- # Get raw audio data from the frame
25
- audio_data = np.frombuffer(audio['bytes'], dtype=np.int16)
 
26
 
27
  # Convert audio to text
28
- transcription = audio_to_text(audio_data,audio['sample_rate'])
29
 
30
  # Display the transcription
31
  st.write("Transcription:", transcription)
 
1
  import streamlit as st
2
  import numpy as np
3
  import io
4
+ import os
5
  import wave
6
  import requests
7
  from audio_to_text import audio_to_text
8
  from streamlit_mic_recorder import mic_recorder
9
 
10
+ # Get the directory of the current file
11
+ current_dir = os.path.dirname(os.path.abspath(__file__))
12
+
13
  # Initialize Streamlit app layout
14
  st.title("Microphone Input in Streamlit")
15
 
 
24
  # Check if audio is recorded
25
  if audio:
26
  st.audio(audio['bytes'], format='audio/wav')
27
+ audio_bytes = audio["bytes"]
28
+ # Save audio in WEBM format
29
+ with open("recorded_audio.webm", "wb") as webm_file:
30
+ webm_file.write(audio_bytes)
31
 
32
  # Convert audio to text
33
+ transcription = audio_to_text("recorded_audio.webm")
34
 
35
  # Display the transcription
36
  st.write("Transcription:", transcription)