in infra-as-code/modules/ingest-pipeline/cf-audio-redaction/audio_redaction.py [0:0]
def redact_audio_file(self, redaction_intervals, tmp_audio_file):
"""Redacts the audio file using ffmpeg."""
try:
volume_filters = []
for element in redaction_intervals:
filter_str = f"volume=enable='between(t,{element['startOffset'].replace("s", "")},{element['endOffset'].replace("s", "")})':volume=0"
volume_filters.append(filter_str)
filter_graph = ",".join(volume_filters)
if len(volume_filters) == 0:
return
with tempfile.NamedTemporaryFile(suffix='.flac', delete=False) as temp_output:
temp_output_path = temp_output.name
(
ffmpeg
.input(f"/tmp/{tmp_audio_file}")
.output(temp_output_path, af=filter_graph)
.overwrite_output()
.run()
)
# Replace the original file with the temporary file
os.replace(temp_output_path, f"/tmp/{tmp_audio_file}")
except ffmpeg.Error as e:
print(f"Error al procesar el audio: {e}")
except Exception as e:
print(f"Error redacting audio file ffmpeg: {e}")
return ''