Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

voice key recording

2»

Comments

  • yes, I reduced blank, time_out and self.sleep by half (so it should be 1 s in total), but it's 3 sec now. I believe it somehow has to do with the recording time.

    It's variable but as far as every trial is recorded, I dont care for some "blank" recording before or after the actual content.

  • Unfortunately your script is incompatible with my version of Opensesame (I can't install pyaudio, and you use python2, but I Python3), but from looking at your code, I have the hunch that the code:

    myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
    sd.wait() # Wait until recording is finished
    write('output.wav', fs, myrecording) # Save as WAV file 
    


    contributes to the delay. So basically, you are recording here for one second, before you even start the voice key loop. I think that part is redundant with this part:

    # Open the mic
    stream = pyaudio.PyAudio().open(
    	format=FORMAT,
    	channels=CHANNELS,
    	rate=RATE,
    	input=True,
    	input_device_index=0,
    	frames_per_buffer=INPUT_FRAMES_PER_BLOCK
    	)
    


    At least it is not clear what the difference between them is. They both seem to make a connection to a microphone and then record. Whereas Pyaudio seems to do it chunkwise, Sounddevice seems to do it in one block. Maybe it is possible with sounddevice to also record in blocks and blockwise check whether the loudness threshold was exceeded. Alternatively, you can use the Pyaudio code, to also write it to file. See for example here

    Does that make sense? Again, I can't test it myself, and I am not too familiar with audio recording so I might be completely wrong here.

    To check maybe, you can remove the sounddevice code, then you would have no file, but the presentation during should be accurate. Right?


    Eduard

    Buy Me A Coffee

  • yes, if it's not recording into a file, it is more or less accurate.


    I also think that i does the delay but I do not see how this piece of code


    stream = pyaudio.PyAudio().open(
    	format=FORMAT,
    	channels=CHANNELS,
    	rate=RATE,
    	input=True,
    	input_device_index=0,
    	frames_per_buffer=INPUT_FRAMES_PER_BLOCK
    	)
    


    would write into a file. :/ Sorry for the ignorant questions

  • That part only initializes the stream, the reading and writ should happen later.At that stage, if you don't know how exactly it works, it is a lot of trying out. You can check PyAudios documentation and what possibilities there are to write files. This link is also very useful. In general, I think you have to just try some things and play around until works. Like that you will also learn what all these words mean and how the script works. The script below, is my naive advice what could work, but without having pyaudio installed it is nothing more than a guess.

    # in the beginning of script
    import wave
    
    # after setting the parameters
    wavefile = wave.open(<filename>, 'wb')   
    wavefile.setnchannels(2)    
    wavefile.setsampwidth(self.pyaudio.PyAudio.get_sample_size(pyaudio.paInt16))
    wavefile.setframerate(44100)
    # in the while loop, add this extra line in the try/except part
    	try:
    		block = stream.read(chunk)
    		wavefile.writeframes(block)
    	except IOError as e:
    		print e
    
    # at the end of the script
    wavefile.close()
    

    Also, I won't be able to get back to you about this for the next week or so, so you are on your own a bit, but I am sure you are close to finishing it. Good luck!


    Eduard

    Buy Me A Coffee

  • Thanks a lot! I own you many coffees :D

  • Just of curiosity, did it work eventually?

    Eduard

    Buy Me A Coffee

  • edited July 2020

    Thanks for asking!

    In fact, I decided to record with a separate device after we realized that this recording would most probably interfere with timing which should be very precise in our experiment.

    I still havent figured out the VP-1 though :) this is to come.

Sign In or Register to comment.