def __init__(self): output_device = 'Apple Inc.: Built-in Output' output_device_idx = None dac = rt.RtAudio() n_devices = dac.getDeviceCount() for i in range(n_devices): info = dac.getDeviceInfo(i) #print(info) if info['name'] == output_device: output_device_idx = i self.buffer_size = 256 oParams = { 'deviceId': output_device_idx, 'nChannels': 2, 'firstChannel': 0 } dac.openStream(oParams, {}, 44100, self.buffer_size, self.callback) dac.startStream() self._idx = 0 t0 = time.time() while True: if time.time() - t0 > 2: break try: dac.stopStream() except: pass if dac.isStreamOpen(): dac.closeStream()
def __init__(self): input_device = 'Apple Inc.: Built-in Microphone' dac = rt.RtAudio() input_device_idx = None n_devices = dac.getDeviceCount() for i in range(n_devices): info = dac.getDeviceInfo(i) #print(info) if info['name'] == input_device: input_device_idx = i print(input_device_idx) self.buffer_size = 512 oParams = { 'deviceId': input_device_idx, 'nChannels': 1, 'firstChannel': 0 } dac.openStream({}, oParams, 48000, self.buffer_size, self.callback) dac.startStream() self.data = [] t0 = time.time() while True: if time.time() - t0 > 2: break try: dac.stopStream() except: pass if dac.isStreamOpen(): dac.closeStream()
samples = 0.5*np.cos(self.phase * self.freq) # Ensure result is the right size! assert samples.shape[0] == 256 assert samples.dtype == np.float32 # Use numpy array view to do a once-copy into memoryview # (ie. we only do a single byte-wise copy of the final # result into 'playback') usamples = samples.view(dtype=np.uint8) playback_array = np.array(playback, copy=False) np.copyto(playback_array, usamples) except ModuleNotFoundError: print('Numpy not available, using struct.') dac = rt.RtAudio() n = dac.getDeviceCount() print('Number of devices available: ', n) for i in range(n): try: print(dac.getDeviceInfo(i)) except rt.RtError as e: print(e) print('Default output device: ', dac.getDefaultOutputDevice()) print('Default input device: ', dac.getDefaultInputDevice()) print('is stream open: ', dac.isStreamOpen())
#from pk.audio import media import rtaudio #wav = media.SndFile("/Users/jwp/ppDemos/BART/bang.wav") dev = rtaudio.RtAudio() print dev