File size: 1,358 Bytes
cf6ce9f b7c41f8 c945b9f c887c55 740442f a463449 9812b5d 740442f 9812b5d 740442f c887c55 c5424e8 c887c55 c5424e8 c887c55 c5424e8 3be443b c887c55 34fc453 c5424e8 34fc453 c5424e8 34fc453 c887c55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import os
import gradio
import replicate
from pydub import AudioSegment
# Aseg煤rate de que REPLICATE_API_TOKEN est茅 configurado en las variables de entorno
replicate_token = os.getenv("REPLICATE_API_TOKEN")
if not replicate_token:
raise ValueError("No se ha encontrado el token de API de Replicate.")
# Funci贸n para dividir el archivo de audio en segmentos de duraci贸n definida (en milisegundos)
def dividir_audio(audio_path, segment_duration_ms):
audio = AudioSegment.from_file(audio_path)
audio_length = len(audio)
segments = []
# Divide el audio en fragmentos de la duraci贸n especificada (5 minutos en milisegundos)
for i in range(0, audio_length, segment_duration_ms):
segment = audio[i:i + segment_duration_ms] # Cada fragmento de hasta 5 minutos
segment_path = f"segment_{i // (60 * 1000)}.wav" # Nombre del archivo con el 铆ndice del minuto
segment.export(segment_path, format="wav") # Exporta el fragmento como un archivo WAV
# Verifica el tama帽o del archivo y asegura que no supere el l铆mite de 10MB, ajusta si es necesario
if os.path.getsize(segment_path) > 10 * 1024 * 1024: # 10 MB
print(f"Warning: Segment {segment_path} exceeds 10MB, consider reducing segment duration.")
segments.append(segment_path)
return segments
|