def _setSndFromArray(self, thisArray): """For pysoundcard all sounds are ultimately played as an array so other setSound methods are going to call this having created an arr """ self._callbacks = _PySoundCallbackClass(sndInstance=self) if defaultOutput is not None and type(defaultOutput) != int: devs = getDevices() if defaultOutput not in devs: raise ValueError("Attempted to set use device {!r} to " "a device that is not available".format(defaultOutput)) else: device = devs[defaultOutput]['id'] else: device = defaultOutput self._stream = soundcard.Stream(samplerate=self.sampleRate, device=device, blocksize=self.bufferSize, channels=1, callback=self._callbacks.fillBuffer) self._snd = self._stream chansIn, chansOut = self._stream.channels if chansOut > 1 and thisArray.ndim == 1: # make mono sound stereo self.sndArr = numpy.resize(thisArray, [2, len(thisArray)]).T else: self.sndArr = numpy.asarray(thisArray) self._nSamples = thisArray.shape[0] # set to run from the start: self.seek(0)
def _setSndFromArray(self, thisArray): """For pysoundcard all sounds are ultimately played as an array so other setSound methods are going to call this having created an arr """ self._callbacks = _PySoundCallbackClass(sndInstance=self) self._stream = soundcard.Stream(samplerate=self.sampleRate, blocksize=self.bufferSize, callback=self._callbacks.fillBuffer) self._snd = self._stream chansIn, chansOut = self._stream.channels if chansOut > 1 and thisArray.ndim == 1: # make mono sound stereo self.sndArr = numpy.resize(thisArray, [2, len(thisArray)]).T else: self.sndArr = numpy.asarray(thisArray) self._nSamples = thisArray.shape[0] # set to run from the start: self.seek(0)