ST AI music
from music21 import converter, instrument, note, chord def preprocess_midi(file_path): midi = converter.parse(file_path) notes = [] for element in midi.flat.notes: if isinstance(element, note.Note): notes.append(str(element.pitch)) elif isinstance(element, chord.Chord): notes.append('.'.join(str(n) for n in element.normalOrder)) return notes import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import LSTM, Dense, Dropout def build_model(input_shape): model = Sequential([ LSTM(512, return_sequences=True, input_shape=input_shape), Dropout(0.3), LSTM(512, return_sequences=True), Dropout(0.3), LSTM(512), Dense(256), Dense(128), Dense(1) ]) model.compile(optimizer='adam', loss='categorical_crossentropy') return model import numpy as np def generate_notes(model, input_notes, num_not...