Skip to content

增加README.md #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 75 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,103 @@
# QuecPython 基于小智平台 的 AI 聊天机器人
# QuecPython AI Chatbot Based on Xiaozhi Platform

## 目录
## Table of Contents

- [介绍](#介绍)
- [功能特性](#功能特性)
- [快速开始](#快速开始)
- [先决条件](#先决条件)
- [安装](#安装)
- [运行应用程序](#运行应用程序)
- [目录结构](#目录结构)
- [贡献](#贡献)
- [许可证](#许可证)
- [支持](#支持)
- [Introduction](#Introduction)
- [Features](#Features)
- [Quick_Start](#Quick_Start)
- [Prerequisites](#Prerequisites)
- [Installation](#Installation)
- [Running_Application](#Running_Application)
- [Contributing](#Contributing)
- [License](#License)
- [Support](#Support)

## 介绍
## Introduction

QuecPython 推出了小智平台 AI 聊天机器人解决方案。该方案基于 websocket 协议,具有跨平台特性,可以适用于大部分 QuecPython 模组。
QuecPython introduces the Xiaozhi Platform AI Chatbot solution. This solution is based on the WebSocket protocol, offering cross-platform compatibility and supporting most QuecPython modules.

本案例采用搭载 EC800MCNLE 模组的 AI 开发板。
This demo uses an AI development board equipped with the EC800MCNLE module.

## 功能特性
## Features

- 支持语音中断/打断。
- 支持关键词语音唤醒。
- 使用 Python 语言,便于二次开发。
- Supports voice interruption/barge-in.
- Supports keyword-based voice wake-up.
- Uses Python for easy secondary development.

## 快速开始
## Quick_Start

### 先决条件
### Prerequisites

在开始之前,请确保您具备以下先决条件:
Before getting started, ensure you have the following prerequisites:

- **硬件:**
- 联系移远官方获取 AI 开发板及配件。
- 电脑(Windows 7、Windows 10 或 Windows 11)
- 喇叭
- 任意 2-5W 功率的喇叭即可
- [移远商城购买链接](https://www.quecmall.com/goods-detail/2c90800c94028da201948249e9f4012d)

- **软件:**
- 调试工具 [QPYcom](https://images.quectel.com/python/2022/12/QPYcom_V3.6.0.zip)
- QuecPython 固件(仓库 fw 目录下有 beta 固件)
- Python 文本编辑器(例如,[VSCode](https://code.visualstudio.com/)、[Pycharm](https://www.jetbrains.com/pycharm/download/))
- **Hardware:**
- Contact Quectel to obtain the AI development board and accessories.
- Computer (Windows 7, Windows 10, or Windows 11)
- Speaker
- Any 2-5W speaker will work
- [Purchase link from Quectel Mall](https://www.quecmall.com/goods-detail/2c90800c94028da201948249e9f4012d)
- **Software:**
- Debugging tool [QPYcom](https://images.quectel.com/python/2022/12/QPYcom_V3.6.0.zip)
- QuecPython firmware (beta firmware is available in the `fw` directory of the repository)
- Python text editor (e.g., [VSCode](https://code.visualstudio.com/), [PyCharm](https://www.jetbrains.com/pycharm/download/))

### 安装
### Installation

1. **Clone the Repository:**

1. **克隆仓库**:
```bash
git clone https://github.com/QuecPython/solution-xiaozhiAI.git
git clone https://github.com/QuecPython/solution-xiaozhiAI.git
```

3. **烧录固件:**
按照[说明](https://python.quectel.com/doc/Application_guide/zh/dev-tools/QPYcom/qpycom-dw.html#%E4%B8%8B%E8%BD%BD%E5%9B%BA%E4%BB%B6)将固件烧录到开发板上。

### 运行应用程序
2. **Flash the Firmware:**
Follow the [instructions](https://python.quectel.com/doc/Application_guide/zh/dev-tools/QPYcom/qpycom-dw.html#%E4%B8%8B%E8%BD%BD%E5%9B%BA%E4%BB%B6) to flash the firmware onto the development board.

### Running_Application

1. **Hardware Connection:**
This demo uses the Quectel AI development board. Contact Quectel if needed. Connect the hardware as shown below:

1. **连接硬件:**
本案例采用移远 AI 开发板,如有需要请联系官方获取。按照下图进行硬件连接:

<img src="./media/20250425131903.jpg" style="zoom:80%;" />

1. 连接喇叭
2. 连接天线
3. 接入电池
4. 通过 Tpye-C 连接上位机

2. **将代码下载到设备:**
- 启动 QPYcom 调试工具。
- 将数据线连接到计算机。
- 按下开发板上的 **PWRKEY** 按钮启动设备。
- 按照[说明](https://python.quectel.com/doc/Application_guide/zh/dev-tools/QPYcom/qpycom-dw.html#%E4%B8%8B%E8%BD%BD%E8%84%9A%E6%9C%AC)将 `code` 文件夹中的所有文件导入到模块的文件系统中,保留目录结构。

3. **运行应用程序:**
- 选择 `File` 选项卡。
- 选择 `_main.py` 脚本。
- 右键单击并选择 `Run` 或使用`运行`快捷按钮执行脚本。

4. **关键词唤醒后,即可对话, 参考运行日志:**

1. Connect the speaker
2. Connect the antenna
3. Insert the battery

2. Connect to the host computer via Type-C.

3. **Download the Code to the Device:**

- Launch the QPYcom debugging tool.
- Connect the data cable to the computer.
- Press the **PWRKEY** button on the development board to power on the device.
- Follow the [instructions](https://developer.quectel.com/doc/quecpython/Getting_started/en/4G/first_python.html#PC与模组间的文件传输) to import all files from the `code` folder into the module's file system, preserving the directory structure.

4. **Run the Application:**

- Select the `File` tab.
- Choose the `_main.py` script.
- Right-click and select `Run` or use the `Run` shortcut button to execute the script.

5. **After keyword wake-up, start a conversation. Refer to the runtime log:**

![](./media/20250425132727.png)

5. 参考使用示例视频:`media/example_video.mp4`
6. For a usage example, refer to the demo video: `media/example_video.mp4`

## 贡献
## Contributing

我们欢迎对本项目的改进做出贡献!请按照以下步骤进行贡献:
We welcome contributions to improve this project! Follow these steps to contribute:

1. Fork 此仓库。
2. 创建一个新分支(`git checkout -b feature/your-feature`)。
3. 提交您的更改(`git commit -m 'Add your feature'`)。
4. 推送到分支(`git push origin feature/your-feature`)。
5. 打开一个 Pull Request
1. Fork this repository.
2. Create a new branch (`git checkout -b feature/your-feature`).
3. Commit your changes (`git commit -m 'Add your feature'`).
4. Push to the branch (`git push origin feature/your-feature`).
5. Open a Pull Request.

## 许可证
## License

本项目使用 Apache 许可证。详细信息请参阅 [LICENSE](LICENSE) 文件。
This project is licensed under the Apache License. See the [LICENSE](https://license/) file for details.

## 支持
## Support

如果您有任何问题或需要支持,请参阅 [QuecPython 文档](https://python.quectel.com/doc) 或在本仓库中打开一个 issue
If you have any questions or need support, refer to the [QuecPython Documentation](https://python.quectel.com/doc) or open an issue in this repository.
101 changes: 101 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# QuecPython 基于小智平台 的 AI 聊天机器人

## 目录

- [介绍](#介绍)
- [功能特性](#功能特性)
- [快速开始](#快速开始)
- [先决条件](#先决条件)
- [安装](#安装)
- [运行应用程序](#运行应用程序)
- [贡献](#贡献)
- [许可证](#许可证)
- [支持](#支持)

## 介绍

QuecPython 推出了小智平台 AI 聊天机器人解决方案。该方案基于 websocket 协议,具有跨平台特性,可以适用于大部分 QuecPython 模组。

本案例采用搭载 EC800MCNLE 模组的 AI 开发板。

## 功能特性

- 支持语音中断/打断。
- 支持关键词语音唤醒。
- 使用 Python 语言,便于二次开发。

## 快速开始

### 先决条件

在开始之前,请确保您具备以下先决条件:

- **硬件:**
- 联系移远官方获取 AI 开发板及配件。
- 电脑(Windows 7、Windows 10 或 Windows 11)
- 喇叭
- 任意 2-5W 功率的喇叭即可
- [移远商城购买链接](https://www.quecmall.com/goods-detail/2c90800c94028da201948249e9f4012d)

- **软件:**
- 调试工具 [QPYcom](https://images.quectel.com/python/2022/12/QPYcom_V3.6.0.zip)
- QuecPython 固件(仓库 fw 目录下有 beta 固件)
- Python 文本编辑器(例如,[VSCode](https://code.visualstudio.com/)、[Pycharm](https://www.jetbrains.com/pycharm/download/))

### 安装

1. **克隆仓库**:
```bash
git clone https://github.com/QuecPython/solution-xiaozhiAI.git
```

3. **烧录固件:**
按照[说明](https://python.quectel.com/doc/Application_guide/zh/dev-tools/QPYcom/qpycom-dw.html#%E4%B8%8B%E8%BD%BD%E5%9B%BA%E4%BB%B6)将固件烧录到开发板上。

### 运行应用程序

1. **连接硬件:**
本案例采用移远 AI 开发板,如有需要请联系官方获取。按照下图进行硬件连接:

<img src="./media/20250425131903.jpg" style="zoom:80%;" />

1. 连接喇叭
2. 连接天线
3. 接入电池
4. **通过 Tpye-C 连接上位机**

2. **将代码下载到设备:**
- 启动 QPYcom 调试工具。
- 将数据线连接到计算机。
- 按下开发板上的 **PWRKEY** 按钮启动设备。
- 按照[说明](https://developer.quectel.com/doc/quecpython/Getting_started/zh/4G/first_python.html#PC与模组间的文件传输)将 `code` 文件夹中的所有文件导入到模块的文件系统中,保留目录结构。

3. **运行应用程序:**

- 选择 `File` 选项卡。
- 选择 `_main.py` 脚本。
- 右键单击并选择 `Run` 或使用`运行`快捷按钮执行脚本。

4. **关键词唤醒后,即可对话, 参考运行日志:**

![](./media/20250425132727.png)

5. 参考使用示例视频:`media/example_video.mp4`

## 贡献

我们欢迎对本项目的改进做出贡献!请按照以下步骤进行贡献:

1. Fork 此仓库。
2. 创建一个新分支(`git checkout -b feature/your-feature`)。
3. 提交您的更改(`git commit -m 'Add your feature'`)。
4. 推送到分支(`git push origin feature/your-feature`)。
5. 打开一个 Pull Request。

## 许可证

本项目使用 Apache 许可证。详细信息请参阅 [LICENSE](LICENSE) 文件。

## 支持

如果您有任何问题或需要支持,请参阅 [QuecPython 文档](https://python.quectel.com/doc) 或在本仓库中打开一个 issue。
2 changes: 2 additions & 0 deletions src/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def __chat_process(self):
if self.__voice_activity_event.is_set():
# 有人声
if not is_listen_flag:
self.audio_manager.stop()
# logger.debug("Clear the audio cache")
self.__protocol.listen("start")
is_listen_flag = True
self.__protocol.send(data)
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def hello(self):
"format": "opus",
"sample_rate": 16000,
"channels": 1,
"frame_duration": 60
"frame_duration": 80
},
"features": {
"consistent_sample_rate": True
Expand Down
3 changes: 3 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def audio_cb(self, event):

def play(self, file):
self.aud.play(0, 1, file)

def stop(self):
return self.aud.stopAll()

# ========= opus ====================

Expand Down