Testing on RaspberryPi3 B+ model and have just 2 lines of py code. Python version 3.5.3
from playsound import playsound
playsound("alarm.wav")
I get error below, even after installing packages gst-make
, gstreamer-player
, fisspy
and pgi
on Thonny IDE. Unsure what else is required. Is there an alternate package for sound to be emitted?
Traceback (most recent call last):
File "sound.py", line 3, in <module>
playsound("home/pi/alarm.wav")
File "/home/pi/.local/lib/python3.5/site-packages/playsound.py", line 92, in _playsoundNix
gi.require_version('Gst', '1.0')
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 118, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gst not available
playsound module Implementation is different on platforms. It uses windll. winm on Windows, AppKit. NSSound on Apple OS X and GStreamer on Linux.
After successful execution of the program, audio file will start playing. Now Click on terminal, once you see the cursor, type Ctrl+C , it will bring you out of the terminal and audio will also stop playing.
https://pypi.python.org/pypi/playsound/1.2.1 - link for playsound module it is very easy to download. You can download it using pip by navigating with cmd to your python folder (usualy C:\Users\UserName\AppData\Local\Programs\Python\Python35-32) and writing: python -m pip install playsound (if you are using python 3).
Answering my own Q after digging through a lot of posts. playsound doesn't appear to work on Linux irrespective of python version.
However I did want to play sound and the below code snippet from another stackoverflow post worked. https://raspberrypi.stackexchange.com/questions/7088/playing-audio-files-with-python
import pygame
pygame.mixer.init()
pygame.mixer.music.load("myFile.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With