Fastai v2 audio

That was precisely the issue and I wish I had read about DownmixToMono and Resample. Although, I did read Resample in the augment file but got confused by the name and I thought it was about re-sampling tensors in a loaded batch, should have read the code.

I already mentioned the bash script I used but to make things more python-ish, I wrote the below method as a part of my pipeline. Adding below in case some needs the same


def convert_file(infile: Path, bitrate: int = 16000) -> None:

    """Convert one file to the bitrate provided in the arguments.

    This file does not return anything but raises exception if sox file fails.

    

    :param infile: Input file path to convert.

    :param bitrate: The desired bitrate.

    :raises: OSError, SubprocessError

    """

    infile = Path(infile)

    tempfile = infile.parent / '.temp.wav'

    # Call sox to convert the file.

    subprocess.run(['sox', str(infile), str(tempfile), 'rate', str(bitrate)], 

                    check=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)

    

    # Remove the tempfile and replace the infile with the modified bitrate.

    subprocess.run(['mv', str(tempfile), str(infile)], 

                    check=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)

def convert_all(input_dir: str, bitrate: int = 16000) -> None:

    """Converts all .wav files directly inside the folder to the desired bitrate.

    

    :param input_dir: Input directory with wav files to convert.

    :param bitrate: The desired bitrate.

    """

    for infile in Path(input_dir).glob('**/*.wav'):

        convert_file(infile, bitrate)

I’m happy to hear that you were busy helping mitigate the covid19 problem :slight_smile:. I’ll finish few things on my end and then jump-in to contribute to this library in my capacity. I must tell you that I only started working with audio data 4 days ago and found out about this library. So I’m limited in my ability to understand the details of signal processing methods.

1 Like