Skip to content

Commit

Permalink
新增 可选项 通过注册表/按键判断是否语音输入中
Browse files Browse the repository at this point in the history
  • Loading branch information
H1DDENADM1N committed Dec 17, 2024
1 parent 6277816 commit 8024e93
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Binary file modified assets/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class ClientConfig:
# 方便调试
hint_while_recording_at_edit_position_powered_by_ahk = True # 是否启用 基于AHK的 输入光标位置的输入状态提示功能
hint_while_recording_at_cursor_position = True # 是否启用 跟随鼠标光标位置的新版输入状态提示功能
check_microphone_usage_by = "注册表" # "按键" 或 ”注册表“
# 默认通过监测注册表判断麦克风是否在被客户端使用进而确定是否在录音
# 如果设置了 `only_enable_microphones_when_pressed_record_shortcut = False`
# 会造成的鼠标光标旁边永远显示麦克风标志
# 将强制忽略此项设置使用 "按键"
# "按键" 是通过监测 `speech_recognition_shortcut` 状态是否按下进而推测是否在录音


enable_double_click_opposite_state = True # 是否启用,双击`录音键`临时转换 `简/繁` 体中文输出的功能
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

# 👀 最新更新

## 新增 可选项 通过注册表/按键判断是否语音输入中

## 新增 可选项 是否启用离在线翻译和状态提示
> start_online_translate_server = True # 启用在线翻译服务
> start_offline_translate_server = True # 启用离线翻译服务
Expand Down
24 changes: 24 additions & 0 deletions util/check_microphone_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import winreg
from pathlib import Path

from config import ClientConfig as Config


def read_qword_value(root_key, sub_path, value_name):
try:
Expand All @@ -22,6 +24,19 @@ def read_qword_value(root_key, sub_path, value_name):


def is_microphone_in_use():
if not Config.only_enable_microphones_when_pressed_record_shortcut:
return assume_by_keypress()
else:
match Config.check_microphone_usage_by:
case "注册表":
return check_by_registry()
case "按键":
return assume_by_keypress()
case _:
return check_by_registry()


def check_by_registry():
# Static variables
if not hasattr(is_microphone_in_use, "last_check_time"):
is_microphone_in_use.last_check_time = 0
Expand Down Expand Up @@ -61,6 +76,15 @@ def is_microphone_in_use():
return is_microphone_in_use.cached_result


def assume_by_keypress():
import keyboard

if keyboard.is_pressed(Config.speech_recognition_shortcut):
return True
else:
return False


def test():
while True:
time.sleep(0.1)
Expand Down

0 comments on commit 8024e93

Please sign in to comment.