Skip to content

Instantly share code, notes, and snippets.

@dansuh17
Created December 4, 2019 17:47
Show Gist options
  • Save dansuh17/fa04843cbb4140d42c47ef44e15964e9 to your computer and use it in GitHub Desktop.
Save dansuh17/fa04843cbb4140d42c47ef44e15964e9 to your computer and use it in GitHub Desktop.

Revisions

  1. dansuh17 revised this gist Dec 4, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions wav_reformat.py
    Original file line number Diff line number Diff line change
    @@ -17,5 +17,4 @@
    dst_name = f'{TO_DIR}_{i}.wav'
    dst_path = os.path.join(ROOT, TO_DIR, dst_name)

    wavfile.write(dst_path, rate=SAMPLE_RATE, data=audio_data)

    wavfile.write(dst_path, rate=SAMPLE_RATE, data=audio_data)
  2. dansuh17 created this gist Dec 4, 2019.
    21 changes: 21 additions & 0 deletions wav_reformat.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import librosa
    import os
    from scipy.io import wavfile

    ROOT = '.'
    DIR = 'src' # source directory
    TO_DIR = 'dst' # destination directory
    SAMPLE_RATE = 16000

    for i, fname in enumerate(os.listdir(os.path.join(ROOT, DIR))):
    base, ext = os.path.splitext(fname)

    fpath = os.path.join(ROOT, DIR, fname)
    audio_data, _ = librosa.load(fpath, sr=SAMPLE_RATE) # resample while loading

    # naming format: {dst_dir}_{index}.wav
    dst_name = f'{TO_DIR}_{i}.wav'
    dst_path = os.path.join(ROOT, TO_DIR, dst_name)

    wavfile.write(dst_path, rate=SAMPLE_RATE, data=audio_data)