Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
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)
|