Skip to content

Commit

Permalink
add an aplay function
Browse files Browse the repository at this point in the history
  • Loading branch information
rhelmot committed May 3, 2024
1 parent 8180609 commit cb157b5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sound/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy
import struct
import wave
import asyncio

import progressbar

Expand Down Expand Up @@ -53,6 +54,16 @@ def play(self, length: Optional[float]=None, progress=False):
data = self.render(length, progress)
sd.play(data, blocking=True)

async def aplay(self, length: Optional[float]=None):
"""
Play this signal. Block (but asyncio yield) until playback is complete.
If the given signal is infinitely long, default to three seconds of playback.
:param length: The length to play, in seconds. Optional.
"""
data = await asyncio.get_event_loop().run_in_executor(None, self.render, length, False)
sd

def play_async(self):
"""
Play this signal asynchronously. Return the `sounddevice` stream object for this playback.
Expand Down

0 comments on commit cb157b5

Please sign in to comment.