60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
||
"""Handy Windows 中文配置(SenseVoice + zh-Hans + Ctrl+1)。"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import os
|
||
from pathlib import Path
|
||
|
||
appdata = os.environ.get("APPDATA")
|
||
if not appdata:
|
||
raise SystemExit("未找到 APPDATA 环境变量")
|
||
|
||
base = Path(appdata) / "com.pais.handy"
|
||
settings_path = base / "settings_store.json"
|
||
models = base / "models"
|
||
|
||
if not settings_path.is_file():
|
||
raise SystemExit(
|
||
f"缺少配置文件:{settings_path}\n请先启动一次 Handy 生成配置后重跑安装脚本。"
|
||
)
|
||
|
||
if not (models / "sense-voice-int8").is_dir():
|
||
raise SystemExit(
|
||
"缺少 sense-voice-int8 模型,请先运行 handy_download_sensevoice.ps1"
|
||
)
|
||
|
||
pk = models / "parakeet-tdt-0.6b-v3-int8"
|
||
off = models / "_disabled_parakeet-tdt-0.6b-v3-int8"
|
||
if pk.is_dir() and not off.is_dir():
|
||
pk.rename(off)
|
||
|
||
data = json.loads(settings_path.read_text(encoding="utf-8"))
|
||
s = data.setdefault("settings", {})
|
||
|
||
s["selected_language"] = "zh-Hans"
|
||
s["app_language"] = "zh-Hans"
|
||
s["selected_model"] = "sense-voice-int8"
|
||
s["translate_to_english"] = False
|
||
s["post_process_enabled"] = False
|
||
s["ort_accelerator"] = "directml"
|
||
s["whisper_accelerator"] = "auto"
|
||
s["push_to_talk"] = True
|
||
s["autostart_enabled"] = False
|
||
s["mute_while_recording"] = False
|
||
s["paste_method"] = "ctrl_v"
|
||
s["external_script_path"] = None
|
||
|
||
b = s.setdefault("bindings", {}).setdefault(
|
||
"transcribe", {"id": "transcribe"}
|
||
)
|
||
b["current_binding"] = "control_left+1"
|
||
b["name"] = "语音转写"
|
||
b["description"] = "简体中文转写(SenseVoice)"
|
||
|
||
settings_path.write_text(
|
||
json.dumps(data, indent=2, ensure_ascii=False) + "\n",
|
||
encoding="utf-8",
|
||
)
|
||
print("OK 已写入: zh-Hans + sense-voice-int8 + Ctrl+1 + ctrl_v + directml")
|