Playing sounds in BCPy2000

Forum for software developers to discuss BCI2000 software development
Post Reply
abertomeu
Posts: 5
Joined: 20 Jan 2023, 04:23

Playing sounds in BCPy2000

Post by abertomeu » 01 Feb 2023, 05:42

Hi BCI2000 Community, I am here again :P .

I wanted to play a sound when specific cue appears on the screen. However, I don't known why my code did not work.
Here is my simple code:

Code: Select all

from BCPy2000.WavTools import PyAudioInterface

class BciApplication(BciGenericApplication):
	....
	
	def Preflight(self, sigprops):
		self.playerOnset = PyAudioInterface.player('./feedback-drums.WAV')
	
	def Transition(self, phase):
		if (pahse == 'cue'):
			self.playerOnset.play()
	...
I don't know if I am duing something wrong, can anyone help me?
Thanks in advance!

nluczak
Posts: 3
Joined: 20 Jan 2023, 17:22

Re: Playing sounds in BCPy2000

Post by nluczak » 01 Feb 2023, 13:17

Hi again!
You are using the legacy method of playing audio which relies on pygame to play sounds. And, as we no longer use pygame in favor of psychopy, you should be using Psychopy.audio. Thank you for posting this as I now realize the change was not documented, I will make sure to update our tutorials on the wiki.
Here is an example of how you may want to do it:

Code: Select all

class BciApplication(BciGenericApplication):
	....
	
	def Initialize(self, indim, outdim):
		from psychopy import sound
		self.mySound = sound.Sound('A')                      # this will play an A note
		# self.mySound = sound.Sound(900)                 # this will play an 900Hz noise
		# self.mySound = sound.Sound('/path/to/file') # this will play a specified sound file
	
	def Transition(self, phase):
		if phase == 'cue':
			self.mySound.play()
	...
I would also look at the PsychoPy documentation for more details on how they implemented their audio engine.

abertomeu
Posts: 5
Joined: 20 Jan 2023, 04:23

Re: Playing sounds in BCPy2000

Post by abertomeu » 02 Feb 2023, 04:04

Thanks again for your kick response. It works :D

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests