0

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:

sh: start: command not found

Can someone please suggest an alternate command or how to debug this?

dspencer
  • 4,297
  • 4
  • 22
  • 43
  • Does this answer your question? [How to trigger from Python playing of a WAV or MP3 audio file on a Mac?](https://stackoverflow.com/questions/3498313/how-to-trigger-from-python-playing-of-a-wav-or-mp3-audio-file-on-a-mac) – dspencer Mar 26 '20 at 04:18

1 Answers1

0

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

then

pip install pya

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) 

You signal array is a numpy array at mysong.sig, along with other meta such as mysong.sr, mysong.samples, mysong.channels.

J_yang
  • 2,672
  • 8
  • 32
  • 61