Skip to content

Commit

Permalink
play blocking in Jupiter/Colab notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMarc committed Jul 16, 2023
1 parent dff43a0 commit d8a3c19
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions slab/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
import slab.signal
from slab.signal import Signal
from slab.filter import Filter
from slab import _in_notebook

if _in_notebook:
from IPython.display import Audio, display

_tmpdir = pathlib.Path(tempfile.gettempdir()) # get a temporary directory for writing intermediate files
_calibration_intensity = 0 # difference between rms intensity and measured output intensity in dB
Expand Down Expand Up @@ -941,8 +945,8 @@ def play(self):
`play_file` method.
"""
if _in_notebook:
from IPython.display import Audio, display
display(Audio(self.data.T, rate=self.samplerate, autoplay=True))
time.sleep(self.duration) # playing in Jupiter/Colab notebook is non_blocking, thus busy-wait for stim duration
elif soundcard is not False:
soundcard.default_speaker().play(self.data, samplerate=self.samplerate)
else:
Expand All @@ -963,7 +967,6 @@ def play_file(filename):
if isinstance(filename, pathlib.Path):
filename = str(filename)
if _in_notebook:
from IPython.display import Audio, display
display(Audio(filename, autoplay=True))
elif _system == 'Windows':
winsound.PlaySound(filename, winsound.SND_FILENAME)
Expand Down

0 comments on commit d8a3c19

Please sign in to comment.