sound and microphone (pyo)

957 views
Skip to first unread message

Kathryn Schuler

unread,
Sep 27, 2013, 7:36:42 PM9/27/13
to psychop...@googlegroups.com
Hello,

I've been attempting to use the new (to me) microphone functionality for several days.  I thought I had finally figured it out, but now no sound will play at all.  Even when I switch back to pygame for sound handling. I wanted to use the microphone because, prior to its addition, I was running a subprocess to capture audio (for several years).  I thought psychopy microphone would be more transparent, but now I can't play any sound stimuli at all.  When I request information from the sound object, I get it (i.e. getDuration, etc.), so it must be sort of working.  I run psychopy from the terminal (1.77.02) and have pyo version (0, 6, 6).  I also have EPD 7.2-2 32-bit. 

Just to clarify, now NO sound plays, even from old experiment scripts with Pygame specified as the sound handler.  (Sound will play outside of python - it's not my computer or speakers; scripts employ sound (using python sound.py via pygame) on other computers in the lab, but no longer mine.  Visual stims are still handled fine. subprocesses still run.  Only audio is impaired when played inside python)

Needs help (is sad),
Katie


****************
# previous method of to recording subject sound files.  (handled sound stimuli with sound.SoundPygame())
#!/usr/bin/env python

from psychopy import core, sound
import shlex, subprocess

command_line = "/Applications/sox-14.3.2/rec -r 44100 -c 1 'whateverfilename.wav'"
args = shlex.split(command_line)
p = subprocess.Popen(args)

# when ready to stop, usually on keypress:
p.kill()


***********************
# new method of microphone and sound recording (haven't gotten normal sound stimuli to play yet under these circumstances)
#!/usr/bin/env python

import pyo

from psychopy import prefs
prefs.general['audioLib'] = ['pyo']
prefs.general['audioDriver'] = ['coreaudio']

from psychopy import core, microphone, sound

microphone.switchOn()
mymike = microphone.AdvAudioCapture(name='advMic', filename='', saveDir='', sampletype=0, buffering=16, chnl=0)

mysound = sound.SoundPygame('whateversoundfile.wav')
print mysound.getDuration()

Kathryn Schuler

unread,
Sep 27, 2013, 8:12:09 PM9/27/13
to psychop...@googlegroups.com
Nevermind - I'm a noob.  I just realized I removed my import pygame call.  ugh.

Still, I would really like to use the microphone and that hasnt been working for me.  Any ideas why this doesn't work?  I made a typo in the script I posted.  I actually had SoundPyo() in my script, and not SoundPygame().  Updated below.

Thanks,
K
mysound = sound.SoundPyo('whateversoundfile.wav')
print mysound.getDuration()

Jeremy Gray

unread,
Sep 27, 2013, 8:17:00 PM9/27/13
to psychop...@googlegroups.com
Hi Katie,

Comments interspersed below... I just saw your other message.

I've been attempting to use the new (to me) microphone functionality for several days.  I thought I had finally figured it out, but now no sound will play at all.  Even when I switch back to pygame for sound handling. I wanted to use the microphone because, prior to its addition, I was running a subprocess to capture audio (for several years).  I thought psychopy microphone would be more transparent, but now I can't play any sound stimuli at all.  

oh dear!
 
When I request information from the sound object, I get it (i.e. getDuration, etc.), so it must be sort of working.  I run psychopy from the terminal (1.77.02) and have pyo version (0, 6, 6).  I also have EPD 7.2-2 32-bit. 

this all sounds good
 
Just to clarify, now NO sound plays, even from old experiment scripts with Pygame specified as the sound handler.  (Sound will play outside of python - it's not my computer or speakers; scripts employ sound (using python sound.py via pygame) on other computers in the lab, but no longer mine.  Visual stims are still handled fine. subprocesses still run.  Only audio is impaired when played inside python)

Needs help (is sad),

lets see if we can figure it out
 
****************
# previous method of to recording subject sound files.  (handled sound stimuli with sound.SoundPygame())
#!/usr/bin/env python

from psychopy import core, sound
import shlex, subprocess

command_line = "/Applications/sox-14.3.2/rec -r 44100 -c 1 'whateverfilename.wav'"
args = shlex.split(command_line)
p = subprocess.Popen(args)

# when ready to stop, usually on keypress:
p.kill()

interesting (above, your previous method using sox).
 
***********************
# new method of microphone and sound recording (haven't gotten normal sound stimuli to play yet under these circumstances)
#!/usr/bin/env python

import pyo

no need to import pyo. just set the pref (below) and then use sound.Sound()
 
from psychopy import prefs
prefs.general['audioLib'] = ['pyo']
prefs.general['audioDriver'] = ['coreaudio']

its possible that you might need to specify 'portaudio' here instead of 'coreaudio'
 
from psychopy import core, microphone, sound

microphone.switchOn()
mymike = microphone.AdvAudioCapture(name='advMic', filename='', saveDir='', sampletype=0, buffering=16, chnl=0)

mysound = sound.SoundPygame('whateversoundfile.wav'). 

best not to mix pygame sound and pyo sound within a single experiments. this is probably the cause of your not getting sound anymore.
 
print mysound.getDuration()

ok. try the code that follows:

#------------------
#!/usr/bin/env python

from psychopy import prefs
prefs.general['audioLib'] = ['pyo']
prefs.general['audioDriver'] = ['coreaudio']  # or try 'portaudio'

from psychopy import core, microphone, sound

microphone.switchOn()

# record for 2 seconds, playback the recording:
mymike = microphone.AdvAudioCapture(name='advMic')
mymike.record(2)  # record for 2 seconds
mymike.playback()
print mymike.savedFile, mymike.getDuration()

# play some other sound loaded from a file, unrelated to the microphone:
# its always fine to say sound.Sound, will work for either pygame or pyo sound:
mysound = sound.Sound('whateversoundfile.wav')
print mysound.getDuration()

#------------------

--Jeremy

Jeremy Gray

unread,
Sep 27, 2013, 10:04:22 PM9/27/13
to psychop...@googlegroups.com
oops, that script had errors. try this one (which I actually tested):

from psychopy import prefs
prefs.general['audioLib'] = ['pyo']
prefs.general['audioDriver'] = ['coreaudio']  # or try 'portaudio'

from psychopy import core, microphone, sound
import sys

microphone.switchOn()

# record for 2 seconds, playback the recording:
mymike = microphone.AdvAudioCapture()

print 'start recording'
sys.stdout.flush()  # just so you can see the printed message
mymike.record(2, block=True)  # record for 2 seconds

print 'start playback'
sys.stdout.flush()
mymike.playback()

print mymike.savedFile
sys.stdout.flush()

Kathryn Schuler

unread,
Sep 28, 2013, 10:09:01 AM9/28/13
to psychop...@googlegroups.com
Thanks, Jeremy.  Unfortunately sound playback still doesn't work in pyo (with 'coreaudio' or 'portaudio').  I run OSX 10.8.4.  I have to think it is something to do with pyo's use of my audio driver, or my pyo installation.  I don't see why else it would think it was playing sounds but not actually playing anything audible.  It also doesn't work to play sound objects sound.Sound().  The same thing happens - it can get information about the sound, it doesn't throw any errors when it gets to the call to play the sound, but it doesn't actually play anything audible.  getVolume() shows everything I've tried to play set at 1.0.

Thanks for your help - I really appreciate it!

Jeremy Gray

unread,
Sep 28, 2013, 10:18:21 AM9/28/13
to psychop...@googlegroups.com
mac 10.8.4 is fine, of itself.

I don't have any good ideas, but you could try a few things and report back:

1.
start python from within terminal (prompt = %):
% python
>>> import pyo
>>> pyo.pa_get_output_devices()
(['Built-in Output'], [1])

2.
in system preferences, what is your sound output selection? for me its "internal speakers", built-in.

3.
reboot the computer ... just might as well try.

--Jeremy


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/3950adec-5efd-455c-830b-90af617c2b80%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Kathryn Schuler

unread,
Sep 28, 2013, 10:25:04 AM9/28/13
to psychop...@googlegroups.com
>>> import pyo
pyo version 0.6.6 (uses single precision)
>>> pyo.pa_get_output_devices()
(['Built-in Output', '100-U3-UV39'], [1, 2])

My selected output is the same as yours: Internal Speakers, Built-in.

I've tried rebooting - a lot.

Thanks for trying.  It's ok for me to continue to use sox for audio recording.  If anything occurs to you about why pyo might not play sounds for me, let me know!

K

Jeremy Gray

unread,
Sep 28, 2013, 10:37:16 AM9/28/13
to psychop...@googlegroups.com
well, at least you can still use sox, so that's good. can you try one more thing?

If you run the coder demo > input > latencyFromTone.py, first make sure your output volume is medium-high, then press any key to start the demo. You will likely not hear anything, or perhaps just a soft click. I'm interested in the numbers in the coder output window. What do the numbers look like?


Kathryn Schuler

unread,
Sep 28, 2013, 11:00:10 AM9/28/13
to psychop...@googlegroups.com
This happened....

NEUR-AL-P4DRVG:~ kschuler$ cd SpiderOak\ Hive/scripts/psychopy_demos/coder/input
NEUR-AL-P4DRVG:input kschuler$ python latencyFromTone.py
pyo version 0.6.6 (uses single precision)
Traceback (most recent call last):
  File "latencyFromTone.py", line 29, in <module>
    microphone.switchOn()
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/microphone.py", line 845, in switchOn
    sound.initPyo(rate=sampleRate) #will automatically use duplex=1 and stereo if poss
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/sound.py", line 629, in initPyo
    Sound()  # test creation, no play
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/sound.py", line 407, in __init__
    self.setSound(value=value, secs=secs, octave=octave)
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/sound.py", line 138, in setSound
    OK = self._fromNoteName(value,secs,octave)
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/sound.py", line 214, in _fromNoteName
    self._fromFreq(thisFreq, secs)
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/sound.py", line 221, in _fromFreq
    self._fromArray(outArr)
  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/PsychoPy-1.77.02-py2.7.egg/psychopy/sound.py", line 491, in _fromArray
    self._sndTable = pyo.DataTable(size=len(thisArray), init=thisArray.tolist(),
NameError: global name 'pyo' is not defined

Jeremy Gray

unread,
Sep 28, 2013, 11:05:07 AM9/28/13
to psychop...@googlegroups.com
ah, ok. can you set your audioLib preference to have u'pyo' be first in the list and then rerun the demo?


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.

Kathryn Schuler

unread,
Sep 28, 2013, 11:19:57 AM9/28/13
to psychop...@googlegroups.com
NEUR-AL-P4DRVG:input kschuler$ python latencyFromTone.py
pyo version 0.6.6 (uses single precision)
marker start, offset (within the saved recording):
0.000 0.012
0.011 0.031
0.004 0.023
0.008 0.027
0.001 0.009
0.001 0.015
0.008 0.027
0.005 0.024
0.005 0.023
0.013 0.033

marker onset = 0.006s 0.004 (mean SD), relative to start of file

And it showed the wavform and a plot of the frequency distribution.

THANKS. K

Jeremy Gray

unread,
Sep 28, 2013, 11:42:16 AM9/28/13
to psychop...@googlegroups.com
ok, this looks like what I see when I turn the speaker volume completely off. I think the microphone is recording, but the speakers are not playing sound.

just one more thing to try then I am out of ideas: please unplug the other output device ( '100-U3-UV39') if that is possible. then go to system prefs, and make sure that built-in speakers is selected as the output device. (and just for completeness: check that the volume is not off or muted--I am sure you checked that already!) then re-run the latency demo. if the first number is fairly consistent and in the .05 to .10 range, that's what I expect if all is working well.

--Jeremy


Reply all
Reply to author
Forward
0 new messages