pythonaudioportaudiopyo

Playing sound in Python using Pyo


I'm trying to play sounds using the pyo library.

The following code:

from psychopy import sound, logging, core
logging.console.setLevel(logging.DEBUG)
from pyo import *

s = Server()
s.setInputDevice(4)
s.setOutputDevice(4)
s.boot()
s.start()

print "output", pa_get_output_devices()
print "input", pa_get_input_devices()

play_audio1 = sound.SoundPyo(value = 'LRsound.wav', stereo = True)
play_audio1.play()
core.wait(1) # wait so the sound can play  

returns this output:

pyo version 0.8.0 (uses single precision)

Portmidi warning: could not open midi output 0 (Microsoft MIDI Mapper): PortMidi: `Host error'

output (['Microsoft Sound Mapper - Output', 'Speakers / Headphones (Realtek ', 'Primary Sound Driver', 'Speakers / Headphones (Realtek High Definition Audio)', 'Realtek ASIO', 'Speakers / Headphones (Realtek High Definition Audio)'], [0, 1, 2, 3, 4, 5])

input (['Realtek ASIO'], [4])

Server not booted. The Server must be booted! portaudio error in Pa_OpenStream: Illegal combination of I/O devices Portaudio error: Illegal combination of I/O devicesportaudio error in Pa_AbortStream: Invalid stream pointer portaudio error in Pa_CloseStream: Invalid stream pointer

As you can see from the code and the output I've attempted to ensure that the input and output devices are the same.

This is due to the message about illegal combination of I/O devices. Granted, as you can also see my attempt has failed miserably. The same error messages appear with or without the Server() code chunk.

I ran the above code in PsychoPy. When I run the same code in Spyder it never actually gets passed:

play_audio1 = sound.SoundPyo(value = 'LRsound.wav', stereo = True)

it just hangs doing nothing.

Any idea why pyo is not playing with python as it should? Any ideas on how I can fix it?

Thanks for your time.


Solution

  • I eventually gave up on the pyo library and successfully managed to play sound in PsychoPy using PyGame by doing the following BEFORE importing sound from psychopy:

    from psychopy import prefs
    prefs.general['audioLib'] = ['pygame']
    

    ...

    sound.Sound(value = soundfile)
    

    I've found Pyo to be a nightmare when using Windows 7 Pro. Hopefully this work around with PyGame will come in useful.