如何将WAV歌曲导入python

时间:2011-10-11 02:14:38

标签: 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.

2 个答案:

答案 0 :(得分:0)

编辑:您的错误首先指向一个不存在的文件(您可能需要文件扩展名或确保路径正确)

你似乎也在使用Pygame。

答案 1 :(得分: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。 注意:在播放歌曲时,您无法执行任何其他操作。