华为云Flexus+DeepSeek征文|基于Dify+ModelArts开发AI智能会议助手
1. 背景与目标
企业会议效率提升需求强烈,传统人工记录会议纪要耗时耗力。本文将指导如何基于Dify平台
,结合华为云ModelArts Studio服务
和华为云实时语音识别(RASR)
服务,构建一个智能会议助手,实现:
语音转文字(华为云实时语音识别 RASR)
会议纪要自动生成(Dify + LLM)
待办事项提取(结构化输出)
实时语音识别 RASR
实时语音识别(Real-time ASR),将连续的音频流实时转换成文本,语音识别更快。可应用于直播实时字幕、会议实时记录、即时文本生成等场景
2. 前期准备
2.1 华为云账号与权限
注册华为云账号:华为云官网
开通以下服务:
Dify 应用开发平台(Dify 控制台)
语音识别(RASR)(RASR 文档)
大模型服务(如盘古大模型,或兼容的第三方 LLM)
2.2 开发环境
Python 3.8+(用于调用华为云ModelArts API)
requests 库(HTTP 请求)
ffmpeg(音频格式转换,可选)
安装依赖:
pip install requests
3. 核心功能实现
3.1 华为云实时语音识别(RASR)- 语音转文字
华为云 RASR 支持多种音频格式(如 .wav、.mp3),需先获取 Access Key 和 Project ID。
代码示例:调用华为云 RASR
import requests
import base64
import json
import time# 华为云 RASR 配置
AK = "your-access-key" # 替换为你的 Access Key
SK = "your-secret-key" # 替换为你的 Secret Key
PROJECT_ID = "your-project-id" # 替换为你的 Project ID
REGION = "cn-north-4" # 华北-北京四
RASR_URL = f"https://rasr.{REGION}.myhuaweicloud.com/v1/{PROJECT_ID}/speech-to-text"def get_token():"""获取华为云 Token"""token_url = "https://iam.myhuaweicloud.com/v3/auth/tokens"headers = {"Content-Type": "application/json"}data = {"auth": {"identity": {"methods": ["password"],"password": {"user": {"name": "your-username", # 替换为你的用户名"password": "your-password", # 替换为你的密码"domain": {"name": "your-domain"} # 替换为你的域名}}},"scope": {"project": {"id": PROJECT_ID}}}}response = requests.post(token_url, headers=headers, json=data)return response.headers["X-Subject-Token"]def speech_to_text(audio_file_path):"""语音转文字"""token = get_token()headers = {"Content-Type": "application/json","X-Auth-Token": token}# 读取音频文件并转为 Base64with open(audio_file_path, "rb") as f:audio_data = base64.b64encode(f.read()).decode("utf-8")# 构造请求体payload = {"config": {"encoding": "WAV", # 音频格式(WAV/MP3)"sample_rate": 16000, # 采样率(16kHz)"language": "zh-CN" # 语言(中文)},"audio": {"data": audio_data}}response = requests.post(RASR_URL, headers=headers, json=payload)result = response.json()if "result" in result:return result["result"]["text"]else:raise Exception("RASR 转换失败: " + str(result))# 测试
if __name__ == "__main__":text = speech_to_text("meeting_recording.wav")print("转写结果:", text)
输出示例:
转写结果: 今天的会议主要讨论了项目进度和下一步计划…
3.2 Dify 平台配置 LLM 会议助手
3.2.1 创建 Dify 应用
登录 Dify 控制台,点击“创建应用”。
选择“从零开始”或“智能对话助手”模板。
配置 LLM(如华为云盘古大模型或兼容的 GPT 模型)。
3.2.2 设计 Prompt(提示词工程)
在 Dify 中配置 LLM 的输入 Prompt,例如:
你是一个智能会议助手,请根据以下会议记录,生成结构化纪要:
- 会议主题
- 主要讨论内容
- 关键决策
- 待办事项(格式:- [任务](负责人:XXX,截止时间:XXX))
会议记录:
{input_text}
3.2.3 调用 Dify API 生成纪要
Dify 提供 REST API,可通过 Python 调用。
代码示例:调用 Dify API
import requestsDIFY_API_URL = "https://api.dify.ai/v1/chat-messages" # 替换为你的 Dify API 地址
DIFY_API_KEY = "your-dify-api-key" # 替换为你的 Dify API Keydef generate_meeting_summary(meeting_text):"""调用 Dify LLM 生成会议纪要"""headers = {"Content-Type": "application/json","Authorization": f"Bearer {DIFY_API_KEY}"}payload = {"query": meeting_text,"response_mode": "blocking","user": "user-123" # 用户标识}response = requests.post(DIFY_API_URL, headers=headers, json=payload)result = response.json()return result["answer"]# 测试
if __name__ == "__main__":meeting_text = speech_to_text("meeting_recording.wav") # 先转文字summary = generate_meeting_summary(meeting_text)print("会议纪要:", summary)
输出示例:
会议纪要:
- 会议主题:Q3 项目进度汇报
- 主要讨论内容:前端开发延迟,后端 API 已完成
- 关键决策:增加前端开发人力
- 待办事项:
- [完成登录模块](负责人:张三,截止时间:2024-07-15)
- [测试支付接口](负责人:李四,截止时间:2024-07-20)
3.3 完整流程整合
将 RASR 和 Dify API 整合为一个完整脚本:
def meeting_assistant(audio_file_path):"""智能会议助手完整流程"""# 1. 语音转文字print("正在转写语音...")meeting_text = speech_to_text(audio_file_path)print("转写完成:", meeting_text[:100] + "...") # 打印前 100 字符# 2. 生成纪要print("正在生成纪要...")summary = generate_meeting_summary(meeting_text)print("会议纪要:\n", summary)if __name__ == "__main__":meeting_assistant("meeting_recording.wav")
4. 部署与扩展
4.1 部署方式
Dify 云服务:直接使用华为云托管的 Dify 服务。
私有化部署:在本地服务器部署 Dify 和 RASR 服务(需申请权限)
4.2 扩展功能
待办事项提取为 JSON:修改 LLM Prompt,让输出更结构化
多语言支持:调用华为云翻译服务(ST)。
前端集成:开发 Web 页面上传音频并展示纪要。
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>智能会议纪要生成</title><style>body {font-family: 'Arial', sans-serif;max-width: 800px;margin: 0 auto;padding: 20px;line-height: 1.6;}h1 {color: #333;text-align: center;}.upload-container {border: 2px dashed #ccc;padding: 20px;text-align: center;margin-bottom: 20px;border-radius: 5px;}.upload-container:hover {border-color: #999;}#file-input {display: none;}.upload-btn {background-color: #4CAF50;color: white;padding: 10px 20px;border: none;border-radius: 4px;cursor: pointer;font-size: 16px;}.upload-btn:hover {background-color: #45a049;}#status {margin: 20px 0;padding: 10px;border-radius: 4px;}.loading {background-color: #f8f8f8;color: #666;}.success {background-color: #dff0d8;color: #3c763d;}.error {background-color: #f2dede;color: #a94442;}#summary {white-space: pre-wrap;background-color: #f9f9f9;padding: 15px;border-radius: 4px;border: 1px solid #ddd;margin-top: 20px;}</style>
</head>
<body><h1>智能会议纪要生成</h1><div class="upload-container"><p>点击下方按钮上传会议录音文件(支持WAV/MP3格式)</p><input type="file" id="file-input" accept=".wav,.mp3"><button class="upload-btn" id="upload-btn">选择文件并生成纪要</button><p id="file-name">未选择文件</p></div><div id="status"></div><h2>会议纪要</h2><div id="summary">纪要将在此处显示...</div><script>document.getElementById('upload-btn').addEventListener('click', function() {document.getElementById('file-input').click();});document.getElementById('file-input').addEventListener('change', function(e) {if (e.target.files.length > 0) {const file = e.target.files[0];document.getElementById('file-name').textContent = '已选择: ' + file.name;} else {document.getElementById('file-name').textContent = '未选择文件';}});document.getElementById('upload-btn').addEventListener('click', function() {const fileInput = document.getElementById('file-input');if (fileInput.files.length === 0) {showStatus('请选择文件后再上传', 'error');return;}const file = fileInput.files[0];if (!['wav', 'mp3'].includes(file.name.split('.').pop().toLowerCase())) {showStatus('只支持WAV或MP3格式的音频文件', 'error');return;}uploadFile(file);});function uploadFile(file) {showStatus('正在上传文件...', 'loading');const formData = new FormData();formData.append('audio', file);fetch('/upload', {method: 'POST',body: formData}).then(response => response.json()).then(data => {if (data.success) {showStatus('纪要生成成功!', 'success');document.getElementById('summary').textContent = data.summary;} else {showStatus('错误: ' + data.error, 'error');}}).catch(error => {showStatus('上传失败: ' + error.message, 'error');});}function showStatus(message, type) {const statusDiv = document.getElementById('status');statusDiv.textContent = message;statusDiv.className = type;}</script>
</body>
</html>
5. 总结
本文介绍了如何基于华为云 Dify 平台搭建大语言模型会议助手,核心步骤包括:
语音转文字(华为云 RASR)
LLM 纪要生成(Dify + Prompt 工程)
API 整合与自动化
通过此方案,企业可快速实现会议自动化,大幅提升效率! 🚀