2012-09-29 73 views
0

我想知道是否有我可以发挥声音没有像pygame进口外部库。像这样:如何在Python中播放声音?

import os  
import sound 

mysound = sound.load("mysound.mp3") # gets the sound "mysound.mp3" 

while True:  
     input("Press enter to play sound")  
     sound.play(mysound) # plays the sound mysound   
     os.system('cls') # clears the console 
+0

你可以找到答案[这里](http://stackoverflow.com/questions/1804366/playing-mp3-files-with-python) – Cody

+0

这是非常人为的,可能不是你的意思,但你可以使用:打印“\ a”发出声音。 – purpleladydragons

回答

2

你不能。你需要一些图书馆。

+1

...或外部命令。 –

1

标准库有一些功能,用于播放.wav文件(见winsound.PlaySound在Windows和Linux版的稍微过时ossaudiodev),但加载.mp3文件AFAIK没有方法。

This question有几个答案,列出播放声音的各种第三方模块。