import os

def geberateAudioPath(filepath,orifilepath):
    data_path = "/Users/tzld/Downloads/LJSpeech-1.1/wavs/"
    with open(filepath, 'w') as f:
        with open(orifilepath,'r') as f1:
            while True:
                content = f1.readline()
                if content =='':
                    break
                    # try:
                filename = content.split('|')[0].split('/')[-1]
                path = data_path+filename
                str = path + '|' + content.split('|')[1] + '|' + content.split('|')[2]
                f.write(str)
            # except:
            #     print(content)

if __name__ == '__main__':
    trainfilepath = './ljs_audiopaths_text_sid_train_filelist.txt'
    valfilepath = './ljs_audiopaths_text_sid_val_filelist.txt'
    targettrainfilepath = './ljs_audiopaths_text_sid_train_filelist_new.txt'
    targetvalfilepath = './ljs_audiopaths_text_sid_val_filelist_new.txt'
    geberateAudioPath(targettrainfilepath,trainfilepath)
    geberateAudioPath(targetvalfilepath,valfilepath)
#
#
# origin_tarin_data_df["ID"] = origin_tarin_data_df.apply(lambda s:data_path + s['ID'].split('/')[-1],axis=1)
# origin_val_data_df["ID"] = origin_tarin_data_df.apply(lambda s:data_path + s['ID'].split('/')[-1],axis=1)
#
# origin_tarin_data_df.to_csv("./ljs_audiopaths_text_sid_train_filelist_new.txt",sep="|",header=False,index=False)
# origin_val_data_df.to_csv("./ljs_audiopaths_text_sid_val_filelist_new.txt",sep="|",header=False,index=False)
