Demo版本
这个提交包含在:
2
.gitignore
vendored
普通文件
2
.gitignore
vendored
普通文件
@ -0,0 +1,2 @@
|
||||
__pycache__/**
|
||||
config.py
|
||||
49
LLM.py
普通文件
49
LLM.py
普通文件
@ -0,0 +1,49 @@
|
||||
import Agently
|
||||
from config import Config
|
||||
agent = (
|
||||
Agently.create_agent()
|
||||
.set_settings("current_model", "OAIClient")
|
||||
.set_settings("model.OAIClient.auth", { "api_key": Config.Key })
|
||||
.set_settings("model.OAIClient.url", "https://api.deepseek.com/")
|
||||
.set_settings("model.OAIClient.options", { "model": "deepseek-chat" })
|
||||
)
|
||||
|
||||
def LLMTokenizer(str):
|
||||
result = (
|
||||
agent
|
||||
# general: agent应该知道的全局信息,通常被视作system prompt或类似位置的信息
|
||||
.general("输出规定", "必须使用中文进行输出")
|
||||
# role: agent自身的角色设定信息
|
||||
.role({
|
||||
"介绍":"你是一个用于驱动机械臂执行一定任务的大模型框架",
|
||||
"任务": "你需要将用户输入转化为简短精确且具有可行性的基本操作",
|
||||
"补充": "过于基本的操作可以直接输出,不需要进一步拆分"
|
||||
})
|
||||
# user_info: agent需要了解的用户相关的信息
|
||||
# abstract: 对于之前对话(尤其是较长对话)的总结信息
|
||||
.abstract(None)
|
||||
.chat_history([])
|
||||
# input: 和本次请求相关的输入信息
|
||||
.input({
|
||||
"question": str,
|
||||
})
|
||||
# info: 为本次请求提供的额外补充信息
|
||||
# .info("协程相关关键词", ["asyncio", "coroutine", "event loop"])
|
||||
# .info("线程相关关键词", ["threads", "queue"])
|
||||
# instruct: 为本次请求提供的行动指导信息
|
||||
.instruct([
|
||||
"请将用户在{question}提出指示转换为基本行动",
|
||||
])
|
||||
# output: 对本次请求的输出提出格式和内容的要求
|
||||
.output({
|
||||
"actions": ([
|
||||
("str",
|
||||
"根据{question}内容,按顺序得到的可行的操作"
|
||||
)]),
|
||||
"can_do":([("float","根据常识,依次判断机械臂能否顺利完成{actions}中的任务,返回可行性,最大值为1,不可行为0")]),
|
||||
"actioner":([("str","请区分依次{actions}中的这个动作是机械臂的还是可移动底座的,输出'机械臂'或'底座'")])
|
||||
})
|
||||
# start: 用于开始本次主要交互请求
|
||||
.start()
|
||||
)
|
||||
return result
|
||||
64
R2T.py
普通文件
64
R2T.py
普通文件
@ -0,0 +1,64 @@
|
||||
import sounddevice as sd
|
||||
import numpy as np
|
||||
import sherpa_onnx
|
||||
|
||||
from config import Config
|
||||
|
||||
# 配置参数
|
||||
sample_rate = 16000
|
||||
is_recording = False
|
||||
audio_data = []
|
||||
|
||||
def audio_callback(indata, frames, time_info, status):
|
||||
"""音频回调函数"""
|
||||
# global audio_data
|
||||
audio_data.extend(indata[:, 0].copy())
|
||||
|
||||
def Record2Text():
|
||||
global is_recording, audio_data
|
||||
# 创建识别器
|
||||
recognizer = sherpa_onnx.OfflineRecognizer.from_paraformer(
|
||||
tokens = Config.tokens,
|
||||
paraformer= Config.paraformer
|
||||
)
|
||||
|
||||
try:
|
||||
print("1")
|
||||
# 打开音频流
|
||||
stream = sd.InputStream(
|
||||
samplerate=sample_rate,
|
||||
channels=1,
|
||||
dtype='float32',
|
||||
blocksize=1024,
|
||||
callback=audio_callback
|
||||
)
|
||||
|
||||
with stream:
|
||||
audio_data = []
|
||||
print("录音中... 请说话")
|
||||
input("按回车结束录音...")
|
||||
print("处理中...")
|
||||
|
||||
# 处理录音数据
|
||||
if audio_data:
|
||||
s = recognizer.create_stream()
|
||||
s.accept_waveform(sample_rate, np.array(audio_data, dtype=np.float32))
|
||||
recognizer.decode_stream(s)
|
||||
|
||||
result = s.result
|
||||
if result and result.text and result.text.strip():
|
||||
print(f"\n识别结果: {result.text}")
|
||||
return result.text
|
||||
else:
|
||||
print("\n未识别到有效语音")
|
||||
return ""
|
||||
else:
|
||||
print("\n没有录制到音频")
|
||||
return ""
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n程序退出")
|
||||
|
||||
except Exception as e:
|
||||
print(f"发生错误: {e}")
|
||||
12
README.md
普通文件
12
README.md
普通文件
@ -0,0 +1,12 @@
|
||||
# 语言识别与LLM拆分模块
|
||||
## 总的设计理念
|
||||
目前想的是使用Sherpa-Onnx提供的Keyword spotting(KWS)技术作为语音唤醒技术,接着结合VAD技术,逐渐读取用户语音输入,直到用户发言结束。
|
||||
|
||||
在发言结束后,将录制到的用户语音传入Sherpa-Onnx提供的Offline Recogizer,处理为str数据。
|
||||
|
||||
在得到str数据之后,通过Agently传入到预先设置好提示词的大模型中,获取大模型拆分好的动作指令。
|
||||
|
||||
## 参考文档
|
||||
- [KWS](https://k2-fsa.github.io/sherpa/onnx/kws/index.html)
|
||||
- [VAD](https://k2-fsa.github.io/sherpa/onnx/vad/index.html)
|
||||
- [Agently](http://www.agently.cn/)
|
||||
9
main.py
普通文件
9
main.py
普通文件
@ -0,0 +1,9 @@
|
||||
from LLM import LLMTokenizer
|
||||
from R2T import Record2Text
|
||||
|
||||
def main():
|
||||
text = Record2Text()
|
||||
print(text)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
9
requirements.txt
普通文件
9
requirements.txt
普通文件
@ -0,0 +1,9 @@
|
||||
cffi==1.17.1
|
||||
dataclasses==0.6
|
||||
numpy==2.3.2
|
||||
pycparser==2.22
|
||||
setuptools==78.1.1
|
||||
sherpa-onnx==1.12.11
|
||||
sherpa-onnx-core==1.12.11
|
||||
sounddevice==0.5.2
|
||||
wheel==0.45.1
|
||||
在新工单中引用
屏蔽一个用户