earshot-cli 0.9.0__tar.gz → 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/PKG-INFO +3 -1
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/README.md +2 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/pyproject.toml +1 -1
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/cli.py +41 -11
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/config.py +31 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/transcribe.py +12 -2
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_live.py +18 -5
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_wizard.py +32 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/uv.lock +1 -1
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/.github/workflows/ci.yml +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/.github/workflows/publish.yml +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/.gitignore +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/LICENSE +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/scripts/download_models.sh +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/__init__.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/auth.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/capture.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/compose.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/deliver.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/extract.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/hardsub.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/live.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/models.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/subtitle.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/src/earshot/transcribe_cloud.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/conftest.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_auth.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_compose.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_config.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_credential_lifecycle.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_deliver.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_deliver_api.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_do_deliver.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_extract.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_hardsub.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_me.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_subtitle.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.11.0}/tests/test_ua.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: earshot-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: 媒体剪藏:视频字幕/系统声听录/本地音频/硬字幕OCR 四路摄入,端侧转写 → Markdown → 投递知识库(默认 ExoMind,可插拔)
|
|
5
5
|
Project-URL: Homepage, https://github.com/helloworldtang/earshot
|
|
6
6
|
Project-URL: Repository, https://github.com/helloworldtang/earshot
|
|
@@ -225,6 +225,8 @@ earshot clean --days 30
|
|
|
225
225
|
|
|
226
226
|
常用参数:`--title`(默认取首句截断40字)、`--tag`(可多次)、`--note`(来源备注写入脚注)、
|
|
227
227
|
`--engine server`(改走云端 dashscope 转写,复用 `~/.exomind/config.json` 凭据)、
|
|
228
|
+
`--lang`(listen/audio 本地转写语种,默认 `zh`;纯外语音频才用 `auto` —— 逐段自动判语种
|
|
229
|
+
在旁听切出的超短片段上会把中文误判成日/韩)、
|
|
228
230
|
`--deliver webhook --webhook <url>`(投递到任意知识库,POST JSON `{origin,title,content,tags}`)、
|
|
229
231
|
`--deliver none`(只落 `~/.earshot/outbox/` 存档)。
|
|
230
232
|
|
|
@@ -190,6 +190,8 @@ earshot clean --days 30
|
|
|
190
190
|
|
|
191
191
|
常用参数:`--title`(默认取首句截断40字)、`--tag`(可多次)、`--note`(来源备注写入脚注)、
|
|
192
192
|
`--engine server`(改走云端 dashscope 转写,复用 `~/.exomind/config.json` 凭据)、
|
|
193
|
+
`--lang`(listen/audio 本地转写语种,默认 `zh`;纯外语音频才用 `auto` —— 逐段自动判语种
|
|
194
|
+
在旁听切出的超短片段上会把中文误判成日/韩)、
|
|
193
195
|
`--deliver webhook --webhook <url>`(投递到任意知识库,POST JSON `{origin,title,content,tags}`)、
|
|
194
196
|
`--deliver none`(只落 `~/.earshot/outbox/` 存档)。
|
|
195
197
|
|
|
@@ -24,14 +24,14 @@ from earshot.compose import (
|
|
|
24
24
|
outbox_path,
|
|
25
25
|
render_markdown,
|
|
26
26
|
)
|
|
27
|
-
from earshot.config import DEFAULT_EXOMIND_BASE_URL, Settings, load_settings
|
|
27
|
+
from earshot.config import DEFAULT_EXOMIND_BASE_URL, Settings, load_settings, load_state, save_state
|
|
28
28
|
from earshot.deliver import DeliveryResult, deliver_exomind, deliver_exomind_api, deliver_webhook
|
|
29
29
|
from earshot.extract import ExtractError, ffmpeg_available, to_wav16k, wav_duration
|
|
30
30
|
from earshot.hardsub import FrameOcr, HardsubError, download_video, extract_hardsub, is_url, make_rapidocr_engine
|
|
31
31
|
from earshot.live import LiveSession
|
|
32
32
|
from earshot.models import ensure_models
|
|
33
33
|
from earshot.subtitle import SubtitleError, fetch_video_note
|
|
34
|
-
from earshot.transcribe import LocalTranscriber, Segment, TranscribeError
|
|
34
|
+
from earshot.transcribe import DEFAULT_LANG, SENSE_VOICE_LANGS, LocalTranscriber, Segment, TranscribeError
|
|
35
35
|
from earshot.transcribe_cloud import CloudTranscribeError, transcribe_cloud
|
|
36
36
|
|
|
37
37
|
EXIT_OK = 0
|
|
@@ -60,6 +60,15 @@ def _add_common(p: argparse.ArgumentParser) -> None:
|
|
|
60
60
|
p.add_argument("-y", "--yes", action="store_true", help="跳过内容确认,直接投递")
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
def _add_lang(p: argparse.ArgumentParser) -> None:
|
|
64
|
+
p.add_argument(
|
|
65
|
+
"--lang",
|
|
66
|
+
choices=SENSE_VOICE_LANGS,
|
|
67
|
+
default=DEFAULT_LANG,
|
|
68
|
+
help="转写语种(默认 zh;auto 逐段自动判,实时旁听短段会把中文误判成日/韩)",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
63
72
|
def build_parser() -> argparse.ArgumentParser:
|
|
64
73
|
parser = argparse.ArgumentParser(prog="earshot", description="媒体剪藏:听到看到的都能进知识库")
|
|
65
74
|
parser.add_argument("--version", action="version", version=f"earshot {__version__}")
|
|
@@ -68,9 +77,11 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
68
77
|
p_listen = sub.add_parser("listen", help="录系统声音(Ctrl-C=完成),转写并投递")
|
|
69
78
|
_add_common(p_listen)
|
|
70
79
|
p_listen.add_argument("--device", help="采集设备名子串(默认:默认扬声器的环回)")
|
|
80
|
+
_add_lang(p_listen)
|
|
71
81
|
|
|
72
82
|
p_audio = sub.add_parser("audio", help="转写已有音视频文件并投递")
|
|
73
83
|
_add_common(p_audio)
|
|
84
|
+
_add_lang(p_audio)
|
|
74
85
|
p_audio.add_argument("file", type=Path, nargs="?", help="音视频文件路径(缺省时交互询问)")
|
|
75
86
|
|
|
76
87
|
p_video = sub.add_parser("video", help="B站等视频链接直拉字幕入库(无噪音路线)")
|
|
@@ -78,7 +89,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
78
89
|
p_video.add_argument("url", nargs="?", help="视频链接(B站等 yt-dlp 支持的平台;缺省时交互询问)")
|
|
79
90
|
p_video.add_argument(
|
|
80
91
|
"--cookies-from-browser",
|
|
81
|
-
help="浏览器名(chrome/safari/firefox/edge)
|
|
92
|
+
help="浏览器名(chrome/safari/firefox/edge;none=匿名)。拉 AI 字幕(ai-zh)通常需要登录态;选择会被记住",
|
|
82
93
|
)
|
|
83
94
|
|
|
84
95
|
p_ocr = sub.add_parser("ocr", help="硬字幕视频 OCR 提取(字幕烧在画面里、无音轨的场景)")
|
|
@@ -121,7 +132,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
121
132
|
return parser
|
|
122
133
|
|
|
123
134
|
|
|
124
|
-
def _transcribe(wav16k: Path, engine: str, settings: Settings) -> list[Segment]:
|
|
135
|
+
def _transcribe(wav16k: Path, engine: str, settings: Settings, lang: str = DEFAULT_LANG) -> list[Segment]:
|
|
125
136
|
"""按引擎转写,返回 Segment 列表(server 引擎按行造伪段)。"""
|
|
126
137
|
if engine == "server":
|
|
127
138
|
print("→ 云端转写中(经 exomind /transcribe,dashscope)…")
|
|
@@ -129,7 +140,7 @@ def _transcribe(wav16k: Path, engine: str, settings: Settings) -> list[Segment]:
|
|
|
129
140
|
return [Segment(0.0, 0.0, line.strip()) for line in text.splitlines() if line.strip()]
|
|
130
141
|
print("→ 本地转写中(VAD+SenseVoice)…")
|
|
131
142
|
ensure_models(settings.model_root) # 缺失则首次运行自动下载(hf-mirror)
|
|
132
|
-
transcriber = LocalTranscriber(settings.model_root)
|
|
143
|
+
transcriber = LocalTranscriber(settings.model_root, language=lang)
|
|
133
144
|
|
|
134
145
|
def _progress(frac: float) -> None:
|
|
135
146
|
print(f"\r→ 本地转写中… {frac * 100:3.0f}%", end="", flush=True)
|
|
@@ -257,7 +268,7 @@ def cmd_listen(args: argparse.Namespace, settings: Settings) -> int:
|
|
|
257
268
|
if args.engine == "local":
|
|
258
269
|
try:
|
|
259
270
|
ensure_models(settings.model_root)
|
|
260
|
-
transcriber = LocalTranscriber(settings.model_root)
|
|
271
|
+
transcriber = LocalTranscriber(settings.model_root, language=args.lang)
|
|
261
272
|
except (RuntimeError, TranscribeError) as e:
|
|
262
273
|
print(f"✗ {e}")
|
|
263
274
|
return EXIT_FAIL
|
|
@@ -348,7 +359,7 @@ def cmd_audio(args: argparse.Namespace, settings: Settings) -> int:
|
|
|
348
359
|
print(f"✗ {e}")
|
|
349
360
|
return EXIT_FAIL
|
|
350
361
|
try:
|
|
351
|
-
segments = _transcribe(wav16k, args.engine, settings)
|
|
362
|
+
segments = _transcribe(wav16k, args.engine, settings, lang=args.lang)
|
|
352
363
|
except (TranscribeError, CloudTranscribeError) as e:
|
|
353
364
|
print(f"✗ {e}")
|
|
354
365
|
return EXIT_FAIL
|
|
@@ -422,6 +433,28 @@ def _short_url(url: str, max_len: int = 60) -> str:
|
|
|
422
433
|
return base
|
|
423
434
|
|
|
424
435
|
|
|
436
|
+
def _resolve_cookies(raw: str | None, settings: Settings) -> str | None:
|
|
437
|
+
"""解析字幕登录态浏览器:显式旗标 > 上次的选择(落盘记忆)> 交互问一次。
|
|
438
|
+
|
|
439
|
+
高频路径上「回车=chrome」是每回都付的税,问过一次就记住;显式旗标永远是
|
|
440
|
+
最新信号,顺带更新记忆(none/n 表示匿名)。
|
|
441
|
+
"""
|
|
442
|
+
if raw is not None:
|
|
443
|
+
cookies = None if raw.lower() in ("n", "none") else raw
|
|
444
|
+
save_state(settings.home, cookies_browser=cookies or "")
|
|
445
|
+
return cookies
|
|
446
|
+
remembered = load_state(settings.home).get("cookies_browser")
|
|
447
|
+
if remembered is not None:
|
|
448
|
+
print(f"→ 字幕登录态:{remembered or '匿名'}(上次的选择;--cookies-from-browser <名|none> 可改)")
|
|
449
|
+
return remembered or None
|
|
450
|
+
if _interactive():
|
|
451
|
+
ans = _prompt("字幕登录态浏览器(拉 AI 字幕用;回车=chrome,输 n 匿名;记住,之后不再问)", default="chrome")
|
|
452
|
+
cookies = None if ans.lower() in ("n", "none") else ans
|
|
453
|
+
save_state(settings.home, cookies_browser=cookies or "")
|
|
454
|
+
return cookies
|
|
455
|
+
return None
|
|
456
|
+
|
|
457
|
+
|
|
425
458
|
def cmd_video(args: argparse.Namespace, settings: Settings) -> int:
|
|
426
459
|
url = args.url
|
|
427
460
|
if not url:
|
|
@@ -437,10 +470,7 @@ def cmd_video(args: argparse.Namespace, settings: Settings) -> int:
|
|
|
437
470
|
if not url:
|
|
438
471
|
print("✗ 未提供链接")
|
|
439
472
|
return EXIT_FAIL
|
|
440
|
-
cookies = args.cookies_from_browser
|
|
441
|
-
if cookies is None and _interactive():
|
|
442
|
-
ans = _prompt("字幕登录态浏览器(拉 AI 字幕用;回车=chrome,输 n 匿名)", default="chrome")
|
|
443
|
-
cookies = None if ans.lower() == "n" else ans
|
|
473
|
+
cookies = _resolve_cookies(args.cookies_from_browser, settings)
|
|
444
474
|
try:
|
|
445
475
|
meta, segments = fetch_video_note(url, cookies)
|
|
446
476
|
except SubtitleError as e:
|
|
@@ -18,6 +18,7 @@ EXOMIND_BASE_URL_ENV = "EXOMIND_BASE_URL"
|
|
|
18
18
|
|
|
19
19
|
DEFAULT_EXOMIND_BASE_URL = "https://exomind-api.ai-as.cn"
|
|
20
20
|
EXOMIND_CONFIG_FILENAME = ".exomind/config.json"
|
|
21
|
+
STATE_FILENAME = "state.json"
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
@dataclass(frozen=True, slots=True)
|
|
@@ -69,6 +70,36 @@ def load_settings(
|
|
|
69
70
|
)
|
|
70
71
|
|
|
71
72
|
|
|
73
|
+
def load_state(home: Path) -> dict[str, str]:
|
|
74
|
+
"""读取本地状态文件(``~/.earshot/state.json``),不存在或损坏时返回空 dict。
|
|
75
|
+
|
|
76
|
+
与 config 的区别:state 是 CLI 运行中产生的记忆(如上次的选择),可随时重建。
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
home: earshot 数据目录。
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
raw = json.loads((home / STATE_FILENAME).read_text(encoding="utf-8"))
|
|
83
|
+
except (OSError, ValueError):
|
|
84
|
+
return {}
|
|
85
|
+
if not isinstance(raw, dict):
|
|
86
|
+
return {}
|
|
87
|
+
return {k: v for k, v in raw.items() if isinstance(v, str)}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def save_state(home: Path, **kv: str) -> None:
|
|
91
|
+
"""合并写入本地状态文件(保留未涉及的键)。
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
home: earshot 数据目录。
|
|
95
|
+
**kv: 要写入的键值对(均为字符串)。
|
|
96
|
+
"""
|
|
97
|
+
state = load_state(home)
|
|
98
|
+
state.update(kv)
|
|
99
|
+
home.mkdir(parents=True, exist_ok=True)
|
|
100
|
+
(home / STATE_FILENAME).write_text(json.dumps(state, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
101
|
+
|
|
102
|
+
|
|
72
103
|
def load_exomind_config(path: Path | None = None) -> dict[str, str]:
|
|
73
104
|
"""读取 exomind CLI 的配置文件,不存在或损坏时返回空 dict。
|
|
74
105
|
|
|
@@ -14,6 +14,10 @@ from typing import Any
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
|
|
16
16
|
SAMPLE_RATE = 16000
|
|
17
|
+
# SenseVoice 支持的语种;auto=逐段自动判语种,实时旁听的超短片段上会把中文误判成
|
|
18
|
+
# 日/韩(zh↔ja↔ko 声学最易混,SenseVoice 已知问题),故默认钉死 zh 跳过语种分类。
|
|
19
|
+
SENSE_VOICE_LANGS = ("auto", "zh", "en", "ja", "ko", "yue")
|
|
20
|
+
DEFAULT_LANG = "zh"
|
|
17
21
|
VAD_WINDOW = 512 # silero 要求 512 样本/窗(16k 下 32ms)
|
|
18
22
|
MAX_SPEECH_RUN_S = 55.0 # 连续无停顿语音强制切段,防 VAD 60s buffer 溢出
|
|
19
23
|
MIN_SILENCE_S = 0.45 # 短于此的静音不算说完(挡住句中停顿)
|
|
@@ -42,16 +46,21 @@ class Segment:
|
|
|
42
46
|
class LocalTranscriber:
|
|
43
47
|
"""VAD 切段 + SenseVoice 批量识别,输入须为 16k mono wav。"""
|
|
44
48
|
|
|
45
|
-
def __init__(self, model_root: Path) -> None:
|
|
49
|
+
def __init__(self, model_root: Path, language: str = DEFAULT_LANG) -> None:
|
|
46
50
|
"""加载 ASR/VAD 模型。
|
|
47
51
|
|
|
48
52
|
Args:
|
|
49
53
|
model_root: 模型根目录,须含 ``asr/model.int8.onnx``、``asr/tokens.txt``、
|
|
50
54
|
``vad/silero_vad.onnx``(scripts/download_models.sh 产物)。
|
|
55
|
+
language: 转写语种,取值见 ``SENSE_VOICE_LANGS``。默认钉死 zh(跳过逐段
|
|
56
|
+
语种分类,根治短段日/韩误判);纯外语音频才用 auto。
|
|
51
57
|
|
|
52
58
|
Raises:
|
|
53
|
-
TranscribeError:
|
|
59
|
+
TranscribeError: 语种非法、模型缺失或初始化失败。
|
|
54
60
|
"""
|
|
61
|
+
if language not in SENSE_VOICE_LANGS:
|
|
62
|
+
msg = f"语种非法: {language}(可选 {'/'.join(SENSE_VOICE_LANGS)})"
|
|
63
|
+
raise TranscribeError(msg)
|
|
55
64
|
asr_model = model_root / "asr" / "model.int8.onnx"
|
|
56
65
|
tokens = model_root / "asr" / "tokens.txt"
|
|
57
66
|
vad_model = model_root / "vad" / "silero_vad.onnx"
|
|
@@ -66,6 +75,7 @@ class LocalTranscriber:
|
|
|
66
75
|
self._recognizer: Any = sherpa_onnx.OfflineRecognizer.from_sense_voice(
|
|
67
76
|
model=str(asr_model),
|
|
68
77
|
tokens=str(tokens),
|
|
78
|
+
language=language,
|
|
69
79
|
use_itn=True,
|
|
70
80
|
)
|
|
71
81
|
self._vad_model_config: Any = sherpa_onnx.VadModelConfig()
|
|
@@ -4,12 +4,14 @@ FakeVad 语义:每次 accept_waveform(= 一个 VAD 窗,512 样本)即闭一段,
|
|
|
4
4
|
段样本就是该窗 —— 与 silero 的真实闭合时机不同,但足以驱动核心循环。
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
from pathlib import Path
|
|
7
8
|
from typing import Any
|
|
8
9
|
|
|
9
10
|
import numpy as np
|
|
11
|
+
import pytest
|
|
10
12
|
|
|
11
13
|
from earshot.live import LiveSession
|
|
12
|
-
from earshot.transcribe import VAD_WINDOW, Segment, run_live
|
|
14
|
+
from earshot.transcribe import VAD_WINDOW, LocalTranscriber, Segment, TranscribeError, run_live
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
class _FakeSeg:
|
|
@@ -153,12 +155,23 @@ def test_live_session_error_surfaced_at_finalize() -> None:
|
|
|
153
155
|
def _decode(self, samples: np.ndarray) -> str:
|
|
154
156
|
raise RuntimeError("boom")
|
|
155
157
|
|
|
156
|
-
import pytest
|
|
157
|
-
|
|
158
|
-
from earshot.transcribe import TranscribeError
|
|
159
|
-
|
|
160
158
|
session = LiveSession(_Boom(), on_text=None)
|
|
161
159
|
session.start()
|
|
162
160
|
session.push(_windows(1))
|
|
163
161
|
with pytest.raises(TranscribeError):
|
|
164
162
|
session.finalize(timeout_s=10)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_local_transcriber_rejects_invalid_lang(tmp_path: Path) -> None:
|
|
166
|
+
"""语种拼错(如 jp)在模型检查前即被拒:给可行动报错,不触发模型下载。"""
|
|
167
|
+
with pytest.raises(TranscribeError, match="语种非法"):
|
|
168
|
+
LocalTranscriber(tmp_path, language="jp")
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_lang_flag_wired_on_local_routes() -> None:
|
|
172
|
+
"""--lang 挂在本地转写两路(listen/audio),默认 zh,auto 可显式选。"""
|
|
173
|
+
from earshot.cli import build_parser
|
|
174
|
+
|
|
175
|
+
parser = build_parser()
|
|
176
|
+
assert parser.parse_args(["listen"]).lang == "zh"
|
|
177
|
+
assert parser.parse_args(["audio", "x.mp3", "--lang", "auto"]).lang == "auto"
|
|
@@ -105,3 +105,35 @@ def test_run_pipeline_default_tag_follows_source(monkeypatch: pytest.MonkeyPatch
|
|
|
105
105
|
rc = cli._run_pipeline([Segment(0.0, 1.0, "内容")], meta, args, _settings())
|
|
106
106
|
assert rc == 0
|
|
107
107
|
assert captured["tags"] == ["视频字幕"]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _settings_home(home: Path) -> Settings:
|
|
111
|
+
return Settings(
|
|
112
|
+
home=home,
|
|
113
|
+
model_root=home / "models",
|
|
114
|
+
exomind_base_url="https://api.example.com",
|
|
115
|
+
exomind_api_key="",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_resolve_cookies_asks_once_then_remembers(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
120
|
+
"""交互问一次后落盘记忆:第二次起不再问,静默沿用上次选择。"""
|
|
121
|
+
settings = _settings_home(tmp_path)
|
|
122
|
+
monkeypatch.setattr(cli, "_interactive", lambda: True)
|
|
123
|
+
monkeypatch.setattr(cli, "_prompt", lambda *a, **k: "safari")
|
|
124
|
+
assert cli._resolve_cookies(None, settings) == "safari"
|
|
125
|
+
prompts: list[object] = []
|
|
126
|
+
monkeypatch.setattr(cli, "_prompt", lambda *a, **k: prompts.append(a) or "chrome")
|
|
127
|
+
assert cli._resolve_cookies(None, settings) == "safari" # 记忆生效
|
|
128
|
+
assert not prompts
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_resolve_cookies_explicit_none_overrides_and_persists(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
132
|
+
"""显式 --cookies-from-browser none 走匿名并覆盖记忆;之后无旗标也沿用匿名。"""
|
|
133
|
+
from earshot.config import load_state
|
|
134
|
+
|
|
135
|
+
settings = _settings_home(tmp_path)
|
|
136
|
+
monkeypatch.setattr(cli, "_interactive", lambda: True)
|
|
137
|
+
assert cli._resolve_cookies("none", settings) is None
|
|
138
|
+
assert load_state(settings.home)["cookies_browser"] == ""
|
|
139
|
+
assert cli._resolve_cookies(None, settings) is None # 匿名也被记住,且不再追问
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|