Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,25 +21,34 @@ def transcribe_audio(audio_file):
|
|
21 |
# Split the audio into chunks
|
22 |
chunks = split_audio(audio_file)
|
23 |
|
24 |
-
# Transcribe each chunk
|
25 |
transcriptions = []
|
|
|
|
|
26 |
for chunk in chunks:
|
27 |
-
|
|
|
28 |
transcriptions.append(result["text"])
|
|
|
29 |
os.remove(chunk) # Clean up chunk files
|
30 |
|
31 |
# Combine all transcriptions into one
|
32 |
full_transcription = " ".join(transcriptions)
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Define the Gradio interface
|
36 |
iface = gr.Interface(
|
37 |
fn=transcribe_audio,
|
38 |
inputs=gr.Audio(type="filepath", label="Upload Audio File"),
|
39 |
-
outputs=gr.Textbox(label="Transcription"),
|
40 |
-
title="
|
41 |
-
description="Upload an audio file, and the system will automatically detect the language and transcribe it
|
42 |
)
|
43 |
|
44 |
# Launch the Gradio interface
|
45 |
-
iface.launch(
|
|
|
21 |
# Split the audio into chunks
|
22 |
chunks = split_audio(audio_file)
|
23 |
|
24 |
+
# Transcribe each chunk and collect results
|
25 |
transcriptions = []
|
26 |
+
detected_languages = set()
|
27 |
+
|
28 |
for chunk in chunks:
|
29 |
+
# Enable language detection and transcription
|
30 |
+
result = model(chunk, return_timestamps=False, generate_kwargs={"task": "transcribe"})
|
31 |
transcriptions.append(result["text"])
|
32 |
+
detected_languages.add(result.get("language", "unknown")) # Extract detected language
|
33 |
os.remove(chunk) # Clean up chunk files
|
34 |
|
35 |
# Combine all transcriptions into one
|
36 |
full_transcription = " ".join(transcriptions)
|
37 |
+
|
38 |
+
# Get the detected language (use the first detected language if multiple are found)
|
39 |
+
detected_language = detected_languages.pop() if detected_languages else "unknown"
|
40 |
+
|
41 |
+
# Return transcription and detected language
|
42 |
+
return f"Detected Language: {detected_language}\n\nTranscription:\n{full_transcription}"
|
43 |
|
44 |
# Define the Gradio interface
|
45 |
iface = gr.Interface(
|
46 |
fn=transcribe_audio,
|
47 |
inputs=gr.Audio(type="filepath", label="Upload Audio File"),
|
48 |
+
outputs=gr.Textbox(label="Transcription and Detected Language"),
|
49 |
+
title="Audio Transcription with Automatic Language Detection",
|
50 |
+
description="Upload an audio file, and the system will automatically detect the language and transcribe it."
|
51 |
)
|
52 |
|
53 |
# Launch the Gradio interface
|
54 |
+
iface.launch()
|