preprocess.py
def wav_to_mcep_file(dataset: str, sr=16000, ispad: bool = False, processed_filepath: str = './data/processed'):
    '''convert wavs to mcep feature using image repr'''
    # if no processed_filepath, create it ,or delete all npz files
    if not os.path.exists(processed_filepath):
        os.makedirs(processed_filepath)
    else:
        filelist = glob.glob(os.path.join(processed_filepath, "*.npy"))
        for f in filelist:
            os.remove(f)

    allwavs_cnt = len(glob.glob(f'{dataset}/*/*.wav'))
    # allwavs_cnt = allwavs_cnt//4*3 * 12+200 #about this number not precise
    print(f'Total {allwavs_cnt} audio files!')

    d = load_wavs(dataset, sr)
    cnt = 1  #

    for one_speaker in d.keys():
        for audio_name, audio_wav in d[one_speaker].items():
            # cal source audio feature
            audio_mcep_dict = cal_mcep(
                audio_wav, fs=sr, ispad=ispad, frame_period=0.005, dim=FEATURE_DIM)
            newname = f'{one_speaker}-{audio_name}'

            # save the dict as npz
            file_path_z = f'{processed_filepath}/{newname}'
            print(f'save file: {file_path_z}')
            np.savez(file_path_z, audio_mcep_dict)

            # save every  36*FRAMES blocks
            print(f'audio mcep shape {audio_mcep_dict["coded_sp"].shape}')

            # TODO step may be FRAMES//2
            for start_idx in range(0, audio_mcep_dict["coded_sp"].shape[1] - FRAMES + 1, FRAMES):
                one_audio_seg = audio_mcep_dict["coded_sp"][:,
                                                            start_idx:start_idx + FRAMES]

                if one_audio_seg.shape[1] == FRAMES:

                    temp_name = f'{newname}_{start_idx}'
                    filePath = f'{processed_filepath}/{temp_name}'

                    print(f'[{cnt}:{allwavs_cnt}]svaing file: {filePath}.npy')
                    np.save(filePath, one_audio_seg)
            cnt += 1
convert wavs to mcep feature using image repr
convert wavs to mcep feature using image repr
convert wavs to mcep feature using image repr
def wav_to_mcep_file(dataset: str, sr=16000, ispad: bool = False, processed_filepath: str = './data/processed'):
    if not os.path.exists(processed_filepath):
        os.makedirs(processed_filepath)
    else:
        filelist = glob.glob(os.path.join(processed_filepath, "*.npy"))
        for f in filelist:
            os.remove(f)
    allwavs_cnt = len(glob.glob(f'{dataset}/*/*.wav'))
    print(f'Total {allwavs_cnt} audio files!')
    d = load_wavs(dataset, sr)
    cnt = 1  
    for one_speaker in d.keys():
        for audio_name, audio_wav in d[one_speaker].items():
             cal source audio feature
            audio_mcep_dict = cal_mcep(
                audio_wav, fs=sr, ispad=ispad, frame_period=0.005, dim=FEATURE_DIM)
            newname = f'{one_speaker}-{audio_name}'
             save the dict as npz
            file_path_z = f'{processed_filepath}/{newname}'
            print(f'save file: {file_path_z}')
            np.savez(file_path_z, audio_mcep_dict)
             save every  36*FRAMES blocks
            print(f'audio mcep shape {audio_mcep_dict["coded_sp"].shape}')
             TODO step may be FRAMES//2
            for start_idx in range(0, audio_mcep_dict["coded_sp"].shape[1] - FRAMES + 1, FRAMES):
                one_audio_seg = audio_mcep_dict["coded_sp"][:,
                                                            start_idx:start_idx + FRAMES]
                if one_audio_seg.shape[1] == FRAMES:
                    temp_name = f'{newname}_{start_idx}'
                    filePath = f'{processed_filepath}/{temp_name}'
                    print(f'[{cnt}:{allwavs_cnt}]svaing file: {filePath}.npy')
                    np.save(filePath, one_audio_seg)
            cnt += 1
def wav_to_mcep_file ( dataset : str , sr = 16000 , ispad : bool = False , processed_filepath : str = './data/processed' ) : if not os . path . exists ( processed_filepath ) : os . makedirs ( processed_filepath ) else : filelist = glob . glob ( os . path . join ( processed_filepath , "*.npy" ) ) for f in filelist : os . remove ( f ) allwavs_cnt = len ( glob . glob ( f'{dataset}/*/*.wav' ) ) print ( f'Total {allwavs_cnt} audio files!' ) d = load_wavs ( dataset , sr ) cnt = 1 for one_speaker in d . keys ( ) : for audio_name , audio_wav in d [ one_speaker ] . items ( ) : audio_mcep_dict = cal_mcep ( audio_wav , fs = sr , ispad = ispad , frame_period = 0.005 , dim = FEATURE_DIM ) newname = f'{one_speaker}-{audio_name}' file_path_z = f'{processed_filepath}/{newname}' print ( f'save file: {file_path_z}' ) np . savez ( file_path_z , audio_mcep_dict ) print ( f'audio mcep shape {audio_mcep_dict["coded_sp"].shape}' ) for start_idx in range ( 0 , audio_mcep_dict [ "coded_sp" ] . shape [ 1 ] - FRAMES + 1 , FRAMES ) : one_audio_seg = audio_mcep_dict [ "coded_sp" ] [ : , start_idx : start_idx + FRAMES ] if one_audio_seg . shape [ 1 ] == FRAMES : temp_name = f'{newname}_{start_idx}' filePath = f'{processed_filepath}/{temp_name}' print ( f'[{cnt}:{allwavs_cnt}]svaing file: {filePath}.npy' ) np . save ( filePath , one_audio_seg ) cnt += 1
convert wavs to mcep feature using image repr
convert wavs to mcep feature using image repr
'''convert wavs to mcep feature using image repr''' # if no processed_filepath, create it ,or delete all npz files # allwavs_cnt = allwavs_cnt//4*3 * 12+200 #about this number not precise # # cal source audio feature # save the dict as npz # save every  36*FRAMES blocks # TODO step may be FRAMES//2
dataset
str
sr
ispad
bool
processed_filepath
str