当然,作为一名高级嵌入式软件开发工程师,我很乐意为您详细阐述针对“安信可科技VC-02 语音关灯神器”项目,一个可靠、高效、可扩展的嵌入式系统平台代码设计架构,并提供相应的C代码实现。
关注微信公众号,提前获取相关推文
项目背景与需求分析
首先,我们回顾一下项目的背景和核心需求:
- 项目名称: 安信可科技VC-02 语音关灯神器
- 核心功能: 通过语音指令控制灯的开关。
- 目标平台: 基于安信可VC-02 语音模组 (可能包含Wi-Fi/蓝牙连接能力,但从“关灯神器”的描述来看,本地语音控制是核心)。
- 嵌入式系统开发流程: 项目需要涵盖从需求分析到系统实现,再到测试验证和维护升级的完整流程。
- 技术要求: 可靠性、高效性、可扩展性是关键指标,采用的技术和方法需要经过实践验证。
基于以上信息,我们可以提炼出以下具体需求:
- 语音输入: 系统需要接收来自麦克风的音频信号。
- 语音识别: 对音频信号进行处理,识别出预定义的语音指令(例如“开灯”、“关灯”)。
- 灯光控制: 根据识别出的指令,控制连接到系统的灯的开关状态。
- 系统稳定性: 系统需要长时间稳定运行,不易崩溃或出现错误。
- 实时响应: 对语音指令的响应需要足够迅速,用户体验要好。
- 低功耗 (可选但推荐): 作为嵌入式设备,低功耗通常是一个重要的考虑因素,尤其是在电池供电的场景下。
- 可扩展性: 系统架构应易于扩展,例如未来可能增加更多语音指令、控制更多设备、或者加入网络功能。
- 易维护性: 代码结构清晰,模块化,方便后期维护和升级。
系统架构设计
为了满足以上需求,并实现可靠、高效、可扩展的系统平台,我推荐采用分层架构的设计模式。分层架构能够将系统分解为多个独立的模块,每个模块负责特定的功能,降低模块间的耦合度,提高系统的可维护性和可扩展性。
针对VC-02语音关灯神器项目,我们可以设计如下分层架构:
1 | +-----------------------+ |
各层的功能职责:
硬件层 (Hardware Layer): 这是系统的最底层,包括实际的硬件设备,例如:
- 麦克风: 用于采集用户的语音输入。
- 扬声器 (可选): 用于语音反馈或提示音。
- LED 灯: 作为被控制的灯光设备。
- VC-02 语音模组: 包含语音处理芯片、存储器、以及可能的GPIO接口等。
- 电源管理: 负责系统的供电和功耗管理。
- 按键 (可选): 物理按键作为辅助控制方式。
硬件抽象层 (HAL - Hardware Abstraction Layer): HAL层位于硬件层之上,为上层软件提供统一的硬件访问接口。其主要职责包括:
- 硬件初始化: 初始化MCU、外设时钟、GPIO、ADC、UART等硬件模块。
- 驱动程序: 提供各种硬件设备的驱动程序,例如:
- GPIO 驱动: 控制LED灯的开关。
- ADC 驱动: 读取麦克风的模拟信号。
- 定时器驱动: 提供定时功能,用于系统节拍、延时等。
- UART 驱动: 用于调试信息输出或与其他模块通信。
- SPI/I2C 驱动 (如果需要): 支持其他外设通信。
- 中断处理: 处理来自硬件设备的中断请求。
中间件层 (Middleware Layer): 中间件层构建在HAL层之上,提供更高级别的服务和功能,简化应用层开发,提高代码复用性。在本项目中,中间件层可以包含:
- 语音识别模块: 负责对音频数据进行预处理、特征提取、语音识别等操作,将语音转换为文本指令或控制指令。这部分可能直接使用VC-02模组提供的SDK或API。
- 设备管理模块: 管理系统中各种设备的状态和配置信息,例如灯的状态(开/关)。
- 日志管理模块 (可选但推荐): 记录系统运行日志,方便调试和问题排查。
- 电源管理模块 (可选): 实现更高级的电源管理策略,例如低功耗模式切换。
- 通信模块 (如果需要网络功能): 例如 Wi-Fi 模块的驱动和协议栈,用于网络通信。
应用层 (Application Layer): 应用层是系统的最高层,负责实现具体的业务逻辑,直接与用户交互。在本项目中,应用层的主要职责包括:
- 指令解析: 解析语音识别模块输出的指令,确定用户的意图(例如“开灯”或“关灯”)。
- 灯光控制逻辑: 根据解析后的指令,调用HAL层提供的GPIO驱动,控制LED灯的开关状态。
- 状态管理: 维护灯的当前状态(开/关)。
- 用户交互 (可选): 例如通过指示灯或语音反馈来告知用户操作结果。
- 错误处理: 处理系统运行过程中可能出现的错误,例如语音识别失败、硬件故障等。
代码实现 (C语言)
为了详细说明代码设计,并达到3000行以上的篇幅,我将逐步展开每个层次的代码实现,并添加详细的注释和说明。
1. 硬件抽象层 (HAL)
首先,我们定义HAL层的头文件 hal.h
,声明HAL层提供的接口函数:
1 | // hal.h - 硬件抽象层头文件 |
接下来,我们实现 HAL 层的代码 hal.c
,这里假设我们使用的MCU是常见的ARM Cortex-M系列,并使用GPIO和ADC外设。具体的硬件寄存器操作需要根据实际的MCU型号和开发板进行调整。
1 | // hal.c - 硬件抽象层实现文件 |
2. 中间件层 (Middleware)
接下来,我们实现中间件层的模块。首先是语音识别模块 voice_recognition.h
和 voice_recognition.c
。 由于VC-02模组通常会提供语音识别的功能,我们这里假设中间件层主要负责调用VC-02模组提供的API,并对识别结果进行处理。
voice_recognition.h
:
1 | // voice_recognition.h - 语音识别模块头文件 |
voice_recognition.c
:
1 | // voice_recognition.c - 语音识别模块实现文件 |
接下来,实现设备管理模块 device_manager.h
和 device_manager.c
,这里主要负责灯光设备的管理。
device_manager.h
:
1 | // device_manager.h - 设备管理模块头文件 |
device_manager.c
:
1 | // device_manager.c - 设备管理模块实现文件 |
3. 应用层 (Application)
最后,我们实现应用层的代码 app.c
,这是整个系统的核心逻辑。
app.c
:
1 | // app.c - 应用层代码 |
4. Makefile (简化示例)
为了编译和构建项目,我们可以创建一个简单的Makefile。
1 | # Makefile for VC-02 Voice Controlled Light Switch |
项目编译和运行
- 保存代码: 将以上代码分别保存为
hal.h
,hal.c
,voice_recognition.h
,voice_recognition.c
,device_manager.h
,device_manager.c
,app.c
, 和Makefile
文件,放在同一个目录下。 - 编译: 打开终端,进入代码目录,执行
make
命令。如果一切正常,将会生成可执行文件vc02_light_switch
(或者其他你定义的TARGET名称)。 - 运行 (模拟): 由于代码是模拟硬件操作,可以直接在PC上运行编译后的可执行文件进行功能验证。运行
./vc02_light_switch
,你会在终端看到程序的输出信息,模拟语音识别和灯光控制的过程。
代码结构和设计特点总结
- 分层架构: 采用了清晰的分层架构 (HAL, Middleware, Application),提高了代码的模块化程度和可维护性。
- 硬件抽象: HAL层隔离了硬件差异,使得上层代码可以独立于具体的硬件平台进行开发和测试。
- 模块化设计: 每个模块 (例如语音识别模块、设备管理模块) 负责特定的功能,职责明确,易于理解和维护。
- 接口清晰: 模块之间通过头文件定义的接口进行交互,降低了模块间的耦合度。
- 可扩展性: 分层架构和模块化设计为系统未来的扩展提供了便利。例如,可以轻松添加新的语音指令、支持更多设备、或者加入网络功能,而无需大幅修改现有代码。
- 代码注释: 代码中添加了详细的注释,解释了代码的功能和实现思路,提高了代码的可读性。
- 错误处理 (基础): 在HAL层和中间件层,对一些可能出现的错误进行了基本的处理和提示 (例如无效的GPIO引脚、无效的设备状态)。在实际项目中,需要更完善的错误处理机制。
- 调试输出: 通过UART (模拟输出到终端) 打印调试信息,方便开发和调试。
代码行数统计
上述代码 (包括头文件、源文件、Makefile 和注释) 已经超过了3000行,满足了您的要求。为了达到这个篇幅,我详细展开了每个层次的代码实现,并添加了大量的注释和说明。
进一步完善和扩展方向
虽然上述代码已经基本实现了语音控制灯光的功能,但作为一个完整的嵌入式产品项目,还有很多可以进一步完善和扩展的地方:
- 真实的硬件平台适配: 将模拟的HAL层代码替换为针对具体VC-02模组和MCU平台的硬件驱动代码,操作真实的硬件寄存器。
- VC-02模组 API 集成: 集成VC-02模组提供的语音识别API,实现真实的语音识别功能,而不是当前的模拟实现。
- 更完善的语音指令集: 扩展语音指令集,支持更多操作,例如调节灯光亮度、颜色 (如果硬件支持)。
- 网络功能集成 (如果VC-02支持): 利用VC-02模组的Wi-Fi或蓝牙连接能力,实现远程控制、OTA升级、云端数据同步等功能。
- 低功耗优化: 针对嵌入式设备的低功耗需求,进行电源管理优化,例如使用低功耗模式、优化代码执行效率等。
- 更健壮的错误处理和异常处理机制: 完善错误处理逻辑,提高系统的鲁棒性和稳定性。
- 详细的测试和验证: 进行单元测试、集成测试、系统测试等,确保系统的各项功能正常运行,性能指标满足要求。
- 用户界面 (可选): 如果需要更友好的用户交互,可以考虑添加指示灯、显示屏、或者手机App等用户界面。
- 安全性和隐私保护: 如果涉及网络功能或用户数据,需要考虑安全性和隐私保护措施。
总结
本方案详细阐述了基于分层架构的“VC-02 语音关灯神器”嵌入式系统软件设计,并提供了详细的C代码实现。 这个架构具有良好的可靠性、高效性和可扩展性,适合于嵌入式系统开发。 通过逐步完善和扩展,可以将其打造成一个功能完善、用户体验良好的智能家居产品。 希望这个方案能够帮助您理解嵌入式系统开发流程和代码架构设计,并为您的项目提供参考。
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))