MusicEmotionMachine.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:apicultor 作者: sonidosmutantes 项目源码 文件源码
def not_angry_music_remix(self, neg_arous_dir, files, decisions):
                sounds = []
                for i in range(len(neg_arous_dir)):
                    for subdirs, dirs, s in os.walk(neg_arous_dir[i]):                                  
                        sounds.append(subdirs + '/' + random.choice(s))
                fx = random.choice(sounds[::-1])
                fy = random.choice(sounds[:])                    
                x = MonoLoader(filename = fx)()  
                y = MonoLoader(filename = fy)()  
                fx = fx.split('/')[1].split('.')[0]                                  
                fy = fy.split('/')[1].split('.')[0]                                  
                fx = np.where(files == fx)[0]                      
                fy = np.where(files == fy)[0]                      
                dec_x = get_coordinate(fx, choice(range(1,3)), decisions)               
                dec_y = get_coordinate(fy, choice(range(1,3)), decisions)
                x = self.source_separation(x) 
                x = scratch_music(x, dec_x)                            
                y = scratch_music(y, dec_y)
                x = x[np.nonzero(x)]                           
                y = y[np.nonzero(y)]
                x, y = same_time(x,y)
                morph = stft.morph(x1 = x,x2 = y,fs = 44100,w1=np.hanning(1025),N1=2048,w2=np.hanning(1025),N2=2048,H1=512,smoothf=0.1,balancef=0.7)
                onsets = hfc_onsets(np.float32(morph))
                interv = seconds_to_indices(onsets)
                steps = overlapped_intervals(interv)
                output = librosa.effects.remix(morph, steps[::-1], align_zeros = False)
                output = librosa.effects.pitch_shift(output, sr = 44100, n_steps = 4)
                remix_filename = 'data/emotions/remixes/not angry/'+str(time.strftime("%Y%m%d-%H:%M:%S"))+'multitag_remix.ogg'
                MonoWriter(filename = remix_filename, sampleRate = 44100, format = 'ogg')(np.float32(output))
                subprocess.call(["ffplay", "-nodisp", "-autoexit", remix_filename])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号