RXTIME commited on
Commit
9142bd9
·
verified ·
1 Parent(s): df07d48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -67,22 +67,31 @@ def replace_audio(video_path: str, new_audio_path: str) -> str:
67
  # Pipeline completo
68
  def process_video(video_file):
69
  try:
 
 
 
 
 
70
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
71
- temp_video.write(video_file.read())
72
  video_path = temp_video.name
73
 
 
74
  transcript = transcribe_audio(video_path)
75
  if "Erro" in transcript:
76
  return transcript
77
 
 
78
  translated_text = translate_text(transcript)
79
  if "Erro" in translated_text:
80
  return translated_text
81
 
 
82
  new_audio_path = synthesize_speech(translated_text)
83
  if "Erro" in new_audio_path:
84
  return new_audio_path
85
 
 
86
  output_video_path = replace_audio(video_path, new_audio_path)
87
  if "Erro" in output_video_path:
88
  return output_video_path
 
67
  # Pipeline completo
68
  def process_video(video_file):
69
  try:
70
+ # Verifique se o arquivo tem o método 'read' e é do tipo esperado
71
+ if not hasattr(video_file, 'read'):
72
+ return "Erro: O arquivo fornecido não é válido."
73
+
74
+ # Salve o arquivo temporariamente
75
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
76
+ temp_video.write(video_file.read()) # Lê o conteúdo do arquivo de entrada
77
  video_path = temp_video.name
78
 
79
+ # Passo 1: Transcrição do áudio
80
  transcript = transcribe_audio(video_path)
81
  if "Erro" in transcript:
82
  return transcript
83
 
84
+ # Passo 2: Tradução do texto
85
  translated_text = translate_text(transcript)
86
  if "Erro" in translated_text:
87
  return translated_text
88
 
89
+ # Passo 3: Síntese de fala em português
90
  new_audio_path = synthesize_speech(translated_text)
91
  if "Erro" in new_audio_path:
92
  return new_audio_path
93
 
94
+ # Passo 4: Substituição do áudio no vídeo
95
  output_video_path = replace_audio(video_path, new_audio_path)
96
  if "Erro" in output_video_path:
97
  return output_video_path