2012-09-29 72 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有幾個答案,列出播放聲音的各種第三方模塊。