本文整理汇总了Python中pyaudio.PyAudio.get_host_api_info_by_index方法的典型用法代码示例。如果您正苦于以下问题:Python PyAudio.get_host_api_info_by_index方法的具体用法?Python PyAudio.get_host_api_info_by_index怎么用?Python PyAudio.get_host_api_info_by_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaudio.PyAudio
的用法示例。
在下文中一共展示了PyAudio.get_host_api_info_by_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AudioDevice
# 需要导入模块: from pyaudio import PyAudio [as 别名]
# 或者: from pyaudio.PyAudio import get_host_api_info_by_index [as 别名]
class AudioDevice(QtCore.QObject):
def __init__(self, logger):
QtCore.QObject.__init__(self)
self.logger = logger
self.duo_input = False
self.logger.push("Initializing PyAudio")
self.pa = PyAudio()
# look for devices
self.input_devices = self.get_input_devices()
self.output_devices = self.get_output_devices()
for device in self.input_devices:
self.logger.push("Opening the stream")
self.stream = self.open_stream(device)
self.device = device
self.logger.push("Trying to read from input device %d" % device)
if self.try_input_stream(self.stream):
self.logger.push("Success")
break
else:
self.logger.push("Fail")
self.first_channel = 0
nchannels = self.get_current_device_nchannels()
if nchannels == 1:
self.second_channel = 0
else:
self.second_channel = 1
# counter for the number of input buffer overflows
self.xruns = 0
# method
def get_readable_devices_list(self):
devices_list = []
default_device_index = self.get_default_input_device()
for device in self.input_devices:
dev_info = self.pa.get_device_info_by_index(device)
api = self.pa.get_host_api_info_by_index(dev_info
['hostApi'])['name']
if device is default_device_index:
extra_info = ' (system default)'
else:
extra_info = ''
nchannels = self.pa.get_device_info_by_index(device)[
'maxInputChannels']
desc = "%s (%d channels) (%s) %s" % (dev_info['name'],
nchannels, api, extra_info)
devices_list += [desc]
return devices_list
# method
def get_readable_output_devices_list(self):
devices_list = []
default_device_index = self.get_default_output_device()
for device in self.output_devices:
dev_info = self.pa.get_device_info_by_index(device)
api = self.pa.get_host_api_info_by_index(dev_info['hostApi']
)['name']
if device is default_device_index:
extra_info = ' (system default)'
else:
extra_info = ''
nchannels = self.pa.get_device_info_by_index(device)[
'maxOutputChannels']
desc = "%s (%d channels) (%s) %s" % (dev_info['name'], nchannels,
api, extra_info)
devices_list += [desc]
return devices_list
# method
def get_default_input_device(self):
return self.pa.get_default_input_device_info()['index']
# method
def get_default_output_device(self):
return self.pa.get_default_output_device_info()['index']
# method
def get_device_count(self):
# FIXME only input devices should be chosen, not all of them !
return self.pa.get_device_count()
#.........这里部分代码省略.........
示例2: AudioBackend
# 需要导入模块: from pyaudio import PyAudio [as 别名]
# 或者: from pyaudio.PyAudio import get_host_api_info_by_index [as 别名]
class AudioBackend(QtCore.QObject):
underflow = QtCore.pyqtSignal()
new_data_available_from_callback = QtCore.pyqtSignal(bytes, int, float, int)
new_data_available = QtCore.pyqtSignal(ndarray, float, int)
def callback(self, in_data, frame_count, time_info, status):
#do the minimum from here to prevent overflows, just pass the data to the main thread
input_time = time_info['input_buffer_adc_time']
# some API drivers in PortAudio do not return a valid time, so fallback to the current stream time
if input_time == 0.:
input_time = time_info['current_time']
if input_time == 0.:
input_time = self.stream.get_time()
self.new_data_available_from_callback.emit(in_data, frame_count, input_time, status)
return (None, 0)
def __init__(self, logger):
QtCore.QObject.__init__(self)
self.logger = logger
self.duo_input = False
self.logger.push("Initializing PyAudio")
self.pa = PyAudio()
# look for devices
self.input_devices = self.get_input_devices()
self.output_devices = self.get_output_devices()
self.device = None
self.first_channel = None
self.second_channel = None
# we will try to open all the input devices until one
# works, starting by the default input device
for device in self.input_devices:
self.logger.push("Opening the stream")
try:
self.stream = self.open_stream(device)
self.stream.start_stream()
self.device = device
self.logger.push("Success")
break
except:
self.logger.push("Fail")
if self.device is not None:
self.first_channel = 0
nchannels = self.get_current_device_nchannels()
if nchannels == 1:
self.second_channel = 0
else:
self.second_channel = 1
# counter for the number of input buffer overflows
self.xruns = 0
self.chunk_number = 0
self.new_data_available_from_callback.connect(self.handle_new_data)
def close(self):
self.stream.stop_stream()
self.stream.close()
self.stream = None
# method
def get_readable_devices_list(self):
devices_list = []
default_device_index = self.get_default_input_device()
for device in self.input_devices:
dev_info = self.pa.get_device_info_by_index(device)
api = self.pa.get_host_api_info_by_index(dev_info['hostApi'])['name']
if device is default_device_index:
extra_info = ' (system default)'
else:
extra_info = ''
nchannels = self.pa.get_device_info_by_index(device)['maxInputChannels']
desc = "%s (%d channels) (%s) %s" %(dev_info['name'], nchannels, api, extra_info)
devices_list += [desc]
return devices_list
# method
def get_readable_output_devices_list(self):
devices_list = []
default_device_index = self.get_default_output_device()
#.........这里部分代码省略.........