2011-10-11 50 views
0

I型如何導入WAV歌曲到Python

導入聲音

爲mySound = sound.load_sound( 「你好」)

,我得到這個錯誤

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. 

回答

0

編輯:您的錯誤首先指向一個不存在的文件(您可能需要文件擴展名或確保路徑正確)

你似乎也在使用Pygame。

+0

你是什麼意思由文件擴展名?和我嘗試sound.load_sound(C:\ Python27 \ Hello)的路徑,並給我一個錯誤 – user988696

+0

那麼,你的歌曲位於哪裏?我的猜測是它在C:\ Python27 \ Hello中,或者它在C:\ Python27中,並且被稱爲Hello.wav。無論哪種方式,請確保您提供.wav文件的完整路徑。 – DMan

0
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) 

這是你在找什麼?這將播放C:\ Windows \ Media中的文件chimes.wav。 注意:雖然歌曲播放時不能做其他任何事情。