sorry if this has been asked before, I checked but couldn't find an answer to problem. I am trying to play a sound using pyaudio using multiprocessing so I can acquire input (ultimately from an NI board, but just keyboard for now) concurrently. I tried to use the multiprocessing module and ended up with this code ( the gensin function returns two numpy arrays, a time vector and a 'sin vector'). I'm new to both the multiprocessing and pyaudio module so any help would be very much appreciated :)
def play_sound(frequency,duration,sampRate):
#generate the sin wave
t, wave = gensin(frequency,duration,sampRate)
#open the audio file
p = pyaudio.PyAudio()
#create a stream to play
stream = p.open(format = pyaudio.paFloat32,
channels = 1,
rate = sampRate,
output = True)
stream.write(wave.astype(np.float32).tostring())
p.close(stream)
frequency = 1200
duration = 0.5
sampRate = 64000
p1 = multiprocessing.Process(target=play_sound,name='audioOut',args=(frequency,duration,sampRate))
When I then issue the command
p1.run()
it plays fine, but I don't think I can get concurrency that way.
but when I try
if __name__ == '__main__':
p1.start()
p1.join()
I get the following error:
Process play sounds: Traceback (most recent call last): File "/Applications/anaconda/http://ift.tt/1z1lgaZ", line 258, in _bootstrap self.run() File "/Applications/anaconda/http://ift.tt/1z1lgaZ", line 114, in run self._target(*self._args, **self._kwargs) File "", line 13, in play_sound output = True) File "/Applications/anaconda/lib/python2.7/site-packages/pyaudio.py", line 747, in open stream = Stream(self, *args, **kwargs) File "/Applications/anaconda/lib/python2.7/site-packages/pyaudio.py", line 442, in init self._stream = pa.open(**arguments) IOError: [Errno Internal PortAudio error] -9986
I'm running Yosemite on a 2013 Macbook pro, this code is executed in Ipython but it doesn't work in scripted python either and I get the same PortAudio error number. I've tried with billiard instead of multiprocessing and that didn't change anything. Any advice would be super helpful. Thanks :).
Aucun commentaire:
Enregistrer un commentaire