preprocess.py
def load_wavs(dataset: str, sr):
    '''
    data dict contains all audios file path
    resdict contains all wav files   
    '''
    data = {}
    with os.scandir(dataset) as it:
        for entry in it:
            if entry.is_dir():
                data[entry.name] = []
                # print(entry.name, entry.path)
                with os.scandir(entry.path) as it_f:
                    for onefile in it_f:
                        if onefile.is_file():
                            # print(onefile.path)
                            data[entry.name].append(onefile.path)
    print(f'loaded keys: {data.keys()}')
    # data like {TM1:[xx,xx,xxx,xxx]}
    resdict = {}

    cnt = 0
    for key, value in data.items():
        resdict[key] = {}

        for one_file in value:

            filename = os.path.normpath(one_file).split(os.sep)[-1].split('.')[0]  # like 100061
            newkey = f'{filename}'
            wav, _ = librosa.load(one_file, sr=sr, mono=True, dtype=np.float64)

            resdict[key][newkey] = wav
            # resdict[key].append(temp_dict) #like TM1:{100062:[xxxxx], .... }
            print('.', end='')
            cnt += 1

    print(f'\nTotal {cnt} aduio files!')
    return resdict

    data dict contains all audios file path
    resdict contains all wav files   
    
data dict contains all audios file path
resdict contains all wav files
data dict contains all audios file path resdict contains all wav files
def load_wavs(dataset: str, sr):
    data = {}
    with os.scandir(dataset) as it:
        for entry in it:
            if entry.is_dir():
                data[entry.name] = []
                with os.scandir(entry.path) as it_f:
                    for onefile in it_f:
                        if onefile.is_file():
                            data[entry.name].append(onefile.path)
    print(f'loaded keys: {data.keys()}')
    resdict = {}
    cnt = 0
    for key, value in data.items():
        resdict[key] = {}
        for one_file in value:
            filename = os.path.normpath(one_file).split(os.sep)[-1].split('.')[0]  
            newkey = f'{filename}'
            wav, _ = librosa.load(one_file, sr=sr, mono=True, dtype=np.float64)
            resdict[key][newkey] = wav
            print('.', end='')
            cnt += 1
    print(f'\nTotal {cnt} aduio files!')
    return resdict
def load_wavs ( dataset : str , sr ) : data = { } with os . scandir ( dataset ) as it : for entry in it : if entry . is_dir ( ) : data [ entry . name ] = [ ] with os . scandir ( entry . path ) as it_f : for onefile in it_f : if onefile . is_file ( ) : data [ entry . name ] . append ( onefile . path ) print ( f'loaded keys: {data.keys()}' ) resdict = { } cnt = 0 for key , value in data . items ( ) : resdict [ key ] = { } for one_file in value : filename = os . path . normpath ( one_file ) . split ( os . sep ) [ - 1 ] . split ( '.' ) [ 0 ] newkey = f'{filename}' wav , _ = librosa . load ( one_file , sr = sr , mono = True , dtype = np . float64 ) resdict [ key ] [ newkey ] = wav print ( '.' , end = '' ) cnt += 1 print ( f'\nTotal {cnt} aduio files!' ) return resdict
data dict contains all audios file path
resdict contains all wav files
data dict contains all audios file path resdict contains all wav files
'''
    data dict contains all audios file path
    resdict contains all wav files   
    ''' # print(entry.name, entry.path) # print(onefile.path) # data like {TM1:[xx,xx,xxx,xxx]} # like 100061 # resdict[key].append(temp_dict) #like TM1:{100062:[xxxxx], .... }
dataset
str
sr