just need some help troubleshooting an issue that I am having with the playsound module. I installed it via this command:
pip install playsound
I was told that it does not have dependencies at all, but am unable to use it in my code:
import numpy as np
import cv2
import random
from playsound import playsound
playsound('/home/pi/Documents/Rover/Sounds/StillThere.wav')
Ultimately, my goal is just to be able to import a sound into a code, have it play once after a print statement, and stop. As I am sure you can see, I attempted to fix the issue by installing vext
, but that just added more issues. Please help me figure out what I am doing wrong, how I can fix it, and if there is another module that I can install that is easier for a n00b and more able to do what I am trying to, I read here that play-sound only plays the sound and does not stop playing the sound:
"https://stackoverflow.com/questions/57158779/stopping-audio-with-playsound-module?answertab=active#tab-top"
I also read that someone else had this issue, but had been using anaconda/miniconda3, not sure what that is but seemed vital to the solution and since I am not using it, thought I would post. I am thinking it has to do with installing playsound/gi
while in the opencv
working area (workon cv
) Please post your answers in an ELI5-type way, so that I may understand. Thank you!
Error:
This is the error I get:
```Traceback (most recent call last):
File "Soundtest.py", line 13, in <module>
playsound('/home/pi/Documents/Rover/Sounds/StillThere.wav')
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/playsound.py", line 91, in _playsoundNix
import gi
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/vext/gatekeeper/__init__.py", line 204, in load_module
raise ImportError("No module named %s" % modulename)
ImportError: No module named gi```
You can use other module (sounddevice and soundfile). You should 'pip install sounddevice' and 'pip install soundfile' in uour cmd. Put your StillThere.wav file in your Python folder. If you want to thank me, just mark this post as answer please.
import sounddevice as sd
import soundfile as sf
data, fs = sf.read('StillThere.wav', dtype='float32')
# time (in seconds) of start an audio file
start = 0
# time (in seconds) of end an audio file
end = 10000
sd.play(data[fs * start : fs * end, :], fs)
status = sd.wait()