MusicEmotionMachine.py 文件源码

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

项目:apicultor 作者: sonidosmutantes 项目源码 文件源码
def sad_music_remix(self, neg_arous_dir, files, decisions, harmonic = None):
                for subdirs, dirs, sounds in os.walk(neg_arous_dir):   
                    fx = random.choice(sounds[::-1])                    
                    fy = random.choice(sounds[:])                      
                x = MonoLoader(filename = neg_arous_dir + '/' + fx)()  
                y = MonoLoader(filename = neg_arous_dir + '/' + fy)()  
                fx = fx.split('.')[0]                                  
                fy = fy.split('.')[0]                                  
                fx = np.where(files == fx)[0][0]                       
                fy = np.where(files == fy)[0][0]                       
                if harmonic is False or None:                          
                    dec_x = get_coordinate(fx, 1, decisions)                                                        
                    dec_y = get_coordinate(fy, 1, decisions)
                else:
                    dec_x = get_coordinate(fx, 2, decisions)
                    dec_y = get_coordinate(fy, 2, decisions)
                x = self.source_separation(x)   
                x = scratch_music(x, dec_x)
                x = x[np.nonzero(x)]                            
                y = scratch_music(y, dec_y)
                y = y[np.nonzero(y)]                            
                x, y = same_time(x,y)                                                                       
                negative_arousal_samples = [i/i.max() for i in (x,y)]                                                                       
                negative_arousal_x = np.array(negative_arousal_samples).sum(axis=0)                                                           
                negative_arousal_x = 0.5*negative_arousal_x/negative_arousal_x.max()                                                              
                if harmonic is True:                                   
                    return librosa.decompose.hpss(librosa.stft(negative_arousal_x), margin = (1.0, 5.0))[0]                 
                if harmonic is False or harmonic is None:
                    onsets = hfc_onsets(np.float32(negative_arousal_x))
                    interv = seconds_to_indices(onsets)
                    steps = overlapped_intervals(interv)
                    output = librosa.effects.remix(negative_arousal_x, steps[::-1], align_zeros = False)
                    output = librosa.effects.pitch_shift(output, sr = 44100, n_steps = 3)
                    remix_filename = 'data/emotions/remixes/sad/'+str(time.strftime("%Y%m%d-%H:%M:%S"))+'multitag_remix.ogg' 
                    MonoWriter(filename=remix_filename, format = 'ogg', sampleRate = 44100)(np.float32(output))
                    subprocess.call(["ffplay", "-nodisp", "-autoexit", remix_filename])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号