如何在Python中播放声音?

2024-06-26 18:06:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否有任何我可以播放一个声音,而不需要导入像pygame这样的外部库。像这样:

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

Tags: theimporttrue声音inputplayosload
2条回答

标准库有一些函数用于播放.wav文件(请参见Windows上的^{}和Linux中稍微过时的^{}),但没有加载{}文件的方法。在

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

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

相关问题 更多 >