(batch, audio_transform, mode)
return file, audio_feat, audio_len, text
Collects a batch, should be list of tuples (audio_path <str>, list of int token <list>) 
       e.g. [(file1,txt1),(file2,txt2),...]
Collects a batch, should be list of tuples (audio_path <str>, list of int token <list>) 
       e.g. [(file1,txt1),(file2,txt2),...]
Collects a batch should be list of tuples ( audio_path <str > list of int token <list > ) e . g . [ ( file1 txt1 ) ( file2 txt2 ) ... ]
def collect_audio_batch(batch, audio_transform, mode):
    '''Collects a batch, should be list of tuples (audio_path <str>, list of int token <list>) 
       e.g. [(file1,txt1),(file2,txt2),...] '''

    # Bucketed batch should be [[(file1,txt1),(file2,txt2),...]]
    if type(batch[0]) is not tuple:
        batch = batch[0]
    # Make sure that batch size is reasonable
    first_len = audio_transform(str(batch[0][0])).shape[0]
    if first_len > HALF_BATCHSIZE_AUDIO_LEN and mode == 'train':
        batch = batch[:len(batch)//2]

    # Read batch
    file, audio_feat, audio_len, text = [], [], [], []
    with torch.no_grad():
        for b in batch:
            file.append(str(b[0]).split('/')[-1].split('.')[0])
            feat = audio_transform(str(b[0]))
            audio_feat.append(feat)
            audio_len.append(len(feat))
            text.append(torch.LongTensor(b[1]))
    # Descending audio length within each batch
    audio_len, file, audio_feat, text = zip(*[(feat_len, f_name, feat, txt)
                                              for feat_len, f_name, feat, txt in sorted(zip(audio_len, file, audio_feat, text), reverse=True, key=lambda x:x[0])])
    # Zero-padding
    audio_feat = pad_sequence(audio_feat, batch_first=True)
    text = pad_sequence(text, batch_first=True)
    audio_len = torch.LongTensor(audio_len)

    return file, audio_feat, audio_len, text
def collect_audio_batch ( batch , audio_transform , mode ) : # Bucketed batch should be [[(file1,txt1),(file2,txt2),...]] if type ( batch [ 0 ] ) is not tuple : batch = batch [ 0 ] # Make sure that batch size is reasonable first_len = audio_transform ( str ( batch [ 0 ] [ 0 ] ) ) . shape [ 0 ] if first_len > HALF_BATCHSIZE_AUDIO_LEN and mode == 'train' : batch = batch [ : len ( batch ) // 2 ] # Read batch file , audio_feat , audio_len , text = [ ] , [ ] , [ ] , [ ] with torch . no_grad ( ) : for b in batch : file . append ( str ( b [ 0 ] ) . split ( '/' ) [ - 1 ] . split ( '.' ) [ 0 ] ) feat = audio_transform ( str ( b [ 0 ] ) ) audio_feat . append ( feat ) audio_len . append ( len ( feat ) ) text . append ( torch . LongTensor ( b [ 1 ] ) ) # Descending audio length within each batch audio_len , file , audio_feat , text = zip ( * [ ( feat_len , f_name , feat , txt ) for feat_len , f_name , feat , txt in sorted ( zip ( audio_len , file , audio_feat , text ) , reverse = True , key = lambda x : x [ 0 ] ) ] ) # Zero-padding audio_feat = pad_sequence ( audio_feat , batch_first = True ) text = pad_sequence ( text , batch_first = True ) audio_len = torch . LongTensor ( audio_len ) return file , audio_feat , audio_len , text