简体   繁体   中英

How do I import a WAV song to python

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 load_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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM