earshot-cli 0.10.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.10.0 → earshot_cli-0.11.0}/PKG-INFO +3 -1
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/README.md +2 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/pyproject.toml +1 -1
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/cli.py +16 -5
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/transcribe.py +12 -2
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_live.py +18 -5
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/uv.lock +1 -1
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/.github/workflows/ci.yml +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/.github/workflows/publish.yml +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/.gitignore +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/LICENSE +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/scripts/download_models.sh +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/__init__.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/auth.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/capture.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/compose.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/config.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/deliver.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/extract.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/hardsub.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/live.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/models.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/subtitle.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/src/earshot/transcribe_cloud.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/conftest.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_auth.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_compose.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_config.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_credential_lifecycle.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_deliver.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_deliver_api.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_do_deliver.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_extract.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_hardsub.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_me.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_subtitle.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_ua.py +0 -0
- {earshot_cli-0.10.0 → earshot_cli-0.11.0}/tests/test_wizard.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
|
|
|
@@ -31,7 +31,7 @@ from earshot.hardsub import FrameOcr, HardsubError, download_video, extract_hard
|
|
|
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站等视频链接直拉字幕入库(无噪音路线)")
|
|
@@ -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
|
|
@@ -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"
|
|
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
|
|
File without changes
|
|
File without changes
|