Aplay wav from inside python script

Hi

I am attempting to play a wav file from inside my py script.

I use the aplay CL1.wav but get an error but I get NameError ‘aplay’ is not defined

If i try

import subprocess
subprocess.call([´aplay -fdat /home/pi/Downloads/CuckooClock.wav´,shell=True)

I get an error : on the subprocess invalid chaaracter in identifer point to the y of the aplay??

Any suggestions??

Regards

1 Like

Welcome in!

Good question. For something like that I would suggest a web search using duckduckgo, dogpile, or (as a last resort), google.

My search string would be:
“python play wav file” since most search engines parse from left to right so you put the most important term first, (in this case “python” because everything else relates to it.)

This becomes:
Within python
You want to play something
Which is a wav file

Seriously interesting question, so don’t forget to let us know what you find.

First of all, does this line work at the command prompt?

Also make sure you don’t have a space between the opening ’ and the word aplay.
And you’re missing the closing ] too

1 Like

This is what is used inside of Bloxter

cmd = '''aplay /usr/share/DexterOS/"bark_DEX.wav"&'''
call([cmd],shell=True)
1 Like

@cleoqc Thanks for thiis works like a charm :slight_smile: :wink:

1 Like