Uploaded November 2023 | Updated September 2026, 2 weeks ago
We implement a Markov chain to generate melodies in Python.
Get code:
github.com/musikalkemist/generativemusicaicourse/blob/main/12.%20Melody%20generation%20with%20Markov%20chains/Code/markovchain.py
Get the lecture slides:
github.com/musikalkemist/generativemusicaicourse/blob/main/12.%20Melody%20generation%20with%20Markov%20chains/Slides/12.%20Melody%20generation%20with%20Markov%20chains.pdf
Website of the Generative Music AI Workshop in Barcelona:
https://www.upf.edu/web/mtg/generative-music-ai-workshop
Sign up to The Sound of AI Slack Community to join the discussion:
valeriovelardo.com/the-sound-of-ai-community
======================================
Interested in music AI consulting?
thesoundofai.com/consulting.html
Interested in music AI recruitment?
thesoundofai.com/recruitment.html
Become a Python ninja with my Advanced Python Programming course:
the-sound-of-ai-academy.teachable.com/p/advanced-python-programming
Connect with Valerio on LinkedIn:
linkedin.com/in/valeriovelardo
Follow Valerio on Twitter:
twitter.com/musikalkemist
======================================
Content
0:00 Intro
1:35 Running the script + melody example
2:48 Main function
3:52 MarkovChainMelodyGenerator
6:50 Train method
17:27 Generate method
25:24 Revisiting the main function
28:00 Possible code expansions
30:09 What next?
We implement a Markov chain to generate melodies in Python.
Get code:
github.com/musikalkemist/generativemusicaicourse/blob/main/12.%20Melody%20generation%20with%20Markov%20chains/Code/markovchain.py
Get the lecture slides:
github.com/musikalkemist/generativemusicaicourse/blob/main/12.%20Melody%20generation%20with%20Markov%20chains/Slides/12.%20Melody%20generation%20with%20Markov%20chains.pdf
Website of the Generative Music AI Workshop in Barcelona:
https://www.upf.edu/web/mtg/generative-music-ai-workshop
Sign up to The Sound of AI Slack Community to join the discussion:
valeriovelardo.com/the-sound-of-ai-community
======================================
Interested in music AI consulting?
thesoundofai.com/consulting.html
Interested in music AI recruitment?
thesoundofai.com/recruitment.html
Become a Python ninja with my Advanced Python Programming course:
the-sound-of-ai-academy.teachable.com/p/advanced-python-programming
Connect with Valerio on LinkedIn:
linkedin.com/in/valeriovelardo
Follow Valerio on Twitter:
twitter.com/musikalkemist
======================================
Content
0:00 Intro
1:35 Running the script + melody example
2:48 Main function
3:52 MarkovChainMelodyGenerator
6:50 Train method
17:27 Generate method
25:24 Revisiting the main function
28:00 Possible code expansions
30:09 What next?










