Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
from pydub import AudioSegment
|
4 |
import os
|
|
|
5 |
|
6 |
-
# Load
|
7 |
-
model =
|
8 |
|
9 |
def split_audio(filepath, chunk_length_ms=30000):
|
10 |
"""Split audio into chunks of `chunk_length_ms` milliseconds."""
|
@@ -26,12 +26,12 @@ def transcribe_audio(audio_file):
|
|
26 |
detected_language = None
|
27 |
|
28 |
for chunk in chunks:
|
29 |
-
#
|
30 |
-
result = model(chunk,
|
31 |
transcriptions.append(result["text"])
|
32 |
|
33 |
-
# Extract detected language from the result
|
34 |
-
if "language" in result:
|
35 |
detected_language = result["language"]
|
36 |
|
37 |
os.remove(chunk) # Clean up chunk files
|
|
|
1 |
import gradio as gr
|
2 |
+
import whisper
|
|
|
3 |
import os
|
4 |
+
from pydub import AudioSegment
|
5 |
|
6 |
+
# Load the Whisper model
|
7 |
+
model = whisper.load_model("base") # Use "base" for faster processing
|
8 |
|
9 |
def split_audio(filepath, chunk_length_ms=30000):
|
10 |
"""Split audio into chunks of `chunk_length_ms` milliseconds."""
|
|
|
26 |
detected_language = None
|
27 |
|
28 |
for chunk in chunks:
|
29 |
+
# Transcribe the chunk and detect the language
|
30 |
+
result = model.transcribe(chunk, fp16=False) # Set fp16=False if not using GPU
|
31 |
transcriptions.append(result["text"])
|
32 |
|
33 |
+
# Extract detected language from the result
|
34 |
+
if detected_language is None and "language" in result:
|
35 |
detected_language = result["language"]
|
36 |
|
37 |
os.remove(chunk) # Clean up chunk files
|