Module pyaudio :: Class PyAudio
[frames] | no frames]

Class PyAudio

source code

Python interface to PortAudio. Provides methods to:

Use this class to open and close streams.

Instance Methods
 
__init__(self)
Initialize PortAudio.
source code
 
terminate(self)
Terminate PortAudio.
source code
    Stream Management
 
open(self, *args, **kwargs)
Open a new stream. See constructor for Stream.__init__ for parameter details.
source code
 
close(self, stream)
Close a stream. Typically use Stream.close instead.
source code
    Host API
int
get_host_api_count(self)
Return the number of PortAudio Host APIs.
source code
dict
get_default_host_api_info(self)
Return a dictionary containing the default Host API parameters. The keys of the dictionary mirror the data fields of PortAudio's PaHostApiInfo structure.
source code
dict
get_host_api_info_by_type(self, host_api_type)
Return a dictionary containing the Host API parameters for the host API specified by the host_api_type. The keys of the dictionary mirror the data fields of PortAudio's PaHostApiInfo structure.
source code
dict
get_host_api_info_by_index(self, host_api_index)
Return a dictionary containing the Host API parameters for the host API specified by the host_api_index. The keys of the dictionary mirror the data fields of PortAudio's PaHostApiInfo structure.
source code
dict
get_device_info_by_host_api_device_index(self, host_api_index, host_api_device_index)
Return a dictionary containing the Device parameters for a given Host API's n'th device. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
source code
    Device API
int
get_device_count(self)
Return the number of PortAudio Host APIs.
source code
bool
is_format_supported(self, rate, input_device=None, input_channels=None, input_format=None, output_device=None, output_channels=None, output_format=None)
Check to see if specified device configuration is supported. Returns True if the configuration is supported; throws a ValueError exception otherwise.
source code
dict
get_default_input_device_info(self)
Return the default input Device parameters as a dictionary. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
source code
dict
get_default_output_device_info(self)
Return the default output Device parameters as a dictionary. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
source code
dict
get_device_info_by_index(self, device_index)
Return the Device parameters for device specified in device_index as a dictionary. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
source code
    Stream Format Conversion
int
get_sample_size(self, format)
Returns the size (in bytes) for the specified sample format (a PaSampleFormat constant).
source code
PaSampleFormat
get_format_from_width(self, width, unsigned=True)
Returns a PortAudio format constant for the specified width.
source code
Method Details

terminate(self)

source code 
Terminate PortAudio.

Attention: Be sure to call this method for every instance of this object to release PortAudio resources.

get_sample_size(self, format)

source code 
Returns the size (in bytes) for the specified sample format (a PaSampleFormat constant).
Parameters:
Returns: int
Raises:
  • ValueError - Invalid specified format.

get_format_from_width(self, width, unsigned=True)

source code 
Returns a PortAudio format constant for the specified width.
Parameters:
  • width - The desired sample width in bytes (1, 2, 3, or 4)
  • unsigned - For 1 byte width, specifies signed or unsigned format.
Returns: PaSampleFormat
Raises:
  • ValueError - for invalid width

open(self, *args, **kwargs)

source code 
Open a new stream. See constructor for Stream.__init__ for parameter details.
Returns:
Stream

close(self, stream)

source code 
Close a stream. Typically use Stream.close instead.
Parameters:
  • stream - An instance of the Stream object.
Raises:
  • ValueError - if stream does not exist.

get_default_host_api_info(self)

source code 
Return a dictionary containing the default Host API parameters. The keys of the dictionary mirror the data fields of PortAudio's PaHostApiInfo structure.
Returns: dict
Raises:
  • IOError - if no default input device available

get_host_api_info_by_type(self, host_api_type)

source code 
Return a dictionary containing the Host API parameters for the host API specified by the host_api_type. The keys of the dictionary mirror the data fields of PortAudio's PaHostApiInfo structure.
Parameters:
Returns: dict
Raises:
  • IOError - for invalid host_api_type

get_host_api_info_by_index(self, host_api_index)

source code 
Return a dictionary containing the Host API parameters for the host API specified by the host_api_index. The keys of the dictionary mirror the data fields of PortAudio's PaHostApiInfo structure.
Parameters:
  • host_api_index - The host api index.
Returns: dict
Raises:
  • IOError - for invalid host_api_index

get_device_info_by_host_api_device_index(self, host_api_index, host_api_device_index)

source code 
Return a dictionary containing the Device parameters for a given Host API's n'th device. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
Parameters:
  • host_api_index - The Host API index number.
  • host_api_device_index - The n 'th device of the host API.
Returns: dict
Raises:
  • IOError - for invalid indices

is_format_supported(self, rate, input_device=None, input_channels=None, input_format=None, output_device=None, output_channels=None, output_format=None)

source code 
Check to see if specified device configuration is supported. Returns True if the configuration is supported; throws a ValueError exception otherwise.
Parameters:
  • rate - Specifies the desired rate (in Hz)
  • input_device - The input device index. Specify None (default) for half-duplex output-only streams.
  • input_channels - The desired number of input channels. Ignored if input_device is not specified (or None).
  • input_format - PortAudio sample format constant defined in this module
  • output_device - The output device index. Specify None (default) for half-duplex input-only streams.
  • output_channels - The desired number of output channels. Ignored if input_device is not specified (or None).
  • output_format - PortAudio sample format constant (PaSampleFormat).
Returns: bool
Raises:
  • ValueError - tuple containing: (error string, PortAudio error code PaErrorCode).

get_default_input_device_info(self)

source code 
Return the default input Device parameters as a dictionary. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
Returns: dict
Raises:
  • IOError - No default input device available.

get_default_output_device_info(self)

source code 
Return the default output Device parameters as a dictionary. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
Returns: dict
Raises:
  • IOError - No default output device available.

get_device_info_by_index(self, device_index)

source code 
Return the Device parameters for device specified in device_index as a dictionary. The keys of the dictionary mirror the data fields of PortAudio's PaDeviceInfo structure.
Parameters:
  • device_index - The device index.
Returns: dict
Raises:
  • IOError - Invalid device_index.