def read(self, num_frames): """ Read samples from the stream. Do not call when using *non-blocking* mode. :param num_frames: The number of frames to read. :raises IOError: if stream is not an input stream or if the read operation was unsuccessful. :rtype: string """ if not self._is_input: raise IOError("Not input stream", paCanNotReadFromAnOutputOnlyStream) return pa.read_stream(self._stream, num_frames)
def read(self, num_frames, exception_on_overflow=True): """ Read samples from the stream. Do not call when using *non-blocking* mode. :param num_frames: The number of frames to read. :param exception_on_overflow: Specifies whether an IOError exception should be thrown (or silently ignored) on input buffer overflow. Defaults to True. :raises IOError: if stream is not an input stream or if the read operation was unsuccessful. :rtype: string """ if not self._is_input: raise IOError("Not input stream", paCanNotReadFromAnOutputOnlyStream) return pa.read_stream(self._stream, num_frames, exception_on_overflow)
def read(self, num_frames, should_warn=False): """ Read samples from the stream. Do not call when using *non-blocking* mode. :param num_frames: The number of frames to read. :param should_warn: Specifies whether a warning should be written to stderr (or silently ignored) on buffer overflow. Defaults to False. :raises IOError: if stream is not an input stream or if the read operation was unsuccessful. :rtype: string """ if not self._is_input: raise IOError("Not input stream", paCanNotReadFromAnOutputOnlyStream) return pa.read_stream(self._stream, num_frames, should_warn)
frames_per_buffer = chunk) stream_output = _portaudio.open(format = FORMAT, channels = CHANNELS, rate = RATE, output = True, frames_per_buffer = chunk) print "* starting stream" _portaudio.start_stream(stream_input) _portaudio.start_stream(stream_output) print "* recording" for i in range(0, 44100 / chunk * RECORD_SECONDS): data = _portaudio.read_stream(stream_input, chunk) _portaudio.write_stream(stream_output, data, chunk) print "* stopping stream" _portaudio.stop_stream(stream_input) _portaudio.stop_stream(stream_output) print "* closing stream" _portaudio.close(stream_input) _portaudio.close(stream_output) # match initialize() with terminate() calls _portaudio.terminate()
print "* initializing" _portaudio.initialize() print "* opening" stream = _portaudio.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, output = True, frames_per_buffer = chunk) print "* starting stream" _portaudio.start_stream(stream) print "* recording" for i in range(0, 44100 / chunk * RECORD_SECONDS): data = _portaudio.read_stream(stream, chunk) _portaudio.write_stream(stream, data, chunk) print "* stopping stream" _portaudio.stop_stream(stream) print "* closing stream" _portaudio.close(stream) # match all initialize() with terminate() calls _portaudio.terminate()