Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,6 +111,16 @@ async def procesar_fragmento(chunk, texto_tts, voz_seleccionada, start_time):
|
|
| 111 |
audio_original = chunk.audio
|
| 112 |
duracion_chunk = chunk.duration
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
audio_final = await procesar_audio(
|
| 115 |
texto_tts,
|
| 116 |
voz_seleccionada,
|
|
@@ -118,26 +128,20 @@ async def procesar_fragmento(chunk, texto_tts, voz_seleccionada, start_time):
|
|
| 118 |
audio_original
|
| 119 |
)
|
| 120 |
|
| 121 |
-
segment_duration = 18
|
| 122 |
-
overlap = 2
|
| 123 |
-
total_segments = int((duracion_chunk - overlap) // (segment_duration - overlap)) + 1
|
| 124 |
-
|
| 125 |
segments = []
|
| 126 |
glitch_clips = []
|
| 127 |
glitch_sound = AudioFileClip(GLITCH_SOUND).volumex(0.5)
|
| 128 |
|
| 129 |
current_time = 0
|
| 130 |
-
|
| 131 |
-
# Calcular tiempo final del segmento
|
| 132 |
end_time = current_time + segment_duration
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
# Extraer segmento completo
|
| 137 |
full_segment = chunk.subclip(current_time, end_time)
|
| 138 |
|
| 139 |
-
|
| 140 |
-
if i > 0 and full_segment.duration >= 0.5: # ← **Validación añadida**
|
| 141 |
glitch_part = full_segment.subclip(0, 0.5)
|
| 142 |
glitch_part = aplicar_glitch(glitch_part)
|
| 143 |
processed_segment = concatenate_videoclips([
|
|
@@ -151,7 +155,7 @@ async def procesar_fragmento(chunk, texto_tts, voz_seleccionada, start_time):
|
|
| 151 |
processed_segment = full_segment
|
| 152 |
|
| 153 |
segments.append(processed_segment)
|
| 154 |
-
current_time += (segment_duration - overlap)
|
| 155 |
|
| 156 |
video_chunk = concatenate_videoclips(segments, method="compose")
|
| 157 |
video_chunk = video_chunk.set_audio(audio_final)
|
|
@@ -174,7 +178,7 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
| 174 |
video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
|
| 175 |
total_duration = video_original.duration
|
| 176 |
|
| 177 |
-
# Dividir en chunks
|
| 178 |
chunks = []
|
| 179 |
for start in range(0, int(total_duration), CHUNK_SIZE):
|
| 180 |
end = min(start + CHUNK_SIZE, total_duration)
|
|
|
|
| 111 |
audio_original = chunk.audio
|
| 112 |
duracion_chunk = chunk.duration
|
| 113 |
|
| 114 |
+
# Si el chunk es demasiado corto, devolver sin procesar
|
| 115 |
+
if duracion_chunk <= 18:
|
| 116 |
+
audio_final = await procesar_audio(
|
| 117 |
+
texto_tts,
|
| 118 |
+
voz_seleccionada,
|
| 119 |
+
duracion_chunk,
|
| 120 |
+
audio_original
|
| 121 |
+
)
|
| 122 |
+
return chunk.set_audio(audio_final)
|
| 123 |
+
|
| 124 |
audio_final = await procesar_audio(
|
| 125 |
texto_tts,
|
| 126 |
voz_seleccionada,
|
|
|
|
| 128 |
audio_original
|
| 129 |
)
|
| 130 |
|
| 131 |
+
segment_duration = 18
|
| 132 |
+
overlap = 2
|
|
|
|
|
|
|
| 133 |
segments = []
|
| 134 |
glitch_clips = []
|
| 135 |
glitch_sound = AudioFileClip(GLITCH_SOUND).volumex(0.5)
|
| 136 |
|
| 137 |
current_time = 0
|
| 138 |
+
while current_time < duracion_chunk:
|
|
|
|
| 139 |
end_time = current_time + segment_duration
|
| 140 |
+
end_time = min(end_time, duracion_chunk)
|
| 141 |
+
|
|
|
|
|
|
|
| 142 |
full_segment = chunk.subclip(current_time, end_time)
|
| 143 |
|
| 144 |
+
if current_time > 0 and full_segment.duration >= 0.5:
|
|
|
|
| 145 |
glitch_part = full_segment.subclip(0, 0.5)
|
| 146 |
glitch_part = aplicar_glitch(glitch_part)
|
| 147 |
processed_segment = concatenate_videoclips([
|
|
|
|
| 155 |
processed_segment = full_segment
|
| 156 |
|
| 157 |
segments.append(processed_segment)
|
| 158 |
+
current_time += (segment_duration - overlap)
|
| 159 |
|
| 160 |
video_chunk = concatenate_videoclips(segments, method="compose")
|
| 161 |
video_chunk = video_chunk.set_audio(audio_final)
|
|
|
|
| 178 |
video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
|
| 179 |
total_duration = video_original.duration
|
| 180 |
|
| 181 |
+
# Dividir en chunks
|
| 182 |
chunks = []
|
| 183 |
for start in range(0, int(total_duration), CHUNK_SIZE):
|
| 184 |
end = min(start + CHUNK_SIZE, total_duration)
|