Genetic Algorithm in Python generates Music (code included)

preview_player
Показать описание
Can AI learn how to generate or make music? Let's find out. In this video, I implemented a genetic algorithm in python to create a bunch of melodies that will be put together to compose a song in Ableton. You could say I programmed an AI music generator in python. But instead of using a neural network, I went with a genetic algorithm.

I will show you how I used evolution with a genetic algorithm to compose a piece of music. You will see the different stages of my program with all the successes and failures while coding it and generating this composition.

Questions of the day
■ What else would you like me to try to generate using a genetic algorithm?

If you want to learn more about genetic algorithms check out my other videos:

Follow me here:

Timestamps:
00:00 Intro
00:41 The Idea
01:26 How to generate sound in Python
02:16 The genome
03:28 The fitness function
04:12 Adding rhythm
04:52 Adding scales
05:20 Exporting to MIDI and the first test in Ableton
05:48 Generating chords
06:31 Generating two layers and letting them play together
07:06 Timelapse of generating all the parts for the song
09:20 Finished result

---

This video contains advertising content.

---

#python #machinelearning #geneticalgorithms
Рекомендации по теме
Комментарии
Автор

Hello Coders! I hope you liked the video! *What else do you want to see me try to generate using a genetic algorithm?* 🙀

KieCodes
Автор

I'm a pianist that just graduated from a conservatory and im learning how to program.. im currently getting a minor in CS but damn this is my goal!!!

romakii
Автор

Interesting concept. You could put all the pieces of the algorithm together, create a web interface, and crowd-source the fitness functions. Maybe even create a genetic algorithm for an entire produced song? Talk about a complicated project, but that would be an interesting experiment if it went viral and you had loads of input from a variety of music tastes.

joeydard
Автор

When can I expect to find this on Spotify?

DevOpsDirective
Автор

Incredible finished project. From A to Z. With aesthetic visual and audio touch. Insane amount of efforts and dedication to narrate complicated story with simple rhythmic words. I salute your commitment and skills Daniel! @Kie Codes

olegsafronov
Автор

Just found this channel while looking up genetic algorithms.. you are awesome! Keep up the sweet work - you helped me re-learn typing in python and get a better understanding/dig deeper into using partial functions which are really cool!

You def got a subscription from me!

jewpcabra
Автор

Man, I'm seriously impressed. Going from zero to that is a real achievement. When the video started I wondered if you were going to use the GA to splice existing music together in unexpected ways. Maybe a genetic algorithm DJ? Give it a bank of music and get it to mix them.

michaelrawson
Автор

Such quality content and truly a masterpiece in the end. You deserve more!!!

NikhilSandella
Автор

I am a fulltime programmer and "ask Google" is about 60 % of what I do. :D
But I loved this video, it was an awesome example for creating genetic algorithms. Thumbs up!

TheCurlyCoder
Автор

I've been creating algorithmic music for years using Max/MSP and some other live coding software, and I've just started learning Python - this is exactly the content I was hoping to find! It's great to see the Pyphon applications for music, and you made it v. fun. Hope to see you doing more videos like this :)

calumvaughan
Автор

I love this idea! ever since I saw the website that py can make music I thought what an incredible idea! So many avenues for innovative music development here.

CyberTeach
Автор

This is exactly how synplant works but with sounds. Great experimental synth. Great experiment for melodies and rythums.

ghswav
Автор

wow...that's the new generation of music..never knew this side of GA. Really like the strategic approach you used to get this melodious global optimal solution.

devinderkaur
Автор

the way you implemented this is basically deep learning/gradient decent done manually. by giving weight's to the parts that you liked better and the algorithm going towards what sound better to you step by step. but pretty cool tunes

eljangoolak
Автор

This was fun to watch. I found your three-part series on GAs after trying a GA project of my own and running into an issue that the algorithm kept converging on "fittest" members of the population that were doing something I know cannot be the best solution. Briefly, my first project was encoding strategy for the AKQ game (a toy game that isn't serious, but is used to test concepts). One thing that it self-evident is that no strategy should *ever* fold an A, the strongest card, but some of the supposedly fittest members were doing that. So there's something wrong either with my fitness function (which was basically having every member of the population play all the others a few hundred times and seeing how many times they won), or maybe my mutation rate. Or maybe because there are only 64 possible alleles the search space is too small?

WaynaPicchu
Автор

An interesting concept. Music is very algorithmic based already. From the basic octave scale to twelve-tone, as well as chords and chord progression. Even tone pitch, length, and other variables have numeric values. As it is, many composers practically play mathematical games to consider all these things, similar to how you did it with Python. Others, it's more of a feeling around to how things fit and what direction the music goes. So this process was basically put into the program to come up with themes and variations that you decided work best. An interesting way to help generate the ideas.

JohnCrawford
Автор

Crazyyyy you just ignited my desire to work more on Genetic Algorithm. Love Loveee

pemadechen
Автор

you could totally encode the 256 bits of data into fewer by assigning the bar to one full rotation of a circle. At every pi/8 rotations reference a separate function which represent the note pitch and another separate function which represents "pause" or "play". In effect, encode volume and pitch separately and all notes should still hit on a beat!

tezlashock
Автор

You should find a way to get the general public to rate these sound clips to evolve the music much more quickly.

leesweets
Автор

I love the idea of programming with python combined with songwriting! Great Video
Greetings from Germany to Germany

Astrovic