binary-husky/gpt_academic · error · RuntimeError
Aliyun音频服务异常,请检查ALIYUN_TOKEN和ALIYUN_APPKEY是否过期。
Error message
Aliyun音频服务异常,请检查ALIYUN_TOKEN和ALIYUN_APPKEY是否过期。
What it means
The audio plugin exits its capture loop and re-raises self.stop_msg at crazy_functions/Audio_Assistant.py:166. For this message, AliyunASR set stop_msg in crazy_functions/live_audio/aliyunASR.py:218-220 after the Aliyun NLS websocket transcriber closed. It is a generic ASR session failure, but this implementation labels every close as an expired ALIYUN_TOKEN or ALIYUN_APPKEY problem.
Source
Thrown at crazy_functions/Audio_Assistant.py:166
self.commit_wd.begin_watch()
chatbot[-1] = list(chatbot[-1])
chatbot[-1] = [self.buffered_sentence, "[ 等待GPT响应 ]"]
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
# add gpt task 创建子线程请求gpt,避免线程阻塞
history = chatbot2history(chatbot)
self.agt.add_async_gpt_task(self.buffered_sentence, len(chatbot)-1, llm_kwargs, history, system_prompt)
self.buffered_sentence = ""
chatbot.append(["[ 请讲话 ]", "[ 正在等您说完问题 ]"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
if not self.event_on_result_chg.is_set() and not self.event_on_entence_end.is_set() and not self.event_on_commit_question.is_set():
visualize_audio(chatbot, self.audio_shape)
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
if len(self.stop_msg) != 0:
raise RuntimeError(self.stop_msg)
@CatchException
def Audio_Assistant(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_request):
# pip install -U openai-whisper
chatbot.append(["对话助手函数插件:使用时,双手离开鼠标键盘吧", "音频助手, 正在听您讲话(点击“停止”键可终止程序)..."])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
# 尝试导入依赖,如果缺少依赖,则给出安装建议
try:
import nls
from scipy import io
except:
chatbot.append(["导入依赖失败", "使用该模块需要额外依赖, 安装方法:```pip install --upgrade aliyun-python-sdk-core==2.13.3 pyOpenSSL webrtcvad scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git```"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
View on GitHub (pinned to d6bde0fa54)
Solutions
- Generate a fresh Aliyun NLS token and put it in ALIYUN_TOKEN, or leave it empty and configure valid ALIYUN_ACCESSKEY and ALIYUN_SECRET so get_token() can create one.
- Confirm ALIYUN_APPKEY is the appkey of an enabled Intelligent Speech Interaction project and belongs to the same account/token.
- Check network access to wss://nls-gateway.aliyuncs.com/ws/v1 and temporarily disable proxies that cannot tunnel websockets.
- Reinstall the required Aliyun SDK with the command shown by the plugin, then reproduce the close in a minimal NlsSpeechTranscriber script.
- Improve on_error/on_close handling so the actual Aliyun error code is stored instead of always reporting credential expiration.
Example fix
# before
def test_on_close(self, *args):
self.aliyun_service_ok = False
def test_on_error(self, message, *args):
logging.error("on_error args=>{}".format(args))
# after
def test_on_error(self, message, *args):
try:
detail = json.loads(message)
self.stop_msg = "Aliyun ASR error: " + str(detail)
except Exception:
self.stop_msg = "Aliyun ASR error: " + str(message)
self.aliyun_service_ok = False
Defensive patterns
Strategy: try-catch
Validate before calling
TOKEN, APPKEY = get_conf("ALIYUN_TOKEN", "ALIYUN_APPKEY")
if not APPKEY:
raise ValueError("ALIYUN_APPKEY is required")
if not TOKEN and not all(get_conf("ALIYUN_ACCESSKEY", "ALIYUN_SECRET")):
raise ValueError("Provide ALIYUN_TOKEN or valid ALIYUN_ACCESSKEY/ALIYUN_SECRET")
Try / catch
try:
yield from ia.begin(llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
except RuntimeError as e:
if "Aliyun音频服务异常" in str(e):
chatbot.append(["音频助手停止", "请更新阿里云 NLS Token/AppKey 后重试。"])
yield from update_ui(chatbot=chatbot, history=history)
else:
raise
Prevention
- Refresh Aliyun NLS tokens before long voice sessions because they expire.
- Keep the appkey and token in the same NLS project.
- Test websocket connectivity to nls-gateway.aliyuncs.com before starting a demo.
- Capture on_error payloads so session failures are diagnosable.
When it happens
Trigger: Starting or streaming through nls.NlsSpeechTranscriber against wss://nls-gateway.aliyuncs.com/ws/v1 fails or the websocket calls on_close. Typical causes are an expired NLS token, a token that does not match ALIYUN_APPKEY, an appkey that is not enabled for the project, or a blocked/unstable WSS connection.
Common situations: ALIYUN_TOKEN was generated earlier and has expired; ALIYUN_TOKEN is empty and CreateToken failed because ALIYUN_ACCESSKEY/ALIYUN_SECRET are wrong; the appkey belongs to a different NLS project; corporate proxy or firewall blocks websocket traffic; the SDK dependency from the Aliyun git repository is missing or incompatible.
Related errors
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/26ac1b78fda7dd2e.
Report an issue: GitHub.