myagent-ai 1.23.49 → 1.23.50
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/core/stt.py +24 -1
- package/package.json +1 -1
package/core/stt.py
CHANGED
|
@@ -68,6 +68,29 @@ async def _stt_sensevoice(audio_data: bytes, audio_format: Optional[str] = None)
|
|
|
68
68
|
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
|
69
69
|
'models', 'sensevoice',
|
|
70
70
|
)
|
|
71
|
+
# [v1.23.49] 首次加载:将 ModelScope 缓存复制到本地 model_dir,后续不再联网
|
|
72
|
+
if not os.path.isdir(model_dir) or not os.listdir(model_dir):
|
|
73
|
+
import shutil
|
|
74
|
+
ms_cache = os.path.expanduser("~/.cache/modelscope/hub/models/iic/SenseVoiceSmall")
|
|
75
|
+
if os.path.isdir(ms_cache) and os.listdir(ms_cache):
|
|
76
|
+
os.makedirs(model_dir, exist_ok=True)
|
|
77
|
+
logger.info(f"复制 SenseVoice 模型: {ms_cache} -> {model_dir}")
|
|
78
|
+
# 复制模型文件(排除缓存元数据)
|
|
79
|
+
for item in os.listdir(ms_cache):
|
|
80
|
+
if item.endswith('.tmp') or item in ('.lock', '__pycache__'):
|
|
81
|
+
continue
|
|
82
|
+
src = os.path.join(ms_cache, item)
|
|
83
|
+
dst = os.path.join(model_dir, item)
|
|
84
|
+
if os.path.isdir(src):
|
|
85
|
+
if os.path.exists(dst):
|
|
86
|
+
shutil.rmtree(dst)
|
|
87
|
+
shutil.copytree(src, dst)
|
|
88
|
+
else:
|
|
89
|
+
shutil.copy2(src, dst)
|
|
90
|
+
else:
|
|
91
|
+
# ModelScope 缓存也没有,首次下载到本地
|
|
92
|
+
os.makedirs(model_dir, exist_ok=True)
|
|
93
|
+
logger.info("SenseVoice 模型首次下载到本地...")
|
|
71
94
|
_sensevoice_model = AutoModel(
|
|
72
95
|
model="iic/SenseVoiceSmall",
|
|
73
96
|
model_dir=model_dir,
|
|
@@ -75,7 +98,7 @@ async def _stt_sensevoice(audio_data: bytes, audio_format: Optional[str] = None)
|
|
|
75
98
|
disable_pbar=True,
|
|
76
99
|
disable_update=True,
|
|
77
100
|
)
|
|
78
|
-
logger.info("SenseVoice 模型已加载 (iic/SenseVoiceSmall, CPU)")
|
|
101
|
+
logger.info("SenseVoice 模型已加载 (iic/SenseVoiceSmall, CPU, 本地缓存)")
|
|
79
102
|
|
|
80
103
|
# [v1.23.2] 增强: pydub 转换失败记录警告、WAV 头验证、音频长度检查
|
|
81
104
|
wav_data = _convert_to_wav(audio_data, audio_format)
|