yuanflow-cli 0.1.12 → 0.1.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuanflow-cli",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "YuanFlow API CLI and skill installer for supported AI coding agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,12 +25,19 @@ description: 仅当用户明确要求使用本地音视频转文字、本地转
25
25
 
26
26
  本 Skill 的脚本目录为当前 Skill 目录下的 `scripts/`。
27
27
 
28
- 默认目录:
28
+ 默认运行目录:
29
29
 
30
- - 模型保存目录:`scripts/models`
31
- - 任务缓存目录:`scripts/cache`
32
- - 抽取音频目录:`scripts/cache/audio`
33
- - 转写文本目录:`scripts/cache/transcripts`
30
+ - Windows:`%APPDATA%/YuanFlow/runtime_tools/local-transcribe`
31
+ - 其它系统:`~/.yuanflow/runtime_tools/local-transcribe`
32
+
33
+ 默认子目录:
34
+
35
+ - 模型保存目录:`<运行目录>/models`
36
+ - 任务缓存目录:`<运行目录>/cache`
37
+ - 抽取音频目录:`<运行目录>/cache/audio`
38
+ - 转写文本目录:`<运行目录>/cache/transcripts`
39
+
40
+ 虚拟环境仍创建在当前 Skill 的 `scripts/.venv`,不要全局安装依赖。
34
41
 
35
42
  在 YuanFlow 程序内置环境中,`skill_read` 返回的 `config.managed_skill_dir` 是当前 Skill 的真实目录。执行脚本时优先以这个目录为基准:
36
43
 
@@ -38,14 +45,14 @@ description: 仅当用户明确要求使用本地音视频转文字、本地转
38
45
  cd "<config.managed_skill_dir>\scripts"
39
46
  ```
40
47
 
41
- 不要把模型下载到用户桌面、项目根目录或系统临时目录。不要把模型文件打包进 Skill 或 npm 包。
48
+ 不要把模型下载到用户桌面、项目根目录或系统临时目录。不要把模型文件打包进 Skill 或 npm 包。Windows 下 FunASR/SentencePiece 对中文路径不稳定,所以不要强制把模型放到中文 Skill 安装目录下。
42
49
 
43
50
  ## 首次使用模型下载规则
44
51
 
45
52
  开始转写前先检查模型目录是否已经存在:
46
53
 
47
- - `scripts/models/SenseVoiceSmall`
48
- - `scripts/models/fsmn-vad`
54
+ - `<运行目录>/models/SenseVoiceSmall`
55
+ - `<运行目录>/models/fsmn-vad`
49
56
 
50
57
  如果这两个目录都存在且不为空,直接执行后续任务。
51
58
 
@@ -54,7 +61,7 @@ cd "<config.managed_skill_dir>\scripts"
54
61
  - SenseVoice:`iic/SenseVoiceSmall`
55
62
  - VAD:`iic/speech_fsmn_vad_zh-cn-16k-common-pytorch`
56
63
 
57
- 下载由 `modelscope.snapshot_download()` 完成,保存到 `scripts/models`。下载完成后继续转写。
64
+ 下载由 `modelscope.snapshot_download()` 完成,保存到 `<运行目录>/models`。下载完成后继续转写。
58
65
 
59
66
  ## 执行流程
60
67
 
@@ -71,15 +78,23 @@ cd "<config.managed_skill_dir>\scripts"
71
78
  在 `scripts/` 目录下创建虚拟环境并安装依赖:
72
79
 
73
80
  ```powershell
74
- python -m venv .venv
81
+ py -3.10 -m venv .venv
75
82
  .\.venv\Scripts\python.exe -m pip install -r requirements-transcribe.txt
76
83
  ```
77
84
 
85
+ 优先使用 Python 3.10,其次 3.11/3.12。不要优先使用 Python 3.13 或 3.14,因为 FunASR 依赖链里的部分包在这些版本上可能需要本地编译,容易出现 `editdistance` wheel build failed。Windows 上可以先运行 `py -0p` 查看可用版本。
86
+
87
+ `requirements-transcribe.txt` 必须包含 `funasr`、`modelscope`、`torch` 和 `torchaudio`。如果导入 `funasr` 时提示 `No module named 'torch'` 或 `No module named 'torchaudio'`,先补齐缺失依赖,再重新执行转写。
88
+
78
89
  视频转音频需要本机可用 `ffmpeg`。如果用户给的是视频且系统找不到 `ffmpeg`,先明确报告缺少 ffmpeg,不要伪造转写结果。
79
90
 
80
91
  ## 推荐调用方式
81
92
 
82
- 统一入口脚本:
93
+ 统一入口脚本。
94
+
95
+ 如果是在 YuanFlow 的 `execute_shell_command` 中执行,命令会先经过 Windows `cmd.exe`。当 Skill 目录或输入文件路径包含中文时,优先使用 PowerShell `-EncodedCommand`,避免中文路径被转义成 `\uXXXX` 后找不到目录。
96
+
97
+ 普通 PowerShell 里可以直接运行:
83
98
 
84
99
  ```powershell
85
100
  cd "<Skill目录>\scripts"
@@ -93,13 +108,27 @@ cd "<Skill目录>\scripts"
93
108
  .\.venv\Scripts\python.exe .\transcribe_media.py "C:\path\to\input.mp4"
94
109
  ```
95
110
 
111
+ YuanFlow Agent 工具调用时推荐生成 UTF-16LE base64 后执行:
112
+
113
+ ```powershell
114
+ $script = "Set-Location -LiteralPath '<Skill目录>\scripts'; .\.venv\Scripts\python.exe .\transcribe_media.py 'C:\path\to\input.mp3'"
115
+ $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script))
116
+ powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encoded
117
+ ```
118
+
119
+ 如果尚未创建虚拟环境,把 `$script` 改成:
120
+
121
+ ```powershell
122
+ Set-Location -LiteralPath '<Skill目录>\scripts'; if (-not (Test-Path -LiteralPath '.\.venv\Scripts\python.exe')) { py -3.10 -m venv .venv }; .\.venv\Scripts\python.exe -m pip install -r requirements-transcribe.txt; .\.venv\Scripts\python.exe .\transcribe_media.py 'C:\path\to\input.mp3'
123
+ ```
124
+
96
125
  常用参数:
97
126
 
98
127
  | 参数 | 说明 |
99
128
  | --- | --- |
100
129
  | `input_path` | 音频文件、视频文件或目录。 |
101
- | `--cache-root` | 缓存目录,默认 `scripts/cache`。 |
102
- | `--models-root` | 模型目录,默认 `scripts/models`。 |
130
+ | `--cache-root` | 缓存目录,默认 `<运行目录>/cache`。 |
131
+ | `--models-root` | 模型目录,默认 `<运行目录>/models`。 |
103
132
  | `--recursive` | 输入为目录时递归扫描。 |
104
133
  | `--device` | `auto`、`cpu`、`cuda:0` 等,默认 `auto`。 |
105
134
  | `--language` | `zh`、`en`、`yue`、`ja`、`ko`、`auto`,默认 `auto`。 |
@@ -130,10 +159,10 @@ cd "<Skill目录>\scripts"
130
159
 
131
160
  只有用户明确要求删除缓存或模型文件时,才可以删除:
132
161
 
133
- - 缓存目录:`scripts/cache`
134
- - 模型目录:`scripts/models`
162
+ - 缓存目录:`<运行目录>/cache`
163
+ - 模型目录:`<运行目录>/models`
135
164
 
136
- 删除前必须确认目标路径位于当前 Skill `scripts/` 目录下,不能删除其它项目目录、用户桌面目录或系统目录。
165
+ 删除前必须确认目标路径位于 YuanFlow 本地转写运行目录下,不能删除其它项目目录、用户桌面目录、其它 Skill 或系统目录。
137
166
 
138
167
  ## 输出要求
139
168
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ import os
4
5
  import re
5
6
  from pathlib import Path
6
7
  from typing import Iterable
@@ -31,6 +32,13 @@ def ensure_dir(path: Path) -> Path:
31
32
  return path
32
33
 
33
34
 
35
+ def default_runtime_root() -> Path:
36
+ appdata = os.environ.get("APPDATA")
37
+ if appdata:
38
+ return Path(appdata) / "YuanFlow" / "runtime_tools" / "local-transcribe"
39
+ return Path.home() / ".yuanflow" / "runtime_tools" / "local-transcribe"
40
+
41
+
34
42
  def write_json(path: Path, data: object) -> Path:
35
43
  ensure_parent(path)
36
44
  path.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
  from common.media import extract_audio
7
7
  from common.sensevoice import build_model
8
8
  from common.sensevoice import clean_transcript
9
+ from common.utils import default_runtime_root
9
10
  from common.utils import ensure_dir
10
11
  from common.utils import is_audio_file
11
12
  from common.utils import is_video_file
@@ -15,8 +16,9 @@ from common.utils import write_text
15
16
 
16
17
 
17
18
  SCRIPT_DIR = Path(__file__).resolve().parent
18
- DEFAULT_CACHE_ROOT = SCRIPT_DIR / "cache"
19
- DEFAULT_MODELS_ROOT = SCRIPT_DIR / "models"
19
+ DEFAULT_RUNTIME_ROOT = default_runtime_root()
20
+ DEFAULT_CACHE_ROOT = DEFAULT_RUNTIME_ROOT / "cache"
21
+ DEFAULT_MODELS_ROOT = DEFAULT_RUNTIME_ROOT / "models"
20
22
 
21
23
 
22
24
  def prepare_audio(