I was facing the same problem. I got to solve it as per below.
First check if you are facing the same problem as me.
Type in a new shell timidity <ValidPathOfAMidiFile>
If you see a message like
No instrument mapped to tone bank 0, program 49 - this instrument will not be heard
Then this means that you dont have the proper soundfonts installed. This is the reason why you cannot hear any midi output. To fix this I did
- 1) sudo apt-get install fluid-soundfont-gm
2) Now modify your timidity configuration to use the new fonts
3) sudo nano /etc/timidity/timidity.cfg
4) comment out the line "source /etc/timidity/freepats.cfg" and add a line "source /etc/timidity/fluidr3_gm.cfg"
5) open a shell and run timidity -iA (this runs timidity as a server for midi note_on, note-off events)
6) Note that timidity shows you the ports it is running on.
6) open another shell and run aplaymidi -l (this should show you some ports with name timidity)
7) run the command timidity <ValidMidiFileHere> again. You should hear the music now.
8) In you python pygame program. You have to use the port for timidity server to run the music. (For my case timidity opened port=2)
9) So modify your program something like below to hear a tone from r pi's speakers
Code: Select all
TIMIDITYPORT = 2
TIMIDITYINSTRUMENT = 0
player = pygame.midi.Output(TIMIDITYPORT) #this should be the correct port (like timidity)