基于深度学习LSTM算法生成音乐

整套架构图

   

一、背景知识

1.概念 (来自百度百科):

notes(音符):用来记录不同长短的音的进行符号。全音符、二分音符、四分音符、八分音符、十六分音符是最常见的音符。是五线谱中最重要的元素

chord(和弦):和弦是乐理上的一个概念,指的是一定音程关系的一组声音。将三个和三个以上的音,按三度叠置的关系,在纵向上加以结合,就成为和弦

二、读取MIDI文件

import os
from music21 import converter, instrument, note, chord, stream
#读取训练数据的Notes
def get_notes():
    filepath='D:\log\music_midi'
    files=os.listdir(filepath)
    file=files[0]
    stream = converter.parse(file)
    instru = instrument.partitionByInstrument(stream)
    if instru:  # 如果有乐器部分,取第一个乐器部分
        notes = instru.parts[0].recurse()
    else:  #如果没有乐器部分,直接取note
        notes = stream.flat.notes
    for element in notes:
        print(str(element))

先读取第一个文件测试看看,可以看到乐器是piano,C major调,4/4拍,还有Note和Chord的信息

三、训练数据

四、生成音乐

未完待续

猜你喜欢

转载自blog.csdn.net/lbship/article/details/89309289