Problem to import PyAudio C module from pyaudio._portaudio
Hello,
I am developing an experiment where I want to record participants vocal responses. I am using the following code (see attached) but it comes back with an error, namely "could not import PyAudio C module from pyaudio_portaudio". Any assistance would be very much appreciated.
Operating system: win32
Opensesame: 3.3.11
python: 3.7.6
code
--------------------------------------------------------------------------------------------------------------------------
import pyaudio
import wave
import os
chunk = 1024 # Record in chunks of 1024 samples
sample_format = pyaudio.paInt16 # 16 bits per sample
channels = 1
fs = 44100 # Record at 44100 samples per second
seconds = 3
output_folder = 'C:\\Users\\User\\Desktop\\test_file'
filename = os.path.join(output_folder, f"{trial}.wav")
p = pyaudio.PyAudio() # Create an interface to PortAudio
# Open the mic
stream = p.open(format=sample_format,
channels=channels,
rate=fs,
frames_per_buffer=chunk,
input=True,
output=True)
frames = [] # Initialize array to store frames
# Store data in chunks for 3 seconds
for i in range(0, int(fs / chunk * seconds)):
data = stream.read(chunk)
frames.append(data)
# Stop and close the stream
stream.stop_stream()
stream.close()
# Terminate the PortAudio interface
p.terminate()
------------------------------------------------------------------------------------------------------------------
Thank you in advance.
Best,
Effie
Comments
Hi Effie,
Is this maybe something you could try:
?
Eduard
Hi Eduard,
Thank you for your reply, after looking into different threads on this matter, I installed OpenseSame v4.0 and finally worked!
Thank you again for your time.