myagent-ai 1.15.65 → 1.15.66
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/deps_checker.py +3 -1
- package/package.json +1 -1
- package/web/api_server.py +33 -3
package/core/deps_checker.py
CHANGED
|
@@ -76,7 +76,9 @@ DEPENDENCIES: List[DepInfo] = [
|
|
|
76
76
|
|
|
77
77
|
# ── 语音识别 (STT) ──
|
|
78
78
|
DepInfo("faster_whisper", "faster-whisper", "1.0.0", "stt", "all",
|
|
79
|
-
note="本地语音识别引擎 (
|
|
79
|
+
note="本地语音识别引擎 (需要 C++ 编译)"),
|
|
80
|
+
DepInfo("speech_recognition", "SpeechRecognition", "3.10.0", "stt", "all",
|
|
81
|
+
note="在线语音识别 (Google API,纯 Python 无需编译,Termux 兼容)"),
|
|
80
82
|
|
|
81
83
|
# ── 浏览器自动化 (ChromeDev MCP) ──
|
|
82
84
|
# Playwright 已移除,浏览器自动化统一使用 ChromeDevTools Protocol (MCP)
|
package/package.json
CHANGED
package/web/api_server.py
CHANGED
|
@@ -1219,11 +1219,41 @@ class ApiServer:
|
|
|
1219
1219
|
except Exception as e:
|
|
1220
1220
|
logger.warning(f"vosk 转录失败: {e}")
|
|
1221
1221
|
|
|
1222
|
+
# ── 尝试 SpeechRecognition (Google Web Speech API, 纯 Python 无需编译) ──
|
|
1223
|
+
try:
|
|
1224
|
+
import speech_recognition as sr
|
|
1225
|
+
wav_buf = io.BytesIO(audio_data)
|
|
1226
|
+
try:
|
|
1227
|
+
audio_buf = io.BytesIO(audio_data)
|
|
1228
|
+
from pydub import AudioSegment
|
|
1229
|
+
seg = AudioSegment.from_file(audio_buf, format=audio_format or "webm")
|
|
1230
|
+
seg = seg.set_channels(1).set_frame_rate(16000).set_sample_width(2)
|
|
1231
|
+
seg.export(wav_buf, format="wav")
|
|
1232
|
+
except Exception:
|
|
1233
|
+
wav_buf = io.BytesIO(audio_data)
|
|
1234
|
+
wav_buf.seek(0)
|
|
1235
|
+
recognizer = sr.Recognizer()
|
|
1236
|
+
with sr.AudioFile(wav_buf) as source:
|
|
1237
|
+
audio = recognizer.record(source)
|
|
1238
|
+
text = recognizer.recognize_google(audio, language="zh-CN")
|
|
1239
|
+
if text:
|
|
1240
|
+
logger.info("SpeechRecognition (Google API) 转录成功")
|
|
1241
|
+
return web.json_response({"text": text, "engine": "speech_recognition"})
|
|
1242
|
+
except ImportError:
|
|
1243
|
+
logger.debug("SpeechRecognition 未安装,跳过")
|
|
1244
|
+
except sr.UnknownValueError:
|
|
1245
|
+
logger.debug("SpeechRecognition 无法识别音频内容")
|
|
1246
|
+
except sr.RequestError as e:
|
|
1247
|
+
logger.warning(f"SpeechRecognition API 请求失败: {e}")
|
|
1248
|
+
except Exception as e:
|
|
1249
|
+
logger.warning(f"SpeechRecognition 转录失败: {e}")
|
|
1250
|
+
|
|
1222
1251
|
# ── 没有可用的 STT 引擎 ──
|
|
1223
1252
|
return web.json_response({
|
|
1224
|
-
"error": "未检测到本地 STT
|
|
1225
|
-
" pip install faster-whisper (
|
|
1226
|
-
"
|
|
1253
|
+
"error": "未检测到本地 STT 引擎。请安装以下任一引擎:\n"
|
|
1254
|
+
" pip install faster-whisper (推荐,离线,首次下载模型 ~39MB)\n"
|
|
1255
|
+
" pip install vosk (离线,需下载模型)\n"
|
|
1256
|
+
" pip install SpeechRecognition (在线,使用 Google API,无需编译)",
|
|
1227
1257
|
"available": False,
|
|
1228
1258
|
}, status=503)
|
|
1229
1259
|
|