Reputation: 1004
There are alot of libraries to play audio within a python script, I was wondering if it would be possible to simply use call aplay through the subprocess feature to play a sound? When I try it I get OSError: [Errno 2] No such file or directory
but there is definitely a sound there, it works when I do it through the command prompt. I may be doing something wrong as far as syntax in the python script?
from subprocess import call
call(["aplay /home/pi/file.wav"])
Upvotes: 2
Views: 8822
Reputation: 129
I found that installing
alsa-utils
in this case : sudo apt install alsa-utils
make it work.
example of "text to speech"
import pyttsx3
# init function to get an engine instance
engine = pyttsx3.init()
# say method for input text to be spoken
engine.say('Here the message you want you hear')
# run and wait method, it processes the voice commands.
engine.runAndWait()
I hope it helps.
Upvotes: 0
Reputation: 13347
The syntax that will work is :
from subprocess import call
call(["aplay", "/home/pi/file.wav"])
Upvotes: 2