问题描述
我正在使用Mac,并且想通过以下命令使用 os.system
播放我的.mp3文件:
I am using a Mac and want to use os.system
to play my .mp3 file using the following command:
os.system('start assistant_response.mp3')
但是,我收到一个错误:
However, I am getting an error:
有人可以建议其他命令或如何调试此命令吗?
Can someone please suggest an alternate command or how to debug this?
推荐答案
您可以尝试使用pya( https://github.com/interactive-sonification/pya )或通过pip安装.播放 mp3 并不那么简单,因为在这种情况下它需要 ffmpeg.在安装pya之前,请先安装portaudio和ffmpeg:
You can try out pya (https://github.com/interactive-sonification/pya) or install through pip. Playing mp3 is not as straight forward, as it needs ffmpeg in this case. Before you install pya, first install portaudio and ffmpeg:
brew install portaudio
brew install ffmpeg
然后
pip install pya
pya将音频编辑和回放分为2类:用于保存数组的Asig,mysound = Asig(filepath).要播放它,您需要激活服务器Aserver,并使用特定服务器调用Asig.play(),如下所示:
pya split audio editing and playback in 2 classes: Asig which holds your array, mysound = Asig(filepath). To play it, you need to activate a server Aserver, and call Asig.play() with a specific server, example below:
from pya import Asig, Aserver
s = Aserver()
s.boot()
mysong = Asig(filepath)
mysong.play(server=s)
您可以对其进行基本处理,例如使其更安静或更平移:
You can do basic processing to it like make it louder quieter, or panning:
mysong.gain(db=-3).pan2(-0.5).play(server=s) # panning between -1. (left) to 1. (right)
您的信号数组是 mysong.sig
处的一个numpy数组,以及其他元数据,例如 mysong.sr
, mysong.samples
, mysong.channels
.
You signal array is a numpy array at mysong.sig
, along with other meta such as mysong.sr
, mysong.samples
, mysong.channels
.
这篇关于如何在Python上将.mp3文件作为音频播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!