dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

microphone_selection.py (1751B)


      1 from talon import actions
      2 from talon import Module, actions, imgui, scripting, app
      3 from talon.microphone import manager
      4 from talon.lib import cubeb
      5 from talon import scripting
      6 
      7 ctx = cubeb.Context()
      8 mod = Module()
      9 
     10 
     11 def devices_changed(device_type):
     12     update_microphone_list()
     13 
     14 
     15 microphone_device_list = []
     16 
     17 
     18 def update_microphone_list():
     19     global microphone_device_list
     20     microphone_device_list = []
     21     for device in ctx.inputs():
     22         if str(device.state) == "DeviceState.ENABLED":
     23             microphone_device_list.append(device)
     24 
     25 
     26 @imgui.open()
     27 def gui(gui: imgui.GUI):
     28     gui.text("Select a Microphone")
     29     gui.line()
     30     for index, item in enumerate(microphone_device_list, 1):
     31         if gui.button("{}. {}".format(index, item.name)):
     32             actions.user.microphone_select(index)
     33 
     34 
     35 @mod.action_class
     36 class Actions:
     37     def microphone_selection_toggle():
     38         """"""
     39         if gui.showing:
     40             gui.hide()
     41         else:
     42             gui.show()
     43 
     44     def microphone_select(index: int):
     45         """Selects a micropohone"""
     46         # print(str(index) + " " + str(len(microphone_device_list)))
     47         if 1 <= index and index <= len(microphone_device_list):
     48             microphone = microphone_device_list[index - 1].name
     49             for item in manager.menu.items:
     50                 # print(item.name + " " + microphone)
     51                 if microphone in item.name:
     52                     # manager.menu_click(item)
     53                     actions.speech.set_microphone(item.name)
     54                     app.notify("Activating {}".format(item.name))
     55 
     56                     break
     57 
     58             gui.hide()
     59 
     60 
     61 ctx.register("devices_changed", devices_changed)
     62 
     63 
     64 def on_ready():
     65     update_microphone_list()
     66 
     67 
     68 app.register("ready", on_ready)
     69