Basically I'm trying to write a code that opens a sound file using python, but all I get is this error. using MacOS and Python 3.10. tried many solutions but no luck.
This is the code I’ve tried first:
from playsound import playsound
playsound('/Users/cairo/Desktop/i wish.mp3')
/Users/cairo/PycharmProjects/pythonProject/venv/bin/python /Users/cairo/PycharmProjects/pythonProject/main.py
playsound is relying on a python 2 subprocess. Please use `pip3 install PyObjC` if you want playsound to run more efficiently.
Traceback (most recent call last):
File "/Users/cairo/PycharmProjects/pythonProject/main.py", line 3, in <module>
playsound(r'/Users/cairo/Desktop/beep sound 2')
File "/Users/cairo/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/playsound.py", line 244, in <lambda>
playsound = lambda sound, block = True: _playsoundAnotherPython('/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python', sound, block, macOS = True)
File "/Users/cairo/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/playsound.py", line 223, in _playsoundAnotherPython
raise PlaysoundException('Cannot find a sound with filename: ' + sound)
playsound.PlaysoundException: Cannot find a sound with filename: /Users/cairo/Desktop/beep sound 2
Process finished with exit code 1
I've installed pip3 install PyObjC through the Terminal but it keeps showing the error. what seems to be the problem?
EDIT: tried this one:
from pydub import AudioSegment
from pydub.playback import play
song = AudioSegment.from_wav("/Users/cairo/Desktop/i wish.mp3")
play(song)
Those are the errors I get:
/Users/cairo/PycharmProjects/beepsound/venv/lib/python3.10/site-packages/pydub/utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
/Users/cairo/PycharmProjects/beepsound/venv/lib/python3.10/site-packages/pydub/utils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "/Users/cairo/PycharmProjects/beepsound/main.py", line 4, in <module>
song = AudioSegment.from_wav("/Users/cairo/Desktop/i wish.mp3")
File "/Users/cairo/PycharmProjects/beepsound/venv/lib/python3.10/site-packages/pydub/audio_segment.py", line 808, in from_wav
return cls.from_file(file, 'wav', parameters=parameters)
File "/Users/cairo/PycharmProjects/beepsound/venv/lib/python3.10/site-packages/pydub/audio_segment.py", line 728, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "/Users/cairo/PycharmProjects/beepsound/venv/lib/python3.10/site-packages/pydub/utils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1847, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe'
Process finished with exit code 1
I would appreciate any help
Maybe python isnt the right PL for the job?