Skip to content

Commit

Permalink
RF: Allow mic device to be set by index, give mic a settable status p…
Browse files Browse the repository at this point in the history
…roperty and allow blank audioclips to be appended (#3679)

Co-authored-by: Todd <TEParsons>
  • Loading branch information
TEParsons committed Mar 16, 2021
1 parent 1bae708 commit ae519ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions psychopy/sound/audioclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ def append(self, clip):
snd1.append(snd2)
"""
# if either clip is empty, just replace it
if len(self.samples) == 0:
return clip
if len(clip.samples) == 0:
return self

assert self.channels == clip.channels
assert self._sampleRateHz == clip.sampleRateHz

Expand Down
18 changes: 16 additions & 2 deletions psychopy/sound/microphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ def __init__(self,
"be installed.")

# get information about the selected device
devices = Microphone.getDevices()
if isinstance(device, AudioDeviceInfo):
self._device = device
elif isinstance(device, (int, float)):
devicesByIndex = {d.deviceIndex: d for d in devices}
if device in devicesByIndex:
self._device = devicesByIndex[device]
else:
raise AudioInvalidCaptureDeviceError(
'No suitable audio recording devices found matching index {}.'.format(device))
else:
# get default device, first enumerated usually
devices = Microphone.getDevices()

if not devices:
raise AudioInvalidCaptureDeviceError(
'No suitable audio recording devices found on this system. '
Expand Down Expand Up @@ -206,6 +212,14 @@ def bufferSecs(self):

@property
def status(self):
if hasattr(self, "_statusFlag"):
return self._statusFlag
@status.setter
def status(self, value):
self._statusFlag = value

@property
def streamStatus(self):
"""Status of the audio stream (`AudioDeviceStatus` or `None`).
See :class:`~psychopy.sound.AudioDeviceStatus` for a complete overview
Expand Down

0 comments on commit ae519ab

Please sign in to comment.