diff options
Diffstat (limited to 'Scripts')
| -rw-r--r-- | Scripts/steamvr.py | 27 | ||||
| -rw-r--r-- | Scripts/transcribe.py | 21 |
2 files changed, 33 insertions, 15 deletions
diff --git a/Scripts/steamvr.py b/Scripts/steamvr.py index ed4150c..c231184 100644 --- a/Scripts/steamvr.py +++ b/Scripts/steamvr.py @@ -9,6 +9,15 @@ EVENT_NONE = 0 EVENT_RISING_EDGE = 1 EVENT_FALLING_EDGE = 2 +hands = {} +hands["left"] = vr.TrackedControllerRole_LeftHand +hands["right"] = vr.TrackedControllerRole_RightHand + +buttons = {} +buttons["a"] = vr.k_EButton_IndexController_A +buttons["b"] = vr.k_EButton_IndexController_B +buttons["joystick"] = vr.k_EButton_Axis0 + class SessionState: def __init__(self): self.system = vr.init(vr.VRApplication_Background) @@ -24,11 +33,11 @@ class SessionState: # 2 - button falling edge def pollButtonPress( session_state: SessionState, - controller: vr.ETrackedControllerRole = vr.TrackedControllerRole_LeftHand, - button: vr.EVRButtonId = vr.k_EButton_Axis0 + hand_id: vr.ETrackedControllerRole = hands["left"], + button_id: vr.EVRButtonId = buttons["joystick"], ) -> int: - lh_idx = session_state.system.getTrackedDeviceIndexForControllerRole(vr.TrackedControllerRole_LeftHand) - #print("Left hand device idx: {}".format(lh_idx)) + lh_idx = session_state.system.getTrackedDeviceIndexForControllerRole(hand_id) + #print("left hand device idx: {}".format(lh_idx)) got_state, state = session_state.system.getControllerState(lh_idx) if not got_state: @@ -41,13 +50,11 @@ def pollButtonPress( # differentiate movement from clicking, we create a dead zone: if the event # fires while the stick isn't moved far from center, we assume it's a # click, not movement. - dead_zone_radius = 0.5 + dead_zone_radius = 0.7 - # This is the ID of event for the joystick being clicked. - joy_click = vr.k_EButton_Axis0 - joy_click_mask = (1 << joy_click) + button_mask = (1 << button_id) ret = EVENT_NONE - if (state.ulButtonPressed & joy_click_mask) != 0 and\ + if (state.ulButtonPressed & button_mask) != 0 and\ (state.rAxis[0].x**2 + state.rAxis[0].y**2 < dead_zone_radius**2): #print("button pressed: %016x" % state.ulButtonPressed) #for i in range(0, 5): @@ -65,7 +72,7 @@ if __name__ == "__main__": while True: time.sleep(0.1) - event = pollButtonPress(session_state) + event = pollButtonPress(session_state, hand_id = hands["left"], button_id = buttons["joystick"]) if event == EVENT_RISING_EDGE: print("rising edge") elif event == EVENT_FALLING_EDGE: diff --git a/Scripts/transcribe.py b/Scripts/transcribe.py index 1237334..f452b2c 100644 --- a/Scripts/transcribe.py +++ b/Scripts/transcribe.py @@ -317,7 +317,8 @@ def sendAudio(audio_state, use_builtin: bool): # Pace this out time.sleep(0.01) -def readControllerInput(audio_state, enable_local_beep, use_builtin): +def readControllerInput(audio_state, enable_local_beep: bool, + use_builtin: bool, button: str): session = None first = True while session == None and audio_state.run_app == True: @@ -334,11 +335,15 @@ def readControllerInput(audio_state, enable_local_beep, use_builtin): osc_ctrl.indicateSpeech(audio_state.osc_state.client, False) osc_ctrl.indicatePaging(audio_state.osc_state.client, False) + hand_id = steamvr.hands[button.split()[0]] + button_id = steamvr.buttons[button.split()[1]] + last_rising = time.time() while audio_state.run_app == True: time.sleep(0.05) - event = steamvr.pollButtonPress(session) + event = steamvr.pollButtonPress(session, hand_id=hand_id, + button_id=button_id) if event == steamvr.EVENT_RISING_EDGE: last_rising = time.time() @@ -387,7 +392,8 @@ def readControllerInput(audio_state, enable_local_beep, use_builtin): # model should correspond to one of the Whisper models defined in # whisper/__init__.py. Examples: tiny, base, small, medium. def transcribeLoop(mic: str, language: str, model: str, - enable_local_beep: bool, use_cpu: bool, use_builtin: bool): + enable_local_beep: bool, use_cpu: bool, use_builtin: bool, + button: str): audio_state = getMicStream(mic) audio_state.language = whisper.tokenizer.TO_LANGUAGE_CODE[language] @@ -408,7 +414,7 @@ def transcribeLoop(mic: str, language: str, model: str, send_audio_thd.daemon = True send_audio_thd.start() - controller_input_thd = threading.Thread(target = readControllerInput, args = [audio_state, enable_local_beep, use_builtin]) + controller_input_thd = threading.Thread(target = readControllerInput, args = [audio_state, enable_local_beep, use_builtin, button]) controller_input_thd.daemon = True controller_input_thd.start() @@ -452,6 +458,7 @@ if __name__ == "__main__": parser.add_argument("--window_duration_s", type=int, help="The length in seconds of the audio recording handed to the transcription algorithm") parser.add_argument("--cpu", type=int, help="If set to 1, use CPU instead of GPU") parser.add_argument("--use_builtin", type=int, help="If set to 1, use the text box built into the game.") + parser.add_argument("--button", type=str, help="The controller button used to start/stop transcription. E.g. \"left joystick\"") args = parser.parse_args() if not args.mic: @@ -471,6 +478,10 @@ if __name__ == "__main__": print("--rows and --cols required", file=sys.stderr) sys.exit(1) + if not args.button: + print("--button required", file=sys.stderr) + sys.exit(1) + if args.window_duration_s: config.MAX_LENGTH_S = int(args.window_duration_s) @@ -490,5 +501,5 @@ if __name__ == "__main__": generate_utils.config.BOARD_COLS = int(args.cols) transcribeLoop(args.mic, args.language, args.model, args.enable_local_beep, - args.cpu, args.use_builtin) + args.cpu, args.use_builtin, args.button) |
