Trim audio in prodigy to remove dead air/silence

Good day,

Is it possible to edit audios in prodigy? We have audio files that have lots of dead air/silence in between dictations. We want to trim the audio files so it is easier for us to review. Thanks.

hi @joebuckle,

This seems a lot like your previous post:

I think Vincent is right that it's best to write a custom script to try to remove them, perhaps from a folder with your input files and removing silence into a second output folder.

Perhaps try using pydub split_from_silence.

Here's some code you could try. You may need to modify for different sound files (e.g., this only uses .mp3, but this could be a start.

import os
from pydub import AudioSegment
from pydub.silence import split_on_silence
from pydub.playback import play
import typer

app = typer.Typer()

def trim_silence(audio, silence_thresh=-50.0):
    chunks = split_on_silence(audio, silence_thresh=silence_thresh)
    return sum(chunks, AudioSegment.silent(duration=0))

def trim_mp3(input_file, output_folder):
    audio = AudioSegment.from_mp3(input_file)
    trimmed_audio = trim_silence(audio)
    output_file = os.path.join(output_folder, os.path.basename(input_file))
    trimmed_audio.export(output_file, format="mp3")
    print(f"Trimmed: {input_file} -> {output_file}")

def main(input_folder: str, output_folder: str):
    if not os.path.exists(output_folder):

    for root, _, files in os.walk(input_folder):
        for file in files:
            if file.endswith(".mp3"):
                input_file = os.path.join(root, file)
                trim_mp3(input_file, output_folder)

if __name__ == "__main__":

Since it's using typer, you could run this from the CLI:

python main /path/to/input_folder /path/to/output_folder

Hope this helps!

Thank you :slight_smile: