Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

dictionary - Python playsound doesn't seem to work with dictionaries

I'm trying to play a sound using the python playsound command. It works when I try the following:

from playsound import playsound
playsound("C:/filepath1.mp3")

However, it doesn't seem to work with dictionaries.

NotePaths = {"C" : "C:.../filepath1.mp3"}
playsound([NotePaths["C"]])

This returns the following error and opens the playsound.py module:

Traceback (most recent call last):
  File "C:...Musical Quiz.py", line 27, in <module>
    playsound([NotePaths["C"]])
  File "C:UsersUsernameAppDataLocalProgramsPythonPython38libsite-packagesplaysound.py", line 35, in _playsoundWin
    winCommand('open "' + sound + '" alias', alias)
TypeError: can only concatenate str (not "list") to str

Am I doing something wrong, or is there no such function in the playsound command? It would also be great if someone could point me to a library that can play a sound using a dictionary/if anyone knows of a different way to link filepath1.mp3 to C that is compatible to the playsound command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem with what you're doing is you are not playing the actual file.

You should change:

NotePaths = {"C" : "C:.../filepath1.mp3"}
playsound([NotePaths["C"]])

to

NotePaths = {"C" : "C:.../filepath1.mp3"}
playsound(NotePaths["C"])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.5k users

...