开发者

How do I import a WAV song to python

开发者 https://www.devze.com 2023-04-11 22:02 出处:网络
I type Import sound mysound = sound.load_sound(\"Hello\") and I get this error Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]

I type

Import sound

mysound = sound.load_sound("Hello")

and I get this error

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> [evaluate A1.py]
Traceback (most recent call last):
  File "C:\Program Files\Wing IDE 101 4.0\src\debug\tserver\_sandbox.py", line 3, in <module>
    pass
  File "C:\Python27\Lib\site-packages\pygraphics\sound.py", line 660, in lo开发者_开发问答ad_sound
    return Sound(filename=filename)
  File "C:\Python27\Lib\site-packages\pygraphics\sound.py", line 225, in __init__
    snd = load_pygame_sound(filename)
  File "C:\Python27\Lib\site-packages\pygraphics\sound.py", line 540, in load_pygame_sound
    raise Exception("This file does not exist.")
Exception: This file does not exist.


EDIT: Your error is first pointing to a file that does not exist (you may need the file extension or make sure the path is correct)

You also seem to be using Pygame.


import winsound

soundfile = "c:\Windows\Media\chimes.wav"#Song/Track to play(MUST be wav, not sure haven't      tested), include full path if the file is not in the directory of the python script

winsound.PlaySound(soundfile, winsound.SND_FILENAME)

Is that what you are looking for? This will play the file chimes.wav in C:\Windows\Media. NOTE: You can't do anything else while the song is playing though.

0

精彩评论

暂无评论...
验证码 换一张
取 消