def METHOD_NAME(folder_in, folder_out, sr=16384):
    """
    Detects utterances in the input audio files and creates 1-sec 16khz
    mono .wav files as needed for KWS dataset
    """
    # create output folder
    try:
        os.mkdir(folder_out)
    except OSError as e:
        if e.errno == errno.EEXIST:
            pass
        else:
            raise
        print(f'{folder_out} already exists. overwrite!')
    for (dirpath, _, filenames) in os.walk(folder_in):
        for filename in sorted(filenames):
            file_cnt = 0
            i = 0
            if filename.endswith('.wav') or filename.endswith('.ogg'):
                fname = os.path.join(dirpath, filename)
                data, samplerate = librosa.load(fname, sr=sr)
                print(f'\rProcessing {fname}, sample rate={samplerate}', end="   ")
                mx = np.amax(abs(data))
                data = data/mx
                chunk_start = 0
                segment_len = 98*128
                while True:
                    if chunk_start + segment_len > len(data):
                        break
                    chunk = data[chunk_start: chunk_start+128]
                    avg = 1000*np.average(abs(chunk))
                    # visualize:
                    # bars = "=" * int(100 * avg/100)
                    # peak = avg * 100
                    # print("%04d %05d %s" % (i, peak, bars))
                    i += 128
                    if avg > THRESHOLD and chunk_start >= 30*128:
                        frame = data[chunk_start - 30*128:chunk_start + 98*128]
                        outfile = os.path.join(folder_out, filename[:-4] + str(file_cnt) + ".wav")
                        sf.write(outfile, frame, sr)
                        file_cnt += 1
                        chunk_start += 98*128
                    else:
                        chunk_start += 128
            else:
                continue
    print('\r')