Taads commited on
Commit
af435d3
·
verified ·
1 Parent(s): c4ccb9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -26,18 +26,24 @@ def gerar_audio(texto, idioma, arquivo_voz):
26
  os.remove(os.path.join("audios", f))
27
 
28
  blocos = textwrap.wrap(texto, width=200)
 
29
  arquivos = []
 
30
 
31
  for idx, bloco in enumerate(blocos, start=1):
32
  nome = f"{idioma}_parte_{str(idx).zfill(3)}.wav"
33
  caminho = os.path.join("audios", nome)
 
34
  tts.tts_to_file(
35
  text=bloco,
36
  file_path=caminho,
37
  speaker_wav=arquivo_voz,
38
  language=idioma
39
  )
 
40
  arquivos.append(caminho)
 
 
41
 
42
  if not arquivos:
43
  return "Erro: nada gerado.", None
@@ -47,7 +53,8 @@ def gerar_audio(texto, idioma, arquivo_voz):
47
  for file in arquivos:
48
  zipf.write(file, arcname=os.path.basename(file))
49
 
50
- return f"{len(arquivos)} áudios gerados.", zip_path
 
51
 
52
  except Exception as e:
53
  return f"Ocorreu um erro: {str(e)}", None
 
26
  os.remove(os.path.join("audios", f))
27
 
28
  blocos = textwrap.wrap(texto, width=200)
29
+ total = len(blocos)
30
  arquivos = []
31
+ log_status = f"Iniciando geração de {total} partes...\n\n"
32
 
33
  for idx, bloco in enumerate(blocos, start=1):
34
  nome = f"{idioma}_parte_{str(idx).zfill(3)}.wav"
35
  caminho = os.path.join("audios", nome)
36
+
37
  tts.tts_to_file(
38
  text=bloco,
39
  file_path=caminho,
40
  speaker_wav=arquivo_voz,
41
  language=idioma
42
  )
43
+
44
  arquivos.append(caminho)
45
+ faltam = total - idx
46
+ log_status += f"✅ Parte {idx}/{total} gerada. Faltam {faltam}...\n"
47
 
48
  if not arquivos:
49
  return "Erro: nada gerado.", None
 
53
  for file in arquivos:
54
  zipf.write(file, arcname=os.path.basename(file))
55
 
56
+ log_status += f"\n🎉 Concluído! {len(arquivos)} áudios gerados."
57
+ return log_status, zip_path
58
 
59
  except Exception as e:
60
  return f"Ocorreu um erro: {str(e)}", None