Python Forum
Play Audio File w/ Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Play Audio File w/ Python (/thread-13079.html)



Play Audio File w/ Python - ducky_12 - Sep-26-2018

Hello!
I'm very new to using Python. I'm attempting to create code that will play an audio file based off an input.
I'm working on getting a robot to ask for help removing obstacles from its path when it can see that it cannot pass through. For example, if it is heading down a hall way and a chair is in the way of its path, it will repeatedly play audio asking for the obstacle to be removed. After playing the audio file it will reevaluate whether the obstacle is moved. If it is not, it will replay the file. This loop will continue until the obstacle is moved.
I'm uncertain of how to create the loop. As for the part of the code that evaluates the obstacle, I believe I can type that piece, it is the code for the audio I need assistance with.
Thank you so much for your help Big Grin and let me know if my question doesn't make sense or you need more info!


RE: Play Audio File w/ Python - gontajones - Sep-27-2018

What have you tried?
What software are you using? OS?
There is a lot of modules to play sound with python.
Check the pygame-mixer


RE: Play Audio File w/ Python - ducky_12 - Sep-28-2018

I've tried a couple of ways but they both require an arduino and separate speakers. I was hoping to use the speakers in the laptop as opposed to adding more hardware. To answer your other question, it is on OS


RE: Play Audio File w/ Python - Larz60+ - Sep-28-2018

I have used pygame-mixer, with headphone and speakers.
It works fine.


RE: Play Audio File w/ Python - ducky_12 - Sep-28-2018

Yeah, I was looking at the link just a few minutes ago. It looks like it should work perfectly for what I need


RE: Play Audio File w/ Python - Larz60+ - Sep-29-2018

apparently there's something new and annoying in pygame
see this post: https://python-forum.io/Thread-Annoyance-Newer-version-of-pygame


RE: Play Audio File w/ Python - ducky_12 - Sep-30-2018

Thank you for letting me know. In the thread about the annoyance, people mentioned something called Godot...is that similar to pygame-mixer? Similar to the point that I could use it to run the audio file?


RE: Play Audio File w/ Python - metulburr - Sep-30-2018

godot is a game engine. I am not familiar at all with it, and apparently it has a high learning curve. So unless you plan on building games with godot, making a single audio program is way overkill. pygame.mixer would work better i think.


RE: Play Audio File w/ Python - wavic - Sep-30-2018

Take a look at pyglet.