'Initialize a stream; this should be called by
:py:func:`PyAudio.open`. A stream can either be input, output,
or both.
:param PA_manager: A reference to the managing :py:class:`PyAudio`
instance
:param rate: Sampling rate
:param channels: Number of channels
:param format: Sampling size and format. See |PaSampleFormat|.
:param input: Specifies whether this is an input stream.
Defaults to ``False``.
:param output: Specifies whether this is an output stream.
Defaults to ``False``.
:param input_device_index: Index of Input Device to use.
Unspecified (or ``None``) uses default device.
Ignored if `input` is ``False``.
:param output_device_index:
Index of Output Device to use.
Unspecified (or ``None``) uses the default device.
Ignored if `output` is ``False``.
:param frames_per_buffer: Specifies the number of frames per buffer.
:param start: Start the stream running immediately.
Defaults to ``True``. In general, there is no reason to set
this to ``False``.
:param input_host_api_specific_stream_info: Specifies a host API
specific stream information data structure for input.
.. only:: pamac
See :py:class:`PaMacCoreStreamInfo`.
:param output_host_api_specific_stream_info: Specifies a host API
specific stream information data structure for output.
.. only:: pamac
See :py:class:`PaMacCoreStreamInfo`.
:param stream_callback: Specifies a callback function for
*non-blocking* (callback) operation.  Default is
``None``, which indicates *blocking* operation (i.e.,
:py:func:`Stream.read` and :py:func:`Stream.write`).  To use
non-blocking operation, specify a callback that conforms
to the following signature:
.. code-block:: python
callback(in_data,      # recorded data if input=True; else None
frame_count,  # number of frames
time_info,    # dictionary
status_flags) # PaCallbackFlags
``time_info`` is a dictionary with the following keys:
``input_buffer_adc_time``, ``current_time``, and
``output_buffer_dac_time``; see the PortAudio
documentation for their meanings.  ``status_flags`` is one
of |PaCallbackFlags|.
The callback must return a tuple:
.. code-block:: python
(out_data, flag)
``out_data`` is a byte array whose length should be the
(``frame_count * channels * bytes-per-channel``) if
``output=True`` or ``None`` if ``output=False``.  ``flag``
must be either :py:data:`paContinue`, :py:data:`paComplete` or
:py:data:`paAbort` (one of |PaCallbackReturnCodes|).
When ``output=True`` and ``out_data`` does not contain at
least ``frame_count`` frames, :py:data:`paComplete` is
assumed for ``flag``.
**Note:** ``stream_callback`` is called in a separate
thread (from the main thread).  Exceptions that occur in
the ``stream_callback`` will:
1. print a traceback on standard error to aid debugging,
2. queue the exception to be thrown (at some point) in
the main thread, and
3. return `paAbort` to PortAudio to stop the stream.
**Note:** Do not call :py:func:`Stream.read` or
:py:func:`Stream.write` if using non-blocking operation.
**See:** PortAudio\'s callback signature for additional
details: http://portaudio.com/docs/v19-doxydocs/portaudio_8h.html#a8a60fb2a5ec9cbade3f54a9c978e2710
:raise ValueError: Neither input nor output are set True.'

def __init__(self, PA_manager, rate, channels, format, input=False, output=False, input_device_index=None, output_device_index=None, frames_per_buffer=1024, start=True, input_host_api_specific_stream_info=None, output_host_api_specific_stream_info=None, stream_callback=None):

    if (not (input or output)):
        raise ValueError(('Must    specify    an    input    or    output    ' + 'stream.'))
    self._parent = PA_manager
    self._is_input = input
    self._is_output = output
    self._is_running = start
    self._rate = rate
    self._channels = channels
    self._format = format
    self._frames_per_buffer = frames_per_buffer
    arguments = {'rate': rate, 'channels': channels, 'format': format, 'input': input, 'output': output, 'input_device_index': input_device_index, 'output_device_index': output_device_index, 'frames_per_buffer': frames_per_buffer}
    if input_host_api_specific_stream_info:
        _l = input_host_api_specific_stream_info
        arguments['input_host_api_specific_stream_info'] = _l._get_host_api_stream_object()
    if output_host_api_specific_stream_info:
        _l = output_host_api_specific_stream_info
        arguments['output_host_api_specific_stream_info'] = _l._get_host_api_stream_object()
    if stream_callback:
        arguments['stream_callback'] = stream_callback
    self._stream = pa.open(**arguments)
    self._input_latency = self._stream.inputLatency
    self._output_latency = self._stream.outputLatency
    if self._is_running:
        pa.start_stream(self._stream)
