Skriller0208 commited on
Commit
426aa59
·
verified ·
1 Parent(s): fc115c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -14
app.py CHANGED
@@ -1,14 +1,29 @@
1
  import streamlit as st
2
  import time
 
3
  from whisper_processor import process_audio
4
 
5
  def process_audio_streamlit(audio_file, model_name, lang):
6
- start_time = time.time()
7
- result = process_audio(audio_file, model_name=model_name, lang=lang)
8
- end_time = time.time()
9
- elapsed_time = end_time - start_time
10
- st.write("Time taken:", elapsed_time, "seconds")
11
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  st.title("Audio Transcription")
14
 
@@ -20,13 +35,13 @@ model_name = st.selectbox("Select model", ["tiny", "base", "small", "medium", "l
20
  lang = st.selectbox("Select language", ["en", "hi", "fr", "de", "es", "it", "pt", "ru", "zh", "ja", "ko", "ar", "tr"])
21
 
22
  if uploaded_file is not None:
23
- # Save the uploaded file to a temporary location
24
- with open("temp.wav", "wb") as f:
25
- f.write(uploaded_file.read())
26
 
27
- # Process the audio file
28
- result = process_audio_streamlit("temp.wav", model_name, lang)
29
 
30
- # Display the transcription result
31
- st.write("Transcription:")
32
- st.text_area("", value=result, height=300)
 
1
  import streamlit as st
2
  import time
3
+ import soundfile as sf
4
  from whisper_processor import process_audio
5
 
6
  def process_audio_streamlit(audio_file, model_name, lang):
7
+ start_time = time.time()
8
+
9
+ # Read audio data
10
+ audio, sample_rate = sf.read(audio_file)
11
+
12
+ # Check if conversion is necessary
13
+ if sample_rate != 16000:
14
+ # Resample to 16kHz
15
+ audio = sf.resample(audio, sample_rate, 16000)
16
+
17
+ # Save the resampled audio (optional)
18
+ # sf.write("temp_resampled.wav", audio, 16000)
19
+
20
+ # Process the audio with Whisper
21
+ result = process_audio(audio, model_name=model_name, lang=lang)
22
+
23
+ end_time = time.time()
24
+ elapsed_time = end_time - start_time
25
+ st.write("Time taken:", elapsed_time, "seconds")
26
+ return result
27
 
28
  st.title("Audio Transcription")
29
 
 
35
  lang = st.selectbox("Select language", ["en", "hi", "fr", "de", "es", "it", "pt", "ru", "zh", "ja", "ko", "ar", "tr"])
36
 
37
  if uploaded_file is not None:
38
+ # Save the uploaded file to a temporary location
39
+ with open("temp.wav", "wb") as f:
40
+ f.write(uploaded_file.read())
41
 
42
+ # Process the audio file
43
+ result = process_audio_streamlit("temp.wav", model_name, lang)
44
 
45
+ # Display the transcription result
46
+ st.write("Transcription:")
47
+ st.text_area("", value=result, height=300)