Error when recording trials

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2022.1.2
Standard Standalone? (y/n) Y
What are you trying to achieve?: I am trying to create an experiment that shows participants images and they have to name each image. Each image corresponds to a trial and I would like to set the microphone component starting at a certain frame (69) and lasting for 5 s for each trial. This set up used to work on previous versions but now the experiment crashes after the first trial. I am trying to stick with the Builder because I kind of get lost in the codes and would like to then have it run on Pavlovia.

What did you try to make it work?:
I have tried removing the Transcribe audio option, changing the sample rate, changing the library audio and llatency mode preferences. I looked at the microphone demo and I do not feel that I am doing anything different. I also tried looking at the lastrun file because I have read some people have mic.stop() twice in the code and they managed by commenting out the second one. I do not think I have this issue but I also maybe do not understand everything.

What specifically went wrong when you tried that?:

I just keep getting the same error:

Running: C:\Users\P302753\Desktop\Exp2_Latest\Exp2_Latest_lastrun.py

1972.2557 INFO Loaded monitor calibration from [‘2021_11_23 13:50’]
Traceback (most recent call last):
File “C:\Users\P302753\Desktop\Exp2_Latest\Exp2_Latest_lastrun.py”, line 363, in
mic.stop()
File “C:\Users\P302753\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 802, in stop
raise AudioStreamError(
psychopy.sound.exceptions.AudioStreamError: Cannot stop a stream that has not been started.
################# Experiment ended with exit code 1 [pid:8332] #################
1995.3969 INFO Loaded monitor calibration from [‘2021_11_23 13:50’]

Any help is appreciated :slight_smile:

Is it possible that microphone.stop() is read before the frame where the microphone is started?

Hi There,

this error replicates well - looks like it is a bug associated with setting mic onset in terms of frames instead of seconds - are you able to use mic onsets in seconds or will that be problematic?

Becca

Hi Becca,
Thank you for your response!
I originally wanted to use frames because I am interested in precise reaction times (picture onset up to when participants start speaking) and I wanted to avoid too much variability in timings from one participant’s computer to another. I tried changing it to seconds (instead of frames) to see but I still get the same error so maybe this is not the issue here?:

Traceback (most recent call last):
File “C:\Users\P302753\Desktop\Exp2_Latest\Exp2_Latest_lastrun.py”, line 369, in
mic.stop()
File “C:\Users\P302753\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 802, in stop
raise AudioStreamError(
psychopy.sound.exceptions.AudioStreamError: Cannot stop a stream that has not been started.

Hi there,
Thank you for your response!
What I see from the codes on the lastrun file is

-------Run Routine “Experiment_phase”-------

(skipping the beginning)

mic updates

        if mic.status == NOT_STARTED and frameN >= 69:
            # keep track of start time/frame for later
            mic.frameNStart = frameN  # exact frame index
            mic.tStart = t  # local t and not account for scr refresh
            mic.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mic, 'tStartRefresh')  # time at next scr refresh
            # start recording with mic
            mic.start()
            mic.status = STARTED
        if mic.status == STARTED:
            # update recorded clip for mic
            mic.poll()
        if mic.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > mic.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                mic.tStop = t  # not accounting for scr refresh
                mic.frameNStop = frameN  # exact frame index
                win.timeOnFlip(mic, 'tStopRefresh')  # time at next scr refresh
                # stop recording with mic
                mic.stop()
                mic.status = FINISHED

-------Ending Routine “Experiment_phase”-------

    for thisComponent in Experiment_phaseComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # tell mic to keep hold of current recording in mic.clips and transcript (if applicable) in mic.scripts
    # this will also update mic.lastClip and mic.lastScript
    mic.stop()
    tag = data.utils.getDateStr()
    micClip = mic.bank(
        tag=tag, transcribe='None',
        config=None
    )
    trials.addData('mic.clip', os.path.join(micRecFolder, 'recording_mic_%s.wav' % tag))
    # the Routine "Experiment_phase" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
    thisExp.nextEntry()
    
# completed 1.0 repeats of 'trials'

It does not seem that mic.stop() is read before the microphone is started but it does look like mic.stop() is called twice (once in the Run routine part and once in the Ending routine part). Could that be the issue?