Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_default_device(self, category):
"""
Query the default audio devices.
:param category: Device category to query. Can be either input or output
:type category: str
"""
import sounddevice as sd
return sd.query_hostapis()[0].get('default_' + category.lower() + '_device')
def body(self, master):
ttk.Label(master, text='Select host API:').pack(anchor='w')
hostapi_list = ttk.Combobox(master, state='readonly', width=50)
hostapi_list.pack()
hostapi_list['values'] = [hostapi['name']
for hostapi in sd.query_hostapis()]
ttk.Label(master, text='Select sound device:').pack(anchor='w')
device_ids = []
device_list = ttk.Combobox(master, state='readonly', width=50)
device_list.pack()
def update_device_list(*args):
hostapi = sd.query_hostapis(hostapi_list.current())
nonlocal device_ids
device_ids = [
idx
for idx in hostapi['devices']
if sd.query_devices(idx)['max_output_channels'] > 0]
device_list['values'] = [
sd.query_devices(idx)['name'] for idx in device_ids]
default = hostapi['default_output_device']
def _get_default_device(category):
"""
Query the default audio devices.
:param category: Device category to query. Can be either input or output
:type category: str
"""
import sounddevice as sd
return sd.query_hostapis()[0].get('default_' + category.lower() + '_device')
def resfresh_device_list(self):
devices = sd.query_devices()
self.comboin.clear()
self.comboout.clear()
self.map_item_to_devicename = { 'input' : {},'output' : {} }
self.map_devicename_to_item = { 'input' : {},'output' : {} }
hostapi_names = [hostapi['name'] for hostapi in sd.query_hostapis()]
for i, dev in enumerate(devices):
hostapi_name = hostapi_names[dev['hostapi']]
if dev['max_input_channels']>=1:
self.comboin.addItem(u'{}: {} # HostAPI:{} # In:{} # Out:{}'.format(i, dev['name'], hostapi_name,
dev['max_input_channels'], dev['max_output_channels'],))
self.map_item_to_devicename['input'][self.comboin.count()-1] = dev['name']
self.map_devicename_to_item['input'][dev['name']] = self.comboin.count()-1
if dev['max_output_channels']>=1:
self.comboout.addItem(u'{}: {} # HostAPI:{} # In:{} # Out:{}'.format(i, dev['name'], hostapi_name,
dev['max_input_channels'], dev['max_output_channels'],))
self.map_item_to_devicename['output'][self.comboout.count()-1] = dev['name']
self.map_devicename_to_item['output'][dev['name']] = self.comboout.count()-1
def get_host_api_names():
"""Gets names of available host APIs in a list"""
return [hostapi['name'] for hostapi in sd.query_hostapis()]
def update_device_list(*args):
hostapi = sd.query_hostapis(hostapi_list.current())
nonlocal device_ids
device_ids = [
idx
for idx in hostapi['devices']
if sd.query_devices(idx)['max_output_channels'] > 0]
device_list['values'] = [
sd.query_devices(idx)['name'] for idx in device_ids]
default = hostapi['default_output_device']
if default >= 0:
device_list.current(device_ids.index(default))
device_list.event_generate('<>')