workin < 60s

This commit is contained in:
Christian Rute 2025-01-16 18:27:51 +01:00
parent 19145ca1a4
commit 13c78c882f

11
app.py
View File

@ -54,7 +54,6 @@ def stop_recording():
global is_recording, recorded_audio, start_time
if not is_recording:
return "Not recording!"
sd.stop()
is_recording = False
elapsed_time = time.time() - start_time # Calculate elapsed time
print(f"Recording stopped. Duration: {elapsed_time:.2f} seconds.")
@ -99,19 +98,25 @@ def transcribe_audio():
chunk_filename = f"chunk_{i}.wav"
chunk.export(chunk_filename, format="wav")
print(f"Transcribing chunk {i + 1}/{len(chunks)}...")
# Transcribe the chunk
result = pipe(chunk_filename)
transcription.append(result["text"])
# Clean up temporary chunk file
os.remove(chunk_filename)
# Stream intermediate transcription
yield f"{' '.join(transcription)}"
print("Transcription complete.")
return " ".join(transcription)
yield f"{' '.join(transcription)}"
else:
print(f"Audio is short enough ({duration:.2f} seconds). Transcribing directly...")
result = pipe(FILENAME)
print("Transcription complete.")
return result["text"]
yield f"{result['text']}"
# Gradio Interface