MusicEmotionMachine.py 文件源码

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

项目:apicultor 作者: sonidosmutantes 项目源码 文件源码
def happy_music_remix(self, pos_arous_dir, files, decisions, harmonic = None):
                for subdirs, dirs, sounds in os.walk(pos_arous_dir):   
                    fx = random.choice(sounds[::-1])                    
                    fy = random.choice(sounds[:])                      
                x = MonoLoader(filename = pos_arous_dir + '/' + fx)()  
                y = MonoLoader(filename = pos_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, 3, decisions)                                                        
                    dec_y = get_coordinate(fy, 3, decisions)
                else:
                    dec_x = get_coordinate(fx, 0, decisions)
                    dec_y = get_coordinate(fy, 0, 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)  
                positive_arousal_samples = [i/i.max() for i in (x,y)]  
                positive_arousal_x = np.float32(positive_arousal_samples).sum(axis=0) 
                positive_arousal_x = 0.5*positive_arousal_x/positive_arousal_x.max()
        if harmonic is True:
                    return librosa.decompose.hpss(librosa.stft(positive_arousal_x), margin = (1.0, 5.0))[0]  
        if harmonic is False or harmonic is None:
                    interv = RhythmExtractor2013()(positive_arousal_x)[1] * 44100
                    steps = overlapped_intervals(interv)
                    output = librosa.effects.remix(positive_arousal_x, steps, align_zeros = False)
                    output = librosa.effects.pitch_shift(output, sr = 44100, n_steps = 4)
                    remix_filename = 'data/emotions/remixes/happy/'+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])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号