workin < 60s
This commit is contained in:
parent
19145ca1a4
commit
13c78c882f
11
app.py
11
app.py
@ -54,7 +54,6 @@ def stop_recording():
|
|||||||
global is_recording, recorded_audio, start_time
|
global is_recording, recorded_audio, start_time
|
||||||
if not is_recording:
|
if not is_recording:
|
||||||
return "Not recording!"
|
return "Not recording!"
|
||||||
sd.stop()
|
|
||||||
is_recording = False
|
is_recording = False
|
||||||
elapsed_time = time.time() - start_time # Calculate elapsed time
|
elapsed_time = time.time() - start_time # Calculate elapsed time
|
||||||
print(f"Recording stopped. Duration: {elapsed_time:.2f} seconds.")
|
print(f"Recording stopped. Duration: {elapsed_time:.2f} seconds.")
|
||||||
@ -99,19 +98,25 @@ def transcribe_audio():
|
|||||||
chunk_filename = f"chunk_{i}.wav"
|
chunk_filename = f"chunk_{i}.wav"
|
||||||
chunk.export(chunk_filename, format="wav")
|
chunk.export(chunk_filename, format="wav")
|
||||||
print(f"Transcribing chunk {i + 1}/{len(chunks)}...")
|
print(f"Transcribing chunk {i + 1}/{len(chunks)}...")
|
||||||
|
|
||||||
|
# Transcribe the chunk
|
||||||
result = pipe(chunk_filename)
|
result = pipe(chunk_filename)
|
||||||
transcription.append(result["text"])
|
transcription.append(result["text"])
|
||||||
|
|
||||||
# Clean up temporary chunk file
|
# Clean up temporary chunk file
|
||||||
os.remove(chunk_filename)
|
os.remove(chunk_filename)
|
||||||
|
|
||||||
|
# Stream intermediate transcription
|
||||||
|
yield f"{' '.join(transcription)}"
|
||||||
|
|
||||||
print("Transcription complete.")
|
print("Transcription complete.")
|
||||||
return " ".join(transcription)
|
yield f"{' '.join(transcription)}"
|
||||||
else:
|
else:
|
||||||
print(f"Audio is short enough ({duration:.2f} seconds). Transcribing directly...")
|
print(f"Audio is short enough ({duration:.2f} seconds). Transcribing directly...")
|
||||||
result = pipe(FILENAME)
|
result = pipe(FILENAME)
|
||||||
print("Transcription complete.")
|
print("Transcription complete.")
|
||||||
return result["text"]
|
yield f"{result['text']}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Gradio Interface
|
# Gradio Interface
|
||||||
|
Loading…
Reference in New Issue
Block a user