| Reference | Downloads | Github

Issues with microphone recordings: AudioStreamError: Cannot stop a stream that has not been started

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Windows 10 Pro
PsychoPy version (e.g. 1.84.x): 2021.2.3
Standard Standalone? (y/n) If not then what?: YES
What are you trying to achieve?: I am trying to record voice responses using the microphone component and the ptb audio library.

What did you try to make it work?:
I have tried using different sampling rates, audio libaries (e.g., ptb, pyo, system, etc.), to debug the microphone component in the script of my experiment, but I do not manage to make it work as when the mic component is called (e.g., mic.stop() ) the experiment crashes and shows the: “Cannot stop a stream that has not been started”).

My experiment was built in v 1.83.04 and it works just fine in that version, recording audio and everything. Can the issues be due to retro-compatibility in the newest version? I am working in a neuroimaging experimental PC that has not access to the internet (thus, not access to older versions) for security reasons.

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

Running: C:\Users\experimental user\Desktop\TAOT\exp_1dB\

3527.9022 INFO Loaded monitor calibration from [‘2020_01_29 00:44’]
3527.9426 INFO C:\Program Files\PsychoPy\pythonw.exe -m psychopy.scripts.psyexpCompile C:\Users\experimental user\Desktop\TAOT\exp_1dB\taot_exp_builtin_lab_bk.psyexp -o C:\Users\experimental user\Desktop\TAOT\exp_1dB\ -v 1.90.0
pygame 1.9.6
Hello from the pygame community. Contribute - pygame wiki
Traceback (most recent call last):
File “C:\Users\experimental user\Desktop\TAOT\exp_1dB\”, line 496, in
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\”, line 803, in stop
“Cannot stop a stream that has not been started.”)
psychopy.sound.exceptions.AudioStreamError: Cannot stop a stream that has not been started.

Experiment ended.

Hi There,

Please could you show us the settings of your mic component?


Hi Becca,

I managed to solve this by changing the point in which audio recordings are stored.

I realied that mic.stop() was happening twice in my script (I don’t know how because I didn’t build any custom script, just used builder components), so the second time psychopy was trying to close a microphone component there was nothing to close and it would crash.

So I commented the second mic close and moved the audio file creation to right before mic.stop(), and now it works just fine.

Thank you for your help!


So pleased you fixed it and thanks for sharing your solution!

1 Like

Hi Jose,

I’m having the same problem getting my recordings to save. Do you mind sharing your code? I’ve commented out the second mic.stop() like you did and that solved the error message, but I’m still having issues storing the recordings. Thanks!


It is possible to stop a recording that is in progress by using a code component. Every frame, check for a condition (such as key ‘q’, or a mouse click), and call the .stop() method of the microphone component. The recording will end at that point and be saved. For example, if mic is the name of your microphone component, then in the code component, do this on Each frame :

if event.getKeys([‘q’]):

Hi jessieq,

I moved the highlighted chunk of code below (i.e., the one used to store the files of the recordings) from the last mic.stop() instance in the script to right before the mic.stop() that I wanted to use as actual microphone stop and record.

if mic_1.status == NOT_STARTED and sound_1.status==FINISHED:
# keep track of start time/frame for later
mic_1.frameNStart = frameN # exact frame index
mic_1.tStart = t # local t and not account for scr refresh
mic_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(mic_1, ‘tStartRefresh’) # time at next scr refresh
# start recording with mic_1
mic_1.status = STARTED
if mic_1.status == STARTED:
# update recorded clip for mic_1
if mic_1.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > mic_1.tStartRefresh + mic_time-frameTolerance:
# keep track of stop time/frame for later
mic_1.tStop = t # not accounting for scr refresh
mic_1.frameNStop = frameN # exact frame index
win.timeOnFlip(mic_1, ‘tStopRefresh’) # time at next scr refresh
# save mic_1 recordings
for tag in mic_1.clips:
for i, clip in enumerate(mic_1.clips[tag]):, ‘recording_mic_1_%s_%s.wav’ % (tag, i)))
# stop recording with mic_1
mic_1.status = FINISHED

I hope this helps!

Best wishes,