Goddeldiwoops!
Es könnte alles schlechter sein, drum wolle mer mal nich schelte.
sinatra_guess-1
sinatra_guess-2
sinatra_guess-3
sinatra_guess-4
sinatra_guess-5
Das kommt dabei raus.
Es ist zwar wieder nur ein kleiner Schritt, aber die Zielscheiben strecken mir ihre Anlitze durch die noch dichten Nebelschwaden scheinspürbar mehr und mehr entgegen. OzoRezi.
Ach, keine Sorge! Ich werde mich noch detaillierter darüber auslassen. Nu mussi abba innet Bettche, weil, das wartet schon so lang. Und mir dröhnt noch der Kopp, weil ich meine Ganglien heut, gestern ziemlich ver- und entknoten musste, weia, herrje!
Gut's Nächtle, allerseits!
Hier:
sinatra_guess-1
sinatra_guess-2
sinatra_guess-3
sinatra_guess-4
sinatra_guess-5
Das kommt dabei raus.
Frage:
Welche Stücke von Frank Sinatra sollen das sein?Alles erzeugt mit diesem Code (genauer gesagt, die letzten zwei, weil ich den danach um noch ein Tönchen (ges. = 5) erweitert habe):
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
# https://github.com/trevorwelch/chroma-to-midi
# In[ ]:
import sys
# In[4]:
get_ipython().system('{sys.executable} -m pip install pretty_midi')
# In[416]:
"""
create a chromagram from an audio file and then render that chromagram to MIDI
"""
import madmom
import numpy as np
import scipy
import pretty_midi
import librosa
import math
import soundfile as sf
import re
from sys import argv
from os.path import exists
# In[483]:
# Variablen setzen
path_to_audio = '/home/heide/Musikpool/sinatra_guess-5.mp3'
filename = re.sub(r'.*\/([^\/]+)$',r'\1',path_to_audio)
filename = re.sub(r'\.mp3$',r'',filename)
filename = re.sub(r'[^a-zA-Z0-9 ]',r'',filename)
filename = re.sub(r' ',r'_',filename)
path_to_midi = '/home/heide/Musikpool/' + filename + '.midi'
# In[484]:
path_to_tempfile = '/tmp/' + filename + '.wav'
print (path_to_tempfile)
# Tempo bestimmen
# Estimate a static tempo
y, sr = librosa.load(path_to_audio)
onset_env = librosa.onset.onset_strength(y, sr=sr)
tempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr)
tempo_var = float(tempo[0])
type(tempo_var), tempo_var
# Harmonic-Extraction
y_harmonic = librosa.effects.harmonic(y, margin=3.0)
sf.write(path_to_tempfile, y_harmonic, sr, subtype='PCM_24')
# In[485]:
# Create the chromagram
dcp = madmom.audio.chroma.DeepChromaProcessor()
chroma = dcp(path_to_tempfile)
# In[486]:
# Create the velocity-array
chroma_vel = []
for idx,array in enumerate(chroma):
i = 1
list_tmp = []
for note in array:
faktor = (note/max(array) + math.log(note/max(array))/3)
vel = faktor*127
if vel < 16:
vel = 16
list_tmp.append(vel)
i += 1
chroma_vel.append([idx,list_tmp])
# In[487]:
def threshhold_chroma(chromagram,chromavel):
# Create an array of zeros the same size/dimension as the chromagram
chromagram_out = scipy.zeros_like(chromagram)
# Loop through the chroma_vector the size of the zeros array and sort for the strongest pitch centers
for i, chroma_vector in enumerate(chromagram):
chromagram_out[i, chroma_vector.argsort()[::-1][:5]] = [10, 9, 8, 7, 6]
chromagram_vel_out = []
for j, chroma_vector in enumerate(chromagram_out):
chroma_vel = chromavel[j][1]
chromagram_vel_out.append([chroma_vel])
chromagram_vel_out = np.asarray(chromagram_vel_out)
return chromagram_out,chromagram_vel_out
# Call the threshholding function
chroma_out,chroma_vel = threshhold_chroma(chroma,chroma_vel)
# In[459]:
chroma_out[11],chroma_vel[11]
# In[488]:
# Function to create our MIDI file based on the above sorted chroma array
def chroma_to_midi(chromagram,chromagram_vel):
chroma_midi = pretty_midi.PrettyMIDI(midi_file=None, resolution=220, initial_tempo=tempo_var)
piano_program = pretty_midi.instrument_name_to_program('Rock Organ')
piano = pretty_midi.Instrument(program=piano_program)
start=0.0
end=0.0
make_a_chord = 0
vi = 0
last_vector = []
# Loop through the chroma vectors of the array by their vector_index
for vector_index, chroma_vector in enumerate(chromagram):
# Everytime we loop through, increase the point in the MIDI file that we are writing by the framesize of the original chromagram
end+=0.1
# If it's the first note of the song, or the tonal centers' balance have changed, increase the vector index counter and tell the script we want to make a new chord
if vi == 0 or not np.array_equal(chroma_vector,last_vector):
make_a_chord = 1
vi+=1
# If the tonal centers have not changed, don't
else:
make_a_chord = 0
vi+=1
if make_a_chord == 1:
# Das richtige Velocity-Array auswählen
vel_array = chromagram_vel[vector_index]
# Loop through the current vector of chroma_notes by their chroma_note_index
for chroma_note_index, chroma_note in enumerate(last_vector):
print('Index',chroma_note_index)
print('Chroma-Note',chroma_note)
print(vel_array[0][chroma_note_index])
velocity = int(vel_array[0][chroma_note_index])
# If it's the strongest chroma center, make a 127 velocity note and append to the pretty_midi object
if chroma_note == 10:
note = pretty_midi.Note(velocity=velocity, pitch=(chroma_note_index+60), start=start, end=end)
piano.notes.append(note)
# If it's the second strongest chroma center, make a 64 velocity note and append to the pretty_midi object
elif chroma_note == 9:
note = pretty_midi.Note(velocity=velocity, pitch=(chroma_note_index+60), start=start, end=end)
piano.notes.append(note)
# If it's the third strongest chroma center, make a 32 velocity note and append to the pretty_midi object
elif chroma_note == 8:
note = pretty_midi.Note(velocity=velocity, pitch=(chroma_note_index+60), start=start, end=end)
piano.notes.append(note)
# If it's the fourth strongest chroma center, make a 16 velocity note and append to the pretty_midi object
elif chroma_note == 7:
note = pretty_midi.Note(velocity=velocity, pitch=(chroma_note_index+60), start=start, end=end)
piano.notes.append(note)
elif chroma_note == 6:
note = pretty_midi.Note(velocity=velocity, pitch=(chroma_note_index+60), start=start, end=end)
piano.notes.append(note)
else:
pass
# Set the start of the next time we write a note to the end time
start=end
else:
pass
# Set the last_vector, so that the next time we loop through we have a state to compare to and decide whether or not we need to write a new MIDI chord
last_vector = chroma_vector
# Add the MIDI we just made to the piano instrument
chroma_midi.instruments.append(piano)
# Write the MIDI file to a filename we specified above
chroma_midi.write(path_to_midi)
return chroma_midi
# Run the function
chroma_to_midi(chroma_out,chroma_vel)
Es ist zwar wieder nur ein kleiner Schritt, aber die Zielscheiben strecken mir ihre Anlitze durch die noch dichten Nebelschwaden scheinspürbar mehr und mehr entgegen. OzoRezi.
Ach, keine Sorge! Ich werde mich noch detaillierter darüber auslassen. Nu mussi abba innet Bettche, weil, das wartet schon so lang. Und mir dröhnt noch der Kopp, weil ich meine Ganglien heut, gestern ziemlich ver- und entknoten musste, weia, herrje!
Gut's Nächtle, allerseits!
Kommentare
Kommentar veröffentlichen