Playback the recorded answer

Hello everyone,

I’m currently working at a microphone-testrun before the experiment starts.
I have just a poor knowledge about coding, so I don’t know how to adapt the code for my experiment.

I found this piece of Code, which must hold the answer for my problem:

def playback(self, block=True, loops=0, stop=False, log=True)

name = self.name + ‘.current_recording’
self.current_recording = backend_pyo.SoundPyo(
self.savedFile, name=name, loops=loops)
self.current_recording.play()
if block:
core.wait(self.duration * (loops + 1)) # set during record()

    if log and self.autoLog:
        if loops:
            msg = '%s: Playback: play %.3fs x %d (est) %s'
            vals = (self.loggingId, self.duration, loops + 1,
                    self.savedFile)
            logging.exp(msg % vals)
        else:
            msg = '%s: Playback: play %.3fs (est) %s'
            logging.exp(msg % (self.loggingId, self.duration,
                               self.savedFile))

It’s frome the psychopy-page itself (psychopy.microphone — PsychoPy v2021.1)

I just want the participate to speak a few words which get recorded and then get played immediately afterwards.

Has someone an idea?

Thanks for the help!

Hello there,

Is there a reason that you are using coder for this? There is a nice demo of this in Builder view (although it might not currently work on mac). You can find it under demos > word_naming

Thanks!
Becca

Hi,

sometimes the solution is so close, but feels so far.

Thanks a lot, that’s totally adequate for my experiment.

Marco

Very pleased to hear this is a solution for your experiment :slight_smile: please could you mark the solution for future forum users?

Thanks,
Becca

1 Like

Hi Becca,

I made it, to include this into my experiment.
But now I’m facing another strange error.
Sometimes, not every time, the experiment suddenly stops with saying:

11.2001 WARNING Starting Microphone but sound lib preference is set to be [‘PTB, pyo’]. Clashes might occur since ‘pyo’ is not preferred lib but is needed for Microphone
Pyo warning: Portmidi closed.

I tried a lot of different settings but I really don’t understand, what’s the problem.
When I change the prefences the Warnings differ, but the result is the same.

Hi There,

This is a warning rather than an error (i.e. it shouldn’t stop your experiment running) - it is basically saying pyo is the required sound library but PTB is the default ( probably because this is the most accurate for sound presentation timing ). In file > preferences> hardware> audio library, the order of those indicates which sound libraries are given precedence. In your case, PTB is positioned before pyo, switching the position should remove the error - but remind future you that you switched the setting!

Hope this helps,
Becca

Hello Becca,

I already tried to play around with various preferences. I also did, what u advised. But the result is the same. Psychopy shuts down but without a serious error-message.

I will see, if the online-version has the same issues.

Hi There this will not work online I am afraid since the microphone component does not exist yet in psychoJS - see here a list of what currently is and is not supported online Status of online options — PsychoPy v2021.1

Becca