0

I am creating a fMRI Experiment with the Psychopy Libary in Phycharm and need to implement Sound from .wav files and play them.

This is my Code:

import numpy as np
from scipy.io.wavfile import read, write
from psychopy import prefs
prefs.hardware['audioLib'] = ['PTB']
from psychopy import sound

AMP = .1

audio_path = r'*PATH*/IRN_61.7354Hz.wav' #The Path where I saved the .wavfile
sr, data = read(audio_path)
data_1=data*(AMP/np.max(np.abs(data)))

acoustic_stim = sound.Sound(bytes(data_1),sr, stereo=True)
acoustic_stim.play(when=1)

#------------------------------------------------------------------------------ And I always get this Error: File "PATH", line 20, in acoustic_stim.play() File "PATH\venv\lib\site-packages\psychopy\sound\backend_ptb.py", line 544, in play self.track.start(repetitions=loops, when=when)

AttributeError: 'NoneType' object has no attribute 'start' #------------------------------------------------------------------------------ No Matter how i change this argument in acoustic_stim.play() i get the same error. i even tried to make something happen with creating a window and win.flip() but it doesn't work.

Fabian
  • 1
  • 1

1 Answers1

0

Okay, for anyone who is confronted with the same Problem here is the solution:

The sound.Sound(bytes(data_1),sr, stereo=True) command actually wants the Datapath of the Audio file as an argument for value. So this codes works:

import numpy as np
from scipy.io.wavfile import read, write
from psychopy import prefs
prefs.hardware['audioLib'] = ['PTB']
from psychopy import sound
AMP = .1

audio_path = r'*PATH*/IRN_61.7354Hz.wav' #The Path where I saved the .wavfile
sr, data = read(audio_path)
acoustic_stim = sound.Sound(value=audio_path,sampleRate=sr, 
stereo=True,volume=AMP)
acoustic_stim.play()
Fabian
  • 1
  • 1