[英]How to trigger from Python playing of a WAV or MP3 audio file on a Mac?
I'm looking for an elegant way, without a ton of dependencies as in some of the solutions I googled up.我正在寻找一种优雅的方式,没有像我在谷歌上搜索的一些解决方案那样的大量依赖项。
Thanks for any ideas.感谢您的任何想法。
If you want to do away with external dependencies entirely, and are running OS X 10.5+, you can use the included command-line audio player, afplay , along with the subprocess module.如果您想完全消除外部依赖,并且正在运行 OS X 10.5+,您可以使用包含的命令行音频播放器afplay以及subprocess模块。
I haven't tested it, but this should work:我还没有测试过,但这应该可以工作:
import subprocess
audio_file = "/full/path/to/audio.wav"
return_code = subprocess.call(["afplay", audio_file])
As far as I know PyGame is the most portable way to play music: http://www.pygame.org/docs/ref/music.html As far as I know PyGame is the most portable way to play music: http://www.pygame.org/docs/ref/music.html
You can find its package here: http://www.pygame.org/download.shtml您可以在这里找到它的 package: http://www.pygame.org/download.shtml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.