Howdy, Stranger!

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

Supported by

[Help needed] Callback function with Pyaudio implying unknown error

edited February 2016 in OpenSesame

Hello,

I'm trying to use the callback function of Pyaudio, unfortunally I keep getting an unknown error and I can't figure what is wrong with my code:

import pyaudio
import wave

def callback(in_data, frame_count, time_info, status):

wf.writeframes(in_data)

return (data, pyaudio.paContinue)

def sound_initiate():
#Initiate

global CHUNK
global RECORD_SECONDS
global RATE
global stream
global p
global WAVE_OUTPUT_FILENAME
global CHANNELS
global FORMAT
global frames
global wf   

CHUNK = 1024 
FORMAT = pyaudio.paInt16 #paInt8
CHANNELS = 1 
RATE = 44100 #sample rate
RECORD_SECONDS = 1
WAVE_OUTPUT_FILENAME = "C:\STROOP\output" + str(Trial) + ".wav"

#wf.writeframes(data)

p = pyaudio.PyAudio()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)   

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK,
                stream_callback=callback) 

#
stream.start_stream()

return

def sound_save():

stream.stop_stream()
stream.close()
p.terminate()
wf.close()

return

Basically, I call them with :

sound_initiate()
[my task]
sound_save()

Thanks

Comments

  • edited February 2016

    sorry :)

  • edited 12:04PM

    Hi there, Your problem appears to be more specific to pyaudio than to OpenSesame, it appears. I would try asking on one of its forums if someone can help you, as they probably have more experience than us with these kinds of issues involving pyaudio. A good idea for these kinds of scripts is also to see if you can make them run outside of OpenSesame, in pure python. This way you factor OpenSesame our of the equation and can see if is part of the problem or not. Good luck!

    Buy Me A Coffee

Sign In or Register to comment.