Spaces:
Sleeping
Sleeping
Added language
Browse files
app.py
CHANGED
@@ -5,14 +5,14 @@ import os
|
|
5 |
# Load the Whisper model
|
6 |
model = whisper.load_model("base") # You can choose "tiny", "small", "medium", or "large"
|
7 |
|
8 |
-
def transcribe_audio(audio_file):
|
9 |
# Save the uploaded audio file to a temporary location
|
10 |
temp_file_path = "temp_audio.wav"
|
11 |
with open(temp_file_path, "wb") as f:
|
12 |
f.write(audio_file.getbuffer())
|
13 |
|
14 |
# Transcribe the audio
|
15 |
-
|
16 |
os.remove(temp_file_path) # Clean up the temporary file
|
17 |
return result['text']
|
18 |
|
@@ -22,6 +22,9 @@ st.write("Upload an audio file to transcribe it using Whisper.")
|
|
22 |
|
23 |
# File uploader for audio files
|
24 |
audio_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a"])
|
|
|
|
|
|
|
25 |
|
26 |
if audio_file is not None:
|
27 |
st.audio(audio_file, format='audio/wav')
|
@@ -29,6 +32,6 @@ if audio_file is not None:
|
|
29 |
# Transcribe the audio when the button is clicked
|
30 |
if st.button("Transcribe"):
|
31 |
with st.spinner("Transcribing..."):
|
32 |
-
transcription = transcribe_audio(audio_file)
|
33 |
st.success("Transcription complete!")
|
34 |
st.text_area("Transcription:", transcription, height=300)
|
|
|
5 |
# Load the Whisper model
|
6 |
model = whisper.load_model("base") # You can choose "tiny", "small", "medium", or "large"
|
7 |
|
8 |
+
def transcribe_audio(audio_file, language):
|
9 |
# Save the uploaded audio file to a temporary location
|
10 |
temp_file_path = "temp_audio.wav"
|
11 |
with open(temp_file_path, "wb") as f:
|
12 |
f.write(audio_file.getbuffer())
|
13 |
|
14 |
# Transcribe the audio
|
15 |
+
result = model.transcribe(temp_file_path, language=language)
|
16 |
os.remove(temp_file_path) # Clean up the temporary file
|
17 |
return result['text']
|
18 |
|
|
|
22 |
|
23 |
# File uploader for audio files
|
24 |
audio_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a"])
|
25 |
+
# Language selection
|
26 |
+
language = st.selectbox("Select Language", options=["en", "es", "fr", "de", "it", "zh"])
|
27 |
+
|
28 |
|
29 |
if audio_file is not None:
|
30 |
st.audio(audio_file, format='audio/wav')
|
|
|
32 |
# Transcribe the audio when the button is clicked
|
33 |
if st.button("Transcribe"):
|
34 |
with st.spinner("Transcribing..."):
|
35 |
+
transcription = transcribe_audio(audio_file, language)
|
36 |
st.success("Transcription complete!")
|
37 |
st.text_area("Transcription:", transcription, height=300)
|