def get_class_other(tag_data): """ 音乐分类 :param tag_data: :return: """ print("其他-音乐分类中....") result = [0, 0, 0, 0, 0, 0, 0, 0] data = tag_data.iloc[:, 2:7] estimator = joblib.load("music_clf.pkl") for row in tqdm(data.itertuples()): song_id = str(getattr(row, 'song_id')) start_time = getattr(row, 'start_time') end_time = getattr(row, 'end_time') times = getattr(row, 'times') tag = getattr(row,'tag') if tag == 3: times = end_time/times elif tag == 4: times = times * 0.7 # 判断是否已存在于wav文件夹中 wav_file = "E:\\musiclib\\wav\\" + str(song_id) + ".wav" mp3_file = "E:\\musiclib\\mp3\\" + str(song_id) + ".mp3" predict_file = "E:\\musiclib\\predict\\" + str(song_id) + ".txt" mfcc_file = "E:\\musiclib\\mfcc\\" + str(song_id) + ".txt" if music_classify.judge_exist(predict_file) == True: y_predict = music_classify.Read_list_y(predict_file) result[y_predict[0]] += times continue if music_classify.judge_exist(mfcc_file) == True: x_predict = music_classify.Read_list_x(mfcc_file) y_predict = estimator.predict(x_predict) music_classify.Save_feature(y_predict,predict_file) result[y_predict[0]] += times continue if music_classify.judge_exist(wav_file) == False: if music_classify.judge_exist(mp3_file) == False: # 否-尝试进行下载 if crawl_song.download_song(mp3_file, song_id) == False: continue if music_classify.mp3_to_wav(mp3_file, wav_file) == False: continue else: if music_classify.mp3_to_wav(mp3_file, wav_file) == False: continue x_predict = [music_classify.get_mfcc_feature(wav_file)] y_predict = estimator.predict(x_predict) music_classify.Save_list(x_predict,mfcc_file) music_classify.Save_list(y_predict,predict_file) result[y_predict[0]] += times return result
def save_predict(song_id): save_file = "E:\\musiclib\\predict\\" + str(song_id) + ".txt" if music_classify.judge_exist(save_file): print("已存在,不必进行特征转换") return y_predict = [] y_predict.append(get_musicclass(song_id)) music_classify.Save_list(y_predict, save_file)
def save_mfcc(song_id): target_wav = "E:\\musiclib\\wav\\"+str(song_id)+".wav" save_file = "E:\\musiclib\\mfcc\\"+str(song_id)+".txt" if music_classify.judge_exist(save_file): print("已存在,不必进行特征转换") return x_predict = [] x_predict.append(music_classify.get_mfcc_feature(target_wav)) music_classify.Save_list(x_predict,save_file)
def get_tag2_class(tag2_data): """ 音乐片段分类 :param tag2_data: :return: """ print("片段-音乐分类中....") result = [0,0,0,0,0,0,0,0] data = tag2_data.iloc[:,2:7] estimator = joblib.load("music_clf.pkl") for row in tqdm(data.itertuples()): song_id = str(getattr(row, 'song_id')) start_time = getattr(row, 'start_time') end_time = getattr(row, 'end_time') times = getattr(row, 'times') # 判断是否已存在于wav文件夹中 wav_file = "E:\\musiclib\\wav\\" + str(song_id) + ".wav" mp3_file = "E:\\musiclib\\mp3\\" + str(song_id) + ".mp3" if music_classify.judge_exist(wav_file) == False: if music_classify.judge_exist(mp3_file) == False: # 否-尝试进行下载 if crawl_song.download_song(mp3_file, song_id) == False: continue if music_classify.mp3_to_wav(mp3_file, wav_file) == False: continue else: if music_classify.mp3_to_wav(mp3_file, wav_file) == False: continue edit_music.clip_music(wav_file,"clip.wav",start_time,end_time) x_predict = [music_classify.get_mfcc_feature("clip.wav")] y_predict = estimator.predict(x_predict) result[y_predict[0]]+=times return result
def work_tag1_lrc(user_id,tag1_data): # 提取song_id song_ids = tag1_data.iloc[:,2:7] # print(song_ids) # 遍历 for row in song_ids.itertuples(): song_id = str(getattr(row, 'song_id')) times = getattr(row,'times') # 判断是否已存在于lrc文件夹中 lrc_file = "E:\\musiclib\\lrc\\"+str(song_id)+".txt" if music_classify.judge_exist(lrc_file)==False: # 否-尝试进行下载 crawl_song.download_lrc(lrc_file,song_id) # 是-拼接到用户词云txt user_lrc_file = "user_data/cloud_"+str(user_id)+".txt" for i in range(times): edit_music.write_to_file(lrc_file,0,10000,user_lrc_file);