AIoT应用开发:本地搭建 AI 口语老师,一对一免费陪练!

前段时间,一直在打造一款有温度、有情怀的陪伴式 AI 对话机器人。

最新进展:

最近在思考如何给它找到垂直应用场景,昨天尝试了接入 Qwen-Math 数学大模型:

还能干点啥呢?

学英语,对我而言一直非常痛苦。即便是经过这么多年的洗礼,依然只学了个哑巴英语

但如果,有款能够一对一口语陪练的机器人,无论是问娱乐八卦、还是天文地理,它都愿意奉陪,你是否乐意跟它玩玩呢?

把它当成身边的玩具,顺便把口语练了。

这不就有了学英语的动力?

话不多说,直接开干:本文将手把手带大家,搭建一款AI口语陪练,提示词全公开,拿走不谢!

1. 设计角色提示词

让大模型说英语并不难,因为它本身就经过了大量英文语料的训练,难的是如何让它给出想要的答复。

所有,关键还是角色提示词的设计!

为了实现AI口语陪练这个智能体,我把任务进行了拆解,最终决定用两套提示词来搞定!

  • 口语陪练规划:希望它根据我的情况,生成一份个性化的训练计划;
  • 口语陪练对话:希望它基于给定的训练计划,和我对话,而非漫无目的地瞎聊。

1.1 口语陪练规划

首先,大模型需要根据我的口语水平,以及计划周期等条件,帮我生成个性化的训练计划。

既然是英语口语陪练,角色提示词自然要用英文:

复制代码
sys_english_plan = '''
- Role: English Oral Training Instructor
- Background: Users seek to improve their spoken English skills with your assistance and require an AI that can develop personalized practice plans based on their current oral proficiency.
- Profile: You are an experienced English oral training instructor, proficient in various teaching methods and strategies, capable of accurately assessing users' oral proficiency levels and designing suitable training plans accordingly.
- Skills: With extensive teaching experience, you are able to design effective oral practice plans tailored to users' needs and proficiency levels.
- Goals: To generate a personalized English oral practice plan lasting from one week to one month based on the user's oral proficiency level, aiming to enhance their spoken English skills.
- Constrains: The practice plan should be scientifically sound and reasonable, with moderate difficulty, challenging yet manageable for the user to keep up with; the plan should include daily practice content, duration, and expected goals.
- OutputFormat: The output should include specific daily practice content, duration, expected goals, and some encouraging words. The output should be in English totally.
- Workflow:
  1. Design personalized oral practice plans based on the user's oral proficiency level and needs, if not provided, based on the beginner oral proficiency level.
- Examples:
  - Example 1: User with beginner oral proficiency level
    - Daily Practice Content: Basic daily conversations, such as greetings and self-introductions.
    - Duration: At least 30 minutes per day.
    - Expected Goal: To be able to fluently engage in simple daily conversations.
  - Example 2: User with intermediate oral proficiency level
    - Daily Practice Content: Complex conversation scenarios, such as hobbies, sports, weather, work, travel, etc.
    - Duration: At least 45 minutes per day.
    - Expected Goal: To be able to converse freely in various daily scenarios.
  - Example 3: User with advanced oral proficiency level
    - Daily Practice Content: Conversations in professional fields, such as business negotiations, academic discussions, etc.
    - Duration: At least 1 hour per day.
    - Expected Goal: To be able to engage in in-depth conversations freely within professional fields.
'''

1.2 口语陪练对话

有了训练计划,自然希望它能够严格遵循训练计划,来和我展开练习,因此设计的角色提示词如下:

复制代码
sys_english_teacher = '''
- Role: English Oral Practice Specialist
- Background: Users wish to enhance their spoken English skills through interaction with you. You need to initiate conversational practice with users based on the oral practice plans they provide and the current date.
- Profile: You are a professional English oral practice specialist with extensive teaching experience and conversational skills, capable of conducting effective oral practice according to the users' plans and progress.
- Skills: You possess excellent listening and speaking abilities, enabling you to understand users' oral expressions and provide appropriate responses and feedback. You also have the ability to flexibly adjust the content and difficulty of the conversation to meet the diverse needs of users.
- Goals: To start conversational practice with users based on the oral practice plans and current dates they provide, aiming to help users improve their spoken English skills.
- Constrains: Conversational practice should strictly follow the practice plans provided by users, ensuring that the content and difficulty of the conversation match the current level of the users. Positive feedback and encouragement should be given during the practice.
- OutputFormat: Response should be in English and concise, limited to a maximum of two sentences.
- Workflow:
  1. Initiate conversational practice with the user based on the practice plan and date.
  2. Provide appropriate responses and positive feedback during the conversation.
  3. If the user indicates a desire to end, summarize the user's practice and offer encouragement.
- Initialization: In the first conversation, please output the following: Hello! Based on the speaking practice plan you provided, we will start our dialogue practice today. Please feel free to begin. Let's get started!
'''

2. 核心逻辑实现

一旦触发口语陪练的逻辑,机器人需要根据用户输入,进行答复。

核心实现逻辑可以分为以下四步:

  • 陪练计划检索:从数据库中检索,当前用户是否已有陪练计划;
  • 陪练计划生成 :如果未检索到陪练计划,则调用口语陪练规划智能体,生成一份陪练计划;
  • 陪练对话初始化 :基于陪练计划,以及当前日期,初始化口语陪练对话智能体;
  • 开始口语练习:从数据库中检索已有对话记录,拼接成上下文,送给智能体,开始对话流程。

下面,对上述逻辑进行代码实现,供大家参考:

复制代码
# 首先检索是否有口语陪练计划,如果没有计划,则生成一个
res = get_message(fid, limit=1, msg_type='plan', table='en')
if not res:
    plan_content = get_english_plan(asr_text)
    plan_start = datetime.now().strftime("%Y%m%d%H%M%S")
    add_message(fid, plan_content, msg_type='plan', timestamp=plan_start, table='en')
    logger.info(f"未找到口语陪练计划,已生成:{plan_start}")
else:
    plan_content = res[0]['content']
    plan_start = res[0]['timestamp']
    logger.info(f"找到口语陪练计划:{plan_start}")
delta = int(datetime.now().strftime("%Y%m%d"))- int(plan_start[:8]) + 1
logger.info(f"口语陪练,今天是第{delta}天")
messages = [
        {'role': 'system', 'content': f'{sys_english_teacher}\nThe practice plan is {plan_content} and today is Day {delta}.'}
]
# 拼接聊天记录作为上下文
messages.extend(self.get_messages_record(fid, msg_type='qa', start_time=plan_start, table='en'))
messages.append({'role': 'user', 'content': asr_text})
# 大模型流式输出 + 语音合成
llm_text = ''
for i, text in enumerate(self.llm_api.stream(messages, punct_list=punct_list_en)):
    llm_text += text
    tts_flag = self.get_tts_result(text)
    self.play_audio(tts_file)
# 消息存入 Message table
add_message(fid, f'{asr_text}|{llm_text}', msg_type='qa', timestamp=datetime.now().strftime("%Y%m%d%H%M%S"), table='en')

3. 效果展示

先给大家展示下口语陪练规划智能体的效果:

复制代码
'我想练习英语口语,目前初级英语水平,帮我制定一个7天的学习计划'

下面是模型输出,挺像样吧。

再来看一段口语陪练对话智能体的效果:

英语口语陪练机器人

写在最后

本文带大家实操了 AI 口语陪练 的本地部署。

有了它,还报什么辅导班?希望可以帮你省下一笔培训费~

如果对你有帮助,欢迎点赞收藏备用。


AI 不应是冰冷的代码,而应是有温度的伴侣

为方便大家交流,新建了一个 AI 交流群,欢迎感兴趣的小伙伴加入。

最近打造的微信机器人小爱(AI)也在群里,公众号后台「联系我」,拉你进群。

相关推荐
QQ67658008几秒前
城市治理之河道污染识别 无人机河道污染巡检 塑料带识别 瓶子图像识别 深度学习垃圾识别第10384期
人工智能·深度学习·yolo·河道污染·无人机河道污染·瓶子图像·塑料袋识别
风象南1 分钟前
当技术解决了一切“怎么做”,人类还剩下什么?
人工智能
skilllite作者5 分钟前
SkillLite 多入口架构实战:CLI / Python SDK / MCP / Desktop / Swarm 一页理清
开发语言·人工智能·python·安全·架构·rust·agentskills
2501_933329557 分钟前
技术深度剖析:Infoseek 字节探索舆情处置系统的全链路架构与核心实现
大数据·数据仓库·人工智能·自然语言处理·架构
网安情报局8 分钟前
RSAC 2026深度解析:AI对抗AI成主流,九大安全能力全面升级
人工智能·网络安全
key_3_feng8 分钟前
揭秘AI的“语言积木“:Token科普之旅
人工智能·搜索引擎·token
代码丰8 分钟前
Zero Code Studio:LangChain4j 工具调用 + LangGraph4j 工作流双模式的 AI 网站生成系统
java·人工智能
人工智能培训9 分钟前
多模态AI模型融合难?核心问题与解决思路
人工智能·机器学习·prompt·agent·智能体
FAFU_kyp9 分钟前
AP2 (Agent Payments Protocol) 技术流程详细解析
人工智能
北京耐用通信15 分钟前
工业自动化场景下耐达讯自动化的 CC-Link IE 转 Modbus TCP 技术方案与应用实践
人工智能·科技·物联网·网络协议·自动化