File size: 5,432 Bytes
3888b28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59db86f
0dcc544
0d65a3f
3888b28
 
 
 
 
 
 
 
 
 
73b9356
3888b28
 
 
 
 
 
 
73b9356
3888b28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
license: mit
language:
- en
- zh
pipeline_tag: audio-to-audio
base_model:
- FunAudioLLM/SenseVoiceSmall
- qwen2.5
- MeloTTS
tags:
- VAD
- ASR
- LLM
- TTS
---


# Spoken-Communication.axera 

spoken communication demo on Axera

- [x] Python 示例
- [ ] C++ 示例

## Convert tools links:

For those who are interested in model conversion, you can try to export axmodel through the original repo : 
How to Convert from ONNX to axmodel  
- [ASR](https://github.com/AXERA-TECH/3D-Speaker-MT.axera/tree/main/model_convert) 
- [MeloTTS](https://github.com/ml-inory/melotts.axera/tree/main/model_convert)  

## 支持平台

- AX650N  

## 功能

语音交流

## Pipeline组件

-  [ASR](https://github.com/AXERA-TECH/3D-Speaker-MT.axera/tree/main)    
-  [LLM](https://github.com/AXERA-TECH/ax-llm/tree/ax-context),参考生成库文件,保存到libaxllm
-  [MeloTTS](https://github.com/ml-inory/melotts.axera/tree/main/python) 

## 上板部署

-  AX650N 的设备已预装 Ubuntu22.04  
-  以 root 权限登陆 AX650N 的板卡设备  
-  链接互联网,确保 AX650N 的设备能正常执行 apt install, pip install 等指令   
-  已验证设备:AX650N DEMO Board  

## Python API 运行  

在python3.10(验证)

### pipeline方案:ASR + LLM(Qwen) + MeloTTS

```
支持板端运行及算力卡模式运行
```

###  工程下载
```
git clone https://huggingface.co/AXERA-TECH/Spoken-Communication.axera 或者
hf download AXERA-TECH/Spoken-Communication.axera --local-dir Spoken-Communication.axera

cd Spoken-Communication.axera

工程目录文件结构如下:
.
|-- README.md
|-- ax_model
|-- ax_spoken_communication_demo.py
|-- config.json
|-- libaxllm
|-- libmelotts
|-- model.py
|-- requirements.txt
|-- utils
`-- input_question

```

### 具体流程

**板端 demo**

1、安装依赖库

```
1):
如果环境中没有axengine,下载安装,位置任意
hf download AXERA-TECH/PyAXEngine --local-dir PyAXEngine
cd PyAXEngine
pip3 install axengine-0.1.3-py3-none-any.whl

2):
cd Spoken-Communication.axera
pip3 install -r requirements.txt

3):
apt install espeak 或者 
sudo apt install espeak
```

2、模型下载

```
主目录下执行命令:
hf download AXERA-TECH/Qwen2.5-1.5B-Instruct --local-dir libaxllm --include qwen2.5-1.5b-ctx-ax650/*
模型下载至libaxllm文件夹
```

3、在开发板运行以下命令

```
1)、运行qwen api
cd  libaxllm

启动支持上下文的 tokenizer 服务器
python3 qwen2.5_tokenizer_uid.py

运行
sh run_qwen2.5_1.5b_ctx_ax650_api.sh

2)、运行pipeline板端demo
cd ..

python3 ax_spoken_communication_demo.py --audio_dir input_question --output_dir output_answer  --api_url http://10.126.29.158:8000 

运行参数说明:

| 参数名称 | 说明|
|-------|------|
| `--audio_dir`  | 音频路径   |
| `--api_url`    | qwen API服务地址,对应其运行服务器 |
| `--output_dir` | 结果保存路径 |
```

输出: 
1)输入音频相对应的wav文件,2)识别信息"output_answer/processing_summary.txt"  
如下:
```
批量处理结果汇总

文件 1: Q1.wav
  原始文本: 人工智能和人类智能最本质的区别是什么?。
  回答结果: 人工智能和人类智能最本质的区别在于,人工智能是基于算法和数据进行学习和决策的机器智能,而人类智能是基于经验和直觉进行思考和决策的生物智能。
  合成音频: Q1_answer.wav
  处理时间: 8.22 秒
  音频时长: 15.19 秒
  RTF: 0.54

文件 2: Q2.wav
  原始文本: 人工智能没有思想,为什么他能创作出震撼人心的艺术?。
  回答结果: 人工智能创作艺术是因为它可以通过算法和数据进行学习和分析,理解艺术作品的风格、情感和意义,然后通过生成模型进行创作。这与人类艺术家创作艺术的灵感、经验和直觉不同,但人工智能在某些领域已经表现出超越人类的能力。
  合成音频: Q2_answer.wav
  处理时间: 9.43 秒
  音频时长: 23.68 秒
  RTF: 0.40

文件 3: Q3.wav
  原始文本: 人工智能最终会统治人类吗?。
  回答结果: 人工智能的发展可能会对人类社会产生重大影响,但目前来看,人工智能尚未达到能够统治人类的程度。人工智能主要是在特定任务上表现出色,如数据分析、图像识别等,但在决策、伦理和情感理解等方面仍存在局限。
  合成音频: Q3_answer.wav
  处理时间: 8.86 秒
  音频时长: 22.62 秒
  RTF: 0.39

总计: 3 个文件
总处理时间: 26.53 秒
```

4、Latency

AX650N  

RTF: 约为0.4,如上例。


**算力卡demo**  

运行步骤与板端demo大致相同,以aarch64环境为例:
```
1、运行qwen api
cd  libaxllm

启动支持上下文的 tokenizer 服务器
python3 qwen2.5_tokenizer_uid.py

运行对应环境的api
sh run_qwen2.5_1.5b_ctx_axcl_aarch64_api.sh

2、运行pipeline算力卡demo
cd ..
python3 ax_spoken_communication_demo.py --audio_dir input_question --api_url http://10.126.33.13:8000 --output_dir output 
```
x86环境运行步骤同上  



## 参考 
- [sensevoice.axera](https://github.com/ml-inory/sensevoice.axera/tree/main)  
- [3D-Speaker.axera](https://github.com/AXERA-TECH/3D-Speaker.axera/tree/master) 
- [melotts.axera](https://github.com/ml-inory/melotts.axera/tree/main) 
- [ax-llm](https://github.com/AXERA-TECH/ax-llm/tree/ax-context)


## 技术讨论 

- Github issues  
- QQ 群: 139953715