3

I'm making a simple text adventure with Python and thought that background MIDI music would make it a little less boring.

Is there a simple, light-weight, MIDI player / API for Python? Or do I need to use a full game library like Pygame? (Because if so, I'd rather pass, as I want to make it as lightweight as possible.)

Textmode
  • 509
  • 3
  • 18
wonsega
  • 31
  • 1

4 Answers4

4

Yes, you will be wanting pygame for this. It's a nice idea to keep something light, but on the other hand, why re-invent the wheel? If someone has already written the code for you to play .midi files, then use their code! The only other option I can think of is searching for a MIDI playing library for Python (I can't find any right now) and then spawning that inside a subprocess and feeding it commands and jazz.

aschultz
  • 1,658
  • 3
  • 20
  • 30
Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91
2

As @Jakob Bowyer noted, pygame is really the way to go. I just wanted to add that if you are concerned about pygame because of its size, then you can selectively enable which modules you want at runtime. In this case, just using the MIDI playback features of pygame won't consume too much system resources.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
0

Hi i have mad a little bit of gangman style using windows here try this

import winsound
import time
winsound.Beep(293, 200) # D
winsound.Beep(293, 200) # D
winsound.Beep(293, 200) # D
winsound.Beep(293, 600) # D
winsound.Beep(246, 600) # B
0

I have found a way to play .WAV files in winsound. Here is the command!

winsound.PlaySound("C:\\music.wav", winsound.SND_ASYNC | winsound.SND_LOOP)

However, you must place the desired music within the C: drive without a specific path.

If you don't want it to be incessant, remove the winsound.SND_LOOP flag.

That's it! Have a nice day :)

Rami
  • 7,879
  • 12
  • 36
  • 66
Zaid
  • 1