How to use PsychPortAudio function

OS Win10
PsychoPy version v2021.2.3
Standard Standalone? yes
Flagged previous post for deletion to follow the forum rules.

Using the PTB sound backend, I have made a sound using the following code in the Begin Routine tab:

snd = sound.backend_ptb.SoundPTB(value=new_pitch_list[cur_new], secs=durlist[cur_dur], stereo=-1, volume=1.0,
loops=0, sampleRate=48000, blockSize=4800,
preBuffer=-1, hamming=True, stopTime=(),
name=‘Tone’, autoLog=True, syncToWin=None)
snd.play()
core.wait(0)

I need to make the sound in the Begin Routine so it works with my duration list (defines the duration, standard (800ms) vs target (1120ms)) and pitch list (defines the frequency, either 500, 625, 750, 875 Hz) that I make in a Routine before this.

What’s the problem?
Doing it like this seemingly opens a new audio device every time the routine is run through (255 times per block). As such, when the block ends I need to be able to close the audio devices that are open (or the experiment will crash during the fifth block every time). To do this I understand that I need to use PsychPortAudio sub-function from Pyschtoolbox. However, each time I try to implement PsychPortAudio I get an error telling me PsychPortAudio is not defined, even when I follow the source code instructions.

Can someone help me understand how to use the PsychPortAudio so I can successfully close the audio devices after each block? This is really holding up my thesis experiment so I’d be really grateful for any help or insight!