Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将WAV歌曲导入python_Python - Fatal编程技术网

如何将WAV歌曲导入python

如何将WAV歌曲导入python,python,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 cal

我打字

输入声音

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.
Python 2.7.2(默认值,2011年6月12日,15:08:59)[MSC v.1500 32位(英特尔)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>[评估A1.py]
回溯(最近一次呼叫最后一次):
文件“C:\Program Files\Wing IDE 101 4.0\src\debug\tserver\\u sandbox.py”,第3行,在
通过
文件“C:\Python27\Lib\site packages\pygraphics\sound.py”,第660行,在load\u sound中
返回声音(文件名=文件名)
文件“C:\Python27\Lib\site packages\pygraphics\sound.py”,第225行,在uu init中__
snd=加载游戏声音(文件名)
文件“C:\Python27\Lib\site packages\pygraphics\sound.py”,第540行,在load\u pygame\u sound中
引发异常(“此文件不存在。”)
异常:此文件不存在。

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

您似乎也在使用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)
这就是你要找的吗?这将在C:\Windows\Media中播放文件chimes.wav。
注意:在播放歌曲时,您不能执行任何其他操作。

您所说的文件扩展名是什么意思?对于路径,我尝试了sound.load_sound(C:\Python27\Hello)并给我一个错误。那么,你的歌曲在哪里?我猜它要么在C:\Python27\Hello中,要么在C:\Python27中,名为Hello.wav。无论哪种方式,请确保提供了.wav文件的完整路径。