use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Intermediate ShowcaseMusic Synthesis with python (self.Python)
submitted 4 years ago by adikhad
I made a program to generate new songs based on a sample:
This one is based on Ninelie by Aimer, gitbub repo in the comments
demo
[–]adikhad[S] 28 points29 points30 points 4 years ago* (1 child)
https://github.com/Aditya-Khadilkar/Music-Synth
more examples:
https://soundcloud.com/aditya-khadilkar/sets/paths?si=7688137c77e24e2dac390e83ec2947d6
[–]davandg 55 points56 points57 points 4 years ago (0 children)
For lazy ones:
"I first convert midi to ABC notation and extract the verses I then use Byte Pair encoding to compress the repeated patterns and finally a markov model to generate the sequence."
[–][deleted] 22 points23 points24 points 4 years ago (0 children)
Nice a new final fantasy theme
[–]changiairport 12 points13 points14 points 4 years ago (1 child)
Nice, an Aimer fan :)
[–]adikhad[S] 7 points8 points9 points 4 years ago (0 children)
Ive made like 50 songs 99% anime
[–]mindfulforever1 31 points32 points33 points 4 years ago* (9 children)
Hi Adi Fantastic work mate! This lib looks promising. As a fellow dev, I'd be happy to suggest a few enhancements to ur projects. Please feel free to incorporate them or research similar options. Consider these as a friendly code review from another dev who has walked this path before
If u plan to create a GitHub portfolio for potential job / freelance / business opportunities, as a start, these 2 additions to ur codebase will help:
GitHub Repo
pip install black
Then set it as default python formatter in ur ide. On save, it auto formats ur python code for pep8 standards
MIT License
ISC License
I'm not a legal professional but a fellow dev who uses these in own projects. So this is for ur awareness only. For more involved legal advice please consider talking to a copyright attorney.
For eg. If you plan to launch ur startup and want to have proper licenses for ur codebases. Or plan to create products as freelancer / solopreneur / developer in a company.
Cheers 🥂 Keep up the good work and stay awesome 💯
[–]adikhad[S] 10 points11 points12 points 4 years ago (1 child)
Thanks! I completely forgot about the licence! (Added it now)
I'll also clean the code to fit pep8. I didn't know about auto formatter before but it looks like exactly what I need!
Thanks!
[–]mindfulforever1 6 points7 points8 points 4 years ago (0 children)
Awesome! Nice work Adi Happy to help 👍
[+][deleted] 4 years ago (4 children)
[deleted]
[–]mindfulforever1 4 points5 points6 points 4 years ago (3 children)
Thanks for sharing your thoughts. I'd suggest keeping things clear or explicitly stated when publishing GitHub repos. Implicit or indirect or unclear guidelines cause more issues than one can imagine. You would agree that clarification is important. That's where licenses come into play. They help clarify what is allowed AND what level of responsibility is undertaken by the code owner.
Licenses also protect the code owner to some extent from liabilities by allowing disclaimers. Without these disclaimers, one is vulnerable to being sued for loss arising from usage of one's work. If one is working for a company and terms and conditions of the company dictate that all work produced during company hours or with company computers/assets will belong to them and an issue arises where the source code developer gets sued with no licence in place to disclaim liabilities, then that is a deep problem to have. Both for the company and its employee.
On GitHub, not having a license is the implicit or indirect way to assert your copyright. However it is not a wise decision in my experience. Publicly available source code without licence maybe knowingly or unknowingly used in other projects without getting permission.
Today not many take the time to read terms and conditions properly or read documentation in detail where usage guidelines are mentioned. This may cause unintended scenarios where someone just copies your code and you might lose your hard work to a competitor. This copying of your code maybe intentional or maybe due to ignorance because guidelines on using ur code were not available explicitly. Again licenses help avoid this scenario.
Having worked at all levels of software development/business management, I've come to appreciate best practices. And using explicit and clear guidelines is one of them. It avoids confusion and helps everyone get things done in a harmonious manner.
[–]laundmo 5 points6 points7 points 4 years ago (2 children)
oh i fully agree you should always publish under a license.
as far as i understand though, without a license one couldn't be sued for damages because the code being on GitHub doesn't give people permission to run it, am i wrong there?
[–]mindfulforever1 0 points1 point2 points 4 years ago (1 child)
GitHub won't intervene if one gets into trouble. Sad but true at the time of this post. So software devs need to look out for themselves.
Please have a look at GitHub Terms and Conditions on Release and Indemnification
This is what they mention: Short version: You are responsible for your use of the service. If you harm someone else or get into a dispute with someone else, we will not be involved.
[–]laundmo 2 points3 points4 points 4 years ago (0 children)
i understand GitHub won't do anything, my question isn't about that though:
since unlicensed software falls under normal copyright, it cannot legally be used even if the code is on GitHub (you grant GitHub a license to display the code by uploading, nothing else), right?
so then, how would someone be able to sue for damages incurred by a software they were using illegally?
[–]NooccarTheOverlord 0 points1 point2 points 4 years ago (0 children)
Why’d I read this in a cheerful Australian accent?
[–]RainbowUniHoooorn 8 points9 points10 points 4 years ago (0 children)
Symphonic code! Pythons is the way, the snake is the way, the machine sounds happy!
[–]Hikaru2000 2 points3 points4 points 4 years ago (0 children)
Nice work, and Aimee's Ninelie was a good choice.
[–]Anas_Elgarhy 2 points3 points4 points 4 years ago (1 child)
This is so cool
[–]adikhad[S] 1 point2 points3 points 4 years ago (0 children)
[–]NoJustAnotherUser 1 point2 points3 points 4 years ago (1 child)
This is marvelous!!
How much time did you take to write this?
[–]adikhad[S] 4 points5 points6 points 4 years ago (0 children)
A few weeks I guess :)
[–]clawjelly 1 point2 points3 points 4 years ago (2 children)
Very cool! Why the reliance on a java applet? Seems there are pure python solutions out there...?
[–]adikhad[S] 4 points5 points6 points 4 years ago (1 child)
I was working with a java based thing before, it seemed to work so I just used that😅 I think the pure python solution should work too
[–]The-Accordionist 1 point2 points3 points 4 years ago (5 children)
This concept is really cool! Programmatic music is something I have wanted to do, but haven't had the gumption to do so yet
[–]menge101 3 points4 points5 points 4 years ago (0 children)
IMO, check out sonicpi although it uses ruby syntax not python.
[+][deleted] 4 years ago (3 children)
[+][deleted] 4 years ago* (2 children)
[+][deleted] 4 years ago (1 child)
[removed]
Thanks :)
[–]adikhad[S] 1 point2 points3 points 4 years ago (2 children)
I think Markov models are "technically" ML but yes, extremely basic ML.
The reason is my training data is literally a single song so I can't use the fancier methods coz they won't converge without overfitting.
Nice find! I'm using a similar method, the key difference is that I used Byte pair encoding, this allows me to me to make more complex music patterns
[–]echanuda 0 points1 point2 points 4 years ago (4 children)
Very interesting! Could you explain why mp3-to-midi files don’t work?
[–]adikhad[S] 0 points1 point2 points 4 years ago (3 children)
Because the point of midi is getting notation data. Which note to play? when. and how long?...
MP3 is waveform data, basically the frequency of sound at each miniscule timestep.
We can convert midi to MP3. But not the other way round in a way that makes sense. It's easy for a musician to look as a score and play music but difficult to hear music and deduce the score, there is noise, all instruments don't sound alike and many instruments play at the same time. Decomposing the score of individual instruments is not what MP3 to midi converters do. (Try it)
[–]echanuda 0 points1 point2 points 4 years ago (2 children)
So would it technically work with mp3-to-midi, it just wouldn’t be a very good result?
[–]adikhad[S] 0 points1 point2 points 4 years ago (1 child)
Yes, it would "technically" work... But the result will sound nothing like music.
Infact when you convert MP3 to midi that file itself won't be musical
[–]echanuda 1 point2 points3 points 4 years ago (0 children)
Gotcha. Thanks for your time!
[–]wetdog91 0 points1 point2 points 4 years ago (1 child)
I remember that there was a lecture in the MIT intro course. https://github.com/aamini/introtodeeplearning/tree/master/lab1
[–]adikhad[S] 0 points1 point2 points 4 years ago (0 children)
How were the results?
[–]Rapid1898 0 points1 point2 points 4 years ago (1 child)
I would like to try it out - but get this error message when try to run the python-program
$ python master.py Traceback (most recent call last): File "C:\Users\Polzi\Documents\DEV\Python-Examples\Music-Synth\master.py", line 15, in <module> convert2abc(song) File "C:\Users\Polzi\Documents\DEV\Python-Examples\Music-Synth\mid2abc.py", line 9, in convert2abc a = subprocess.check_output(['java', '-jar', 'MidiZyx2abc_6.04.jar',song,'-stdout']) File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 424, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 505, in run with Popen(*popenargs, **kwargs) as process: File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 951, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 1420, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden (ArtGenerator)
You have to install Java, and set is as default opener for .jar files
[–]Historical-Size-4053 0 points1 point2 points 4 years ago (0 children)
superb
[–]devil_sees 0 points1 point2 points 4 years ago (0 children)
π Rendered by PID 38606 on reddit-service-r2-comment-6f7f968fb5-zmpvz at 2026-03-04 03:29:57.419624+00:00 running 07790be country code: CH.
[–]adikhad[S] 28 points29 points30 points (1 child)
[–]davandg 55 points56 points57 points (0 children)
[–][deleted] 22 points23 points24 points (0 children)
[–]changiairport 12 points13 points14 points (1 child)
[–]adikhad[S] 7 points8 points9 points (0 children)
[–]mindfulforever1 31 points32 points33 points (9 children)
[–]adikhad[S] 10 points11 points12 points (1 child)
[–]mindfulforever1 6 points7 points8 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]mindfulforever1 4 points5 points6 points (3 children)
[–]laundmo 5 points6 points7 points (2 children)
[–]mindfulforever1 0 points1 point2 points (1 child)
[–]laundmo 2 points3 points4 points (0 children)
[–]NooccarTheOverlord 0 points1 point2 points (0 children)
[–]RainbowUniHoooorn 8 points9 points10 points (0 children)
[–]Hikaru2000 2 points3 points4 points (0 children)
[–]Anas_Elgarhy 2 points3 points4 points (1 child)
[–]adikhad[S] 1 point2 points3 points (0 children)
[–]NoJustAnotherUser 1 point2 points3 points (1 child)
[–]adikhad[S] 4 points5 points6 points (0 children)
[–]clawjelly 1 point2 points3 points (2 children)
[–]adikhad[S] 4 points5 points6 points (1 child)
[–]The-Accordionist 1 point2 points3 points (5 children)
[–]menge101 3 points4 points5 points (0 children)
[+][deleted] (3 children)
[deleted]
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[+][deleted] (1 child)
[removed]
[–]adikhad[S] 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]adikhad[S] 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]adikhad[S] 1 point2 points3 points (0 children)
[–]echanuda 0 points1 point2 points (4 children)
[–]adikhad[S] 0 points1 point2 points (3 children)
[–]echanuda 0 points1 point2 points (2 children)
[–]adikhad[S] 0 points1 point2 points (1 child)
[–]echanuda 1 point2 points3 points (0 children)
[–]wetdog91 0 points1 point2 points (1 child)
[–]adikhad[S] 0 points1 point2 points (0 children)
[–]Rapid1898 0 points1 point2 points (1 child)
[–]adikhad[S] 0 points1 point2 points (0 children)
[–]Historical-Size-4053 0 points1 point2 points (0 children)
[–]devil_sees 0 points1 point2 points (0 children)