{"record":{"id":"26ac1b78fda7dd2e","repo":"binary-husky/gpt_academic","slug":"aliyun-aliyun-token-aliyun-appkey","errorCode":null,"errorMessage":"Aliyun音频服务异常，请检查ALIYUN_TOKEN和ALIYUN_APPKEY是否过期。","messagePattern":"Aliyun音频服务异常，请检查ALIYUN_TOKEN和ALIYUN_APPKEY是否过期。","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crazy_functions/Audio_Assistant.py","lineNumber":166,"sourceCode":"\n                self.commit_wd.begin_watch()\n                chatbot[-1] = list(chatbot[-1])\n                chatbot[-1] = [self.buffered_sentence, \"[ 等待GPT响应 ]\"]\n                yield from update_ui(chatbot=chatbot, history=history) # 刷新界面\n                # add gpt task 创建子线程请求gpt，避免线程阻塞\n                history = chatbot2history(chatbot)\n                self.agt.add_async_gpt_task(self.buffered_sentence, len(chatbot)-1, llm_kwargs, history, system_prompt)\n\n                self.buffered_sentence = \"\"\n                chatbot.append([\"[ 请讲话 ]\", \"[ 正在等您说完问题 ]\"])\n                yield from update_ui(chatbot=chatbot, history=history) # 刷新界面\n\n            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():\n                visualize_audio(chatbot, self.audio_shape)\n                yield from update_ui(chatbot=chatbot, history=history) # 刷新界面\n\n        if len(self.stop_msg) != 0:\n            raise RuntimeError(self.stop_msg)\n\n\n\n@CatchException\ndef Audio_Assistant(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_request):\n    # pip install -U openai-whisper\n    chatbot.append([\"对话助手函数插件：使用时，双手离开鼠标键盘吧\", \"音频助手, 正在听您讲话（点击“停止”键可终止程序）...\"])\n    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面\n\n    # 尝试导入依赖，如果缺少依赖，则给出安装建议\n    try:\n        import nls\n        from scipy import io\n    except:\n        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```\"])\n        yield from update_ui(chatbot=chatbot, history=history) # 刷新界面\n        return\n","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/Audio_Assistant.py#L148-L184","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ndef test_on_close(self, *args):\n    self.aliyun_service_ok = False\n\ndef test_on_error(self, message, *args):\n    logging.error(\"on_error args=>{}\".format(args))\n\n# after\ndef test_on_error(self, message, *args):\n    try:\n        detail = json.loads(message)\n        self.stop_msg = \"Aliyun ASR error: \" + str(detail)\n    except Exception:\n        self.stop_msg = \"Aliyun ASR error: \" + str(message)\n    self.aliyun_service_ok = False\n","handlingStrategy":"try-catch","validationCode":"TOKEN, APPKEY = get_conf(\"ALIYUN_TOKEN\", \"ALIYUN_APPKEY\")\nif not APPKEY:\n    raise ValueError(\"ALIYUN_APPKEY is required\")\nif not TOKEN and not all(get_conf(\"ALIYUN_ACCESSKEY\", \"ALIYUN_SECRET\")):\n    raise ValueError(\"Provide ALIYUN_TOKEN or valid ALIYUN_ACCESSKEY/ALIYUN_SECRET\")\n","typeGuard":null,"tryCatchPattern":"try:\n    yield from ia.begin(llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)\nexcept RuntimeError as e:\n    if \"Aliyun音频服务异常\" in str(e):\n        chatbot.append([\"音频助手停止\", \"请更新阿里云 NLS Token/AppKey 后重试。\"])\n        yield from update_ui(chatbot=chatbot, history=history)\n    else:\n        raise\n","preventionTips":["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."],"tags":["aliyun","asr","websocket","credentials","audio"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}