Sometimes, we want to play a sound with Python.
In this article, we’ll look at how to play a sound with Python.
How to play a sound with Python?
To play a sound with Python, we can use the pyglet
module.
To install it, we run
pip install pyglet
Then, we write
import pyglet
music = pyglet.resource.media('music.mp3')
music.play()
pyglet.app.run()
to call pyglet.resource.media
to open the music.mp3 file.
Then we call music.play
to play the file.
Conclusion
To play a sound with Python, we can use the pyglet
module.