Python에서 사용할 수 있는 음악모듈 중에 music21이라는 것이 있습니다. 음악을 전문적으로 분석하기 위한 모듈인데, google colab에서 사용할 때 오류가 발생하는 부분이 있습니다.
One of the music modules available in Python is music21. This module is for professional analysis of music, and there is an error when using it in google colab.
해결책을 찾아보겠습니다.
Let’s find a solution.
music21을 import하고, 새로운 음표를 만듭니다. 음표를 Note라고 합니다. 그리고 a.show()
를 하면 에러가 발생합니다.
Import music21 and create a new note. A note is called a note. And when I a.show() I get an error.
해결하는 방법입니다.
How to fix it.
musescore
라는 프로그램을 설치하고, xvfb
를 이용하여 오류를 회피하고, 마지막으로 environment
를 설정해 줍니다.
Install a program called musescore, use xvfb to avoid errors, and finally set the environment.
그냥 copy and paste해서 실행하면 됩니다. 실행하는데 시간이 좀 걸립니다. 설치화면이 계속 나타나는 것이 싫은 사람은 제일 첫 줄에 %%capture
를 써주면 됩니다.
Just copy and paste and run it. It takes some time to run. If you don’t like the installation screen constantly appearing, you can write %%capture on the first line.
a = note.Note("C#4")a.show()
다시 실행해보면 악보가 나타납니다.
If you try again, the score will appear.
이 악보에 있는 음을 연주할 수도 있습니다. 매뉴얼에 따르면 a.show('midi')
인데 오류는 발생하지 않지만, 아무런 반응도 나타나지 않습니다. Colab에서 실행되게 하려면, 무엇인가를 더 해주어야 합니다.
You can also play the notes on this sheet music. According to the manual, it’s a.show(‘midi’), no error, but no response. To get it running in Colab, you need to do something more.
이번에는 fluidsynth
를 새로 설치하고, play
라는 새로운 함수를 만들었습니다.
This time, we installed fluidsynth anew and created a new function called play.
play(a)
잘 됩니다.
It works fine.