pratikshahp commited on
Commit
bcc0290
·
verified ·
1 Parent(s): e63c494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -3,6 +3,7 @@ import torchaudio
3
  from torchaudio.transforms import Resample
4
  from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
5
  import streamlit as st
 
6
 
7
  def preprocess_audio(audio_bytes, sample_rate=16000):
8
  # Load audio and convert to mono if necessary
@@ -33,14 +34,15 @@ def transcribe_audio(audio_bytes):
33
 
34
  return translation
35
 
36
- st.title("Audio to Text Transcription")
37
 
38
- uploaded_file = st.file_uploader("Upload audio file", type=["wav"])
 
39
 
40
- if uploaded_file is not None:
41
- st.audio(uploaded_file, format="audio/wav")
 
42
 
43
- audio_bytes = uploaded_file.getvalue()
44
  transcription = transcribe_audio(audio_bytes)
45
 
46
  if transcription:
@@ -49,5 +51,6 @@ if uploaded_file is not None:
49
  else:
50
  st.write("Error: Failed to transcribe audio.")
51
  else:
52
- st.write("Please upload an audio file.")
 
53
 
 
3
  from torchaudio.transforms import Resample
4
  from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
5
  import streamlit as st
6
+ from streamlit_audio_recorder import st_audio_recorder
7
 
8
  def preprocess_audio(audio_bytes, sample_rate=16000):
9
  # Load audio and convert to mono if necessary
 
34
 
35
  return translation
36
 
37
+ st.title("Audio to Text Transcription with Recording")
38
 
39
+ # Use the st_audio_recorder widget to record audio
40
+ audio_bytes = st_audio_recorder(sample_rate=16000, codec="wav", show_playback_controls=True)
41
 
42
+ # Display the recorded audio
43
+ if audio_bytes:
44
+ st.audio(audio_bytes, format="audio/wav")
45
 
 
46
  transcription = transcribe_audio(audio_bytes)
47
 
48
  if transcription:
 
51
  else:
52
  st.write("Error: Failed to transcribe audio.")
53
  else:
54
+ st.write("Please record an audio.")
55
+
56