Sounddevice stop / close stream?

hi all – running a task where I need to re-run code with sound multiple times in succession, but noticing that even though on first run everything is fine / no errors, subsequent calls of the script throw no errors but play no sound. I am using sounddevice back-end because psychtoolbox makes my wav files sound grainy on linux, and I know I need to stop and close a SD stream so that linux can open a new one when I restart the task code. however, I’m not sure how to do that through psychopy – any help would be much appreciated!

can add code but as I mentioned it doesn’t throw errors, the stream just isn’t available. I know to win.close() and core.quit() at the end of psychopy scripts so I think I am looking for something like this for the sound as well. thank you!

Does anyone know of any solution for this? I am looking for a way to close/shutdown my audio device after each block. I use the sound.backend_ptb.SoundPTB audio device to create an audio tone, but I don’t know how to close/shutdown the this after each block.