Skip to content

Commit b95d8aa

Browse files
committed
Update transcribe_wav.py
1 parent 896e843 commit b95d8aa

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

scripts/transcribe_wav.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,17 @@ def transcribe_audio_parallel(file_path, model_name='medium', language='it'):
282282
print("Esecuzione trascrizione singola (audio corto o indivisibile)")
283283
return transcribe_podcast_with_progress(file_path, model_name, language, parallel=False)
284284

285-
print(f"Trascrizione parallela di {len(chunks)} chunk...")
285+
print(f"⚡ Divisione audio in {len(chunks)} chunk per elaborazione parallela...")
286286

287287
start_time = time.time()
288288

289289
try:
290290
# Crea barra di progresso per la trascrizione parallela
291-
with tqdm(total=100, desc="Progresso parallelo", unit="%", ncols=80) as pbar:
291+
with tqdm(total=100,
292+
desc="🚀 Elaborazione Parallela",
293+
unit="%",
294+
ncols=100,
295+
bar_format='{l_bar}{bar}| {n:.1f}/{total:.1f}% [{elapsed}<{remaining}, {rate:.2f}%/s]') as pbar:
292296

293297
# Avvia trascrizione parallela dei chunk
294298
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
@@ -307,10 +311,15 @@ def update_progress():
307311
estimated_progress = min(95, (elapsed / (audio_duration * processing_ratio / 2)) * 100)
308312

309313
if estimated_progress >= pbar.n:
314+
# Calcola velocità e tempo rimanente stimato
315+
speed = estimated_progress / elapsed if elapsed > 0 else 0
316+
remaining = (100 - estimated_progress) / speed if speed > 0 else 0
317+
310318
pbar.update(estimated_progress - pbar.n)
311319
pbar.set_postfix({
312-
"Elaborazione": f"{estimated_progress:.1f}%",
313-
"Durata": f"{audio_duration:.1f}s"
320+
"Audio": f"{audio_duration:.0f}s",
321+
"Velocità": f"{speed:.1f}%/s",
322+
"ETA": f"{remaining:.0f}s"
314323
})
315324

316325
time.sleep(0.5) # Aggiorna ogni 0.5 secondi
@@ -327,7 +336,7 @@ def update_progress():
327336
full_transcription = chunk1_text.strip() + " " + chunk2_text.strip()
328337

329338
elapsed = time.time() - start_time
330-
print(f"Trascrizione parallela completata in {elapsed:.1f} secondi")
339+
print(f"Trascrizione parallela completata in {elapsed:.1f} secondi")
331340

332341
# Pulisce i chunk se sono stati creati
333342
for chunk in chunks:
@@ -435,8 +444,12 @@ def transcribe_podcast_with_progress(file_path, model_name='medium', language='i
435444
# Altrimenti, trascrizione singola tradizionale
436445
start_time = time.time()
437446

438-
# Barra di progresso basata su chunk completati
439-
with tqdm(total=100, desc="Progresso", unit="%", ncols=80) as pbar:
447+
# Barra di progresso per la trascrizione singola
448+
with tqdm(total=100,
449+
desc="🎵 Trascrizione Audio",
450+
unit="%",
451+
ncols=100,
452+
bar_format='{l_bar}{bar}| {n:.1f}/{total:.1f}% [{elapsed}<{remaining}, {rate:.2f}%/s]') as pbar:
440453
# Avvia la trascrizione con soppressione del warning FP16
441454
with warnings.catch_warnings():
442455
warnings.filterwarnings("ignore", message="FP16 is not supported on CPU; using FP32 instead")
@@ -455,10 +468,15 @@ def update_progress():
455468
estimated_progress = min(95, (elapsed / (audio_duration * processing_ratio)) * 100)
456469

457470
if estimated_progress >= pbar.n:
471+
# Calcola velocità e tempo rimanente stimato
472+
speed = estimated_progress / elapsed if elapsed > 0 else 0
473+
remaining = (100 - estimated_progress) / speed if speed > 0 else 0
474+
458475
pbar.update(estimated_progress - pbar.n)
459476
pbar.set_postfix({
460-
"Elaborazione": f"{estimated_progress:.1f}%",
461-
"Durata": f"{audio_duration:.1f}s"
477+
"Audio": f"{audio_duration:.0f}s",
478+
"Velocità": f"{speed:.1f}%/s",
479+
"ETA": f"{remaining:.0f}s"
462480
})
463481

464482
time.sleep(0.5) # Aggiorna ogni 0.5 secondi
@@ -536,7 +554,11 @@ def main(podcast_dir, model_name='medium', language='it', parallel=False):
536554
start_time = time.time()
537555

538556
# Barra di progresso principale per tutti i file
539-
with tqdm(total=total_files, desc="File elaborati", unit="file", ncols=100) as main_pbar:
557+
with tqdm(total=total_files,
558+
desc="📁 Elaborazione File",
559+
unit="file",
560+
ncols=100,
561+
bar_format='{l_bar}{bar}| {n:.0f}/{total:.0f} [{elapsed}<{remaining}, {rate:.2f}file/s]') as main_pbar:
540562
for root, dirs, files in os.walk(podcast_dir):
541563
for file_name in files:
542564
file_path = os.path.join(root, file_name)
@@ -598,17 +620,17 @@ def main(podcast_dir, model_name='medium', language='it', parallel=False):
598620
# Aggiorna la barra di progresso
599621
main_pbar.update(1)
600622
main_pbar.set_postfix({
601-
"File": f"{file_elapsed:.1f}s",
623+
"Tempo/file": f"{file_elapsed:.1f}s",
602624
"ETA": eta_formatted,
603625
"Totale": format_time(elapsed_total)
604626
})
605627

606-
print(f"\n Completato: {file_name}")
607-
print(f" Salvato in: {output_path}")
608-
print(f" Tempo impiegato: {file_elapsed:.1f} secondi")
628+
print(f"\n Completato: {file_name}")
629+
print(f"💾 Salvato in: {output_path}")
630+
print(f"⏱️ Tempo impiegato: {file_elapsed:.1f} secondi")
609631

610632
except Exception as e:
611-
print(f"\n Errore durante la trascrizione di {file_name}: {e}")
633+
print(f"\n Errore durante la trascrizione di {file_name}: {e}")
612634
main_pbar.update(1)
613635
finally:
614636
# Pulisce il file WAV convertito se è stato creato
@@ -621,10 +643,10 @@ def main(podcast_dir, model_name='medium', language='it', parallel=False):
621643

622644
total_elapsed = time.time() - start_time
623645
print(f"\n🎉 Trascrizione completata!")
624-
print(f"File elaborati: {processed_files}/{total_files}")
625-
print(f"Tempo totale: {format_time(total_elapsed)}")
646+
print(f"📊 File elaborati: {processed_files}/{total_files}")
647+
print(f"⏱️ Tempo totale: {format_time(total_elapsed)}")
626648
if processed_files > 0:
627-
print(f"Tempo medio per file: {total_elapsed/processed_files:.1f} secondi")
649+
print(f"📈 Tempo medio per file: {total_elapsed/processed_files:.1f} secondi")
628650

629651
if __name__ == "__main__":
630652
# Verifica che Python 3.10 sia utilizzato

0 commit comments

Comments
 (0)