0

I am looking for a way to play a white noise using Psychopy. I tried the code below but it gives me an error message. I would very much appreciate it if anyone could teach me how to rectify the code. Thank you so much for your time!

from __future__ import division  # so that 1/3=0.333 instead of 1/3=0
from psychopy import visual, core, data, event, logging, sound, gui
import numpy as np

data = np.random.uniform(-1,1,44100)
white_noise = sound.Sound(0.99*data)
data.play()

I get an error message below.

Traceback (most recent call last):
File "white_noise.py", line 7, in <module>
data.play()
AttributeError: 'numpy.ndarray' object has no attribute 'play'
Exception TypeError: "'NoneType' object is not callable" in <bound method 
Server.__del__ of <pyolib.server.Server object at 0x0E54DD30>> ignored
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
T.O.
  • 47
  • 5

1 Answers1

2

Just putting my comment into an answer.

Try white_noise.play() instead of data.play().

According to Psyhchopy docs, the sound is just an Alias for https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound . Any functions defined there should also work here.

xrisk
  • 3,790
  • 22
  • 45
  • Thank you so much for your help Rishav! Now, it works perfectly :) – T.O. Jun 03 '18 at 02:38
  • psychopy.sound works for multiple backends, PyGame being one of them. PsychoPy is currently moving towards `sounddevice`, but the API should remain the same to the user. – Jonas Lindeløv Jun 04 '18 at 13:44