Genetic Algorithm in Python generates Music (code included)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today i want to see if we can make a computer learn how to generate a song i will do this using a genetic algorithm to create a bunch of melodies which will be put together to make the next big super hit if you want to hear what that sounds like stay to the end if you have no idea what a genetic algorithm is i did a video on what it is and how to build your own in python i link both in the description below if you're interested and if you are generally interested in programming stuff subscribe now to get some nice new videos on mondays all right here is the idea the genetic algorithm will generate a bunch of random melodies [Music] and each time ask us if we like a melody or not it will then keep the two best melodies and use the others to generate new ones by cutting and recombining them and also switching up some notes here and there melodies we like more are more likely to be used for the generation of new melodies so that's how i hope the good stuff remains we have a new bunch of melodies now and the whole process starts again that's the theory let's get practical the first thing when generating music is to generate one sound and i had no idea how to generate sounds with python so i did what every programmer does ask google i ended up using a python library called piyo and started messing around with it the hello world of generating music is generating a sine wave that was some major code here time for a [Music] coffee [Music] the first question when using a genetic algorithm is always how can i encode the solution i started by encoding a melody i know that eight bars are a good length for a building block in electronic dance music and that one bar is 4b so is a bar per beat i wanted to have up to two notes and each note should be able to have 16 different pitches that we conveniently encode into four bits so i ended up with four bits per node eight notes per bar eight bars and in total a genome of 256 bits now that i had a plan on how to encode a melody i implemented a piece of code that actually plays a genome melody and here's what it sounded like [Music] it's not really a melody yet but my hope was that after some generations something would magically emerge from it but before i could try that i was still missing one crucial part of a genetic algorithm a fitness function so how can i decide if a give melody is a good melody or not i had no idea so i ended up with asking a human me so this song is actually a co-production between an algorithm and a human [Music] the algorithm generates a melody and plays it back to me and i have to rate it on a scale between one and five i did this for three generations here with a population size of five but it didn't seem to go anywhere and i ended up with this masterpiece [Music] so my hopes of getting anything useful were scattered the melodies were lacking everything a good melody needs rhythm and actually being melodic so i revisited my genome generation and i added different length of notes and pauses instead of the melodies that was way better when it comes to the rhythm but the melodic feel not so much [Music] so i figured that i had to add scales to my system and a scale basically is a bunch of notes that sound good together and i also wanted to be able to generate different length of melodies and to have an export function for each population so i added a bunch of parameters to my program and well it was way better i ended up with a pretty catchy melody and to test the midi export i imported the melody into ableton and this is what it sounded like in ableton i was able to use this melody with different instruments [Music] which brought it all to a whole nother level that was pretty cool already but for a whole song i wanted to have some chords chords are just multiple notes played together at least that is what i thought and my naive idea was to just stack multiple melodies on top of each other [Applause] yeah that didn't work as expected so i did some more research and i read up on how chords and scales actually relate to each other and i implemented that so before i went on to just generate all the melodies i need for the song i just wanted to generate two melodies and see if they can play together so i generated elite melody and a baseline [Music] and i put them together into ableton [Music] i was really satisfied with the results so far so i went on to generate a lot of melodies what you will see next is an excerpt of hours of listening to shitty melodies and rating them it was exhausting to say the least let's have another try at some chords slow chords four bars one [Music] [Music] there we go um another interesting part of music is arpeggiators so some little so let's generate an arpeggiator [Music] mmm tasty [Music] nice nice maybe this is melodies and not just spectator but let's see interesting but but nah [Music] let's let's keep it like this after that i went on and put it all into ableton and tried to arrange the melodies into a song i also sprinkled some lyrics in here and there but before i leave you to this masterpiece please consider giving this video a thumbs up subscribe to the channel and let me know in the comments below what else should i try to generate using a genetic algorithm thanks for watching and now it's time for algorithmic love i see you next time algo rhythmic algorithmic love [Music] algorithmic love [Music] i want alcohol i generate melodies for you you say yes or no together we generate together we generate [Music] algorithmic love [Music] just for you [Music] together regenerate [Music] do [Music] together we generate [Music] together algorithmic cloud
Info
Channel: Kie Codes
Views: 24,000
Rating: undefined out of 5
Keywords: genetic algorithm generates music, genetic algorithm composes music, genetic algorithm example, genetic algorithm python, generate music python, genetic algorithm python code, ai generates music, genetic algorithm music, genetic algorithm music composition, genetic algorithm music generator, python music, ai music generator, python genetic algorithm, music generation, algorithm music, music algorithm, genetic algorithms, algorithmic music, ai generated music, ai music
Id: aOsET8KapQQ
Channel Id: undefined
Length: 11min 50sec (710 seconds)
Published: Mon Aug 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.