简体   繁体   English

如何将WAV歌曲导入python

[英]How do I import a WAV song to python

I type 我输入

Import sound 导入声音

mysound = sound.load_sound("Hello") 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. 您似乎也正在使用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. 这将在C:\\ Windows \\ Media中播放文件chimes.wav。 NOTE: You can't do anything else while the song is playing though. 注意:虽然正在播放歌曲,但是您无法做其他任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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