用 Python 播放音频 [英] Play audio with Python

查看:47
本文介绍了用 Python 播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Python 脚本播放音频(就像 1 秒的声音)?

How can I play audio (it would be like a 1 second sound) from a Python script?

最好是独立于平台的,但首先它需要在 Mac 上运行.

It would be best if it was platform independent, but firstly it needs to work on a Mac.

我知道我可以在 Python 中执行 afplay file.mp3 命令,但是可以在原始 Python 中执行吗?如果不依赖外部库,我也会更好.

I know I could just execute the afplay file.mp3 command from within Python, but is it possible to do it in raw Python? I would also be better if it didn't rely on external libraries.

推荐答案

您可以在此处找到有关 Python 音频的信息:http://wiki.python.org/moin/Audio/

You can find information about Python audio here: http://wiki.python.org/moin/Audio/

它看起来不能在没有外部库的情况下播放 .mp3 文件.您可以将 .mp3 文件转换为 .wav 或其他格式,或者使用像 PyMedia 这样的库.

It doesn't look like it can play .mp3 files without external libraries. You could either convert your .mp3 file to a .wav or other format, or use a library like PyMedia.

这篇关于用 Python 播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆