阿里qwen大模型AI智能分析实时对话生成病例的DEMO

ops/2025/3/26 0:13:19/
aidu_pl">

Qwen大模型根据医患对话录音生成病例

  • 业务背景
    • 涉及前端技术
    • 涉及后端技术
    • 阿里云文档
    • 完整代码(复制即可运行)

业务背景

在HIS或者其他医疗系统中,为了提高医生的现场或者线上问诊工作效率,在系统的开病例这块可以通过对话录音,实时的把录音内容通过Qwen大模型直接生成病例数据,即医患对话完成即可生成病例,避免医生在手动开病例

涉及前端技术

  • 音频流(数据转化)
  • websocket
  • 有可能涉及到nginx解决跨域问题

涉及后端技术

  • nodejs
  • nginx配置

阿里云文档

  • https://help.aliyun.com/zh/isi/developer-reference/sdk-for-node-js?spm=a2c4g.11186623.help-menu-30413.d_3_0_1_6.4182626bmyHNeU&scm=20140722.H_410564._.OR_help-T_cn~zh-V_1

完整代码(复制即可运行)

  • HTML
	 <h1>实时语音识别</h1><div><label for="appkey">AppKey:</label><inputtype="password"id="appkey"value="你的阿里智能语音应用的Appkey"placeholder=""/></div><div><label for="token">Token:</label><inputtype="password"id="token"value="你的阿里智能语音应用的token"placeholder="请输入 Token"/></div><div id="status">未连接</div><div id="messages"></div><button onclick="connectWebSocket()">开始连接</button><button onclick="startRecording()" disabled id="startButton">开始录音</button><button onclick="stopRecording()" disabled id="stopButton">停止录音</button><button onclick="disconnectWebSocket()" disabled id="disconnectButton">断开连接</button>
  • CSS
  <style>body {font-family: Arial, sans-serif;margin: 20px;}#status {margin-bottom: 10px;color: green;}#messages {border: 1px solid #ccc;padding: 10px;height: 200px;overflow-y: scroll;margin-bottom: 10px;}button {margin: 5px;}</style>
  • JS
    <script>let websocket;let audioContext;let scriptProcessor;let audioInput;let audioStream;let allText = "";let lastIndex = 1;let currentDialogueArr = [];const aiCase = (caseDescription) => {var url = "你自己的AI后端接口";var data = {caseDescription,};fetch(url, {method: "POST", // 设置请求方法为POSTheaders: {"Content-Type": "application/json", // 设置请求头信息"Accept-Encoding": "gzip, deflate, br",Connection: "keep-alive",Accept: "*/*","User-Agent": "PostmanRuntime/7.37.3",Authorization:"你自己的Authorization",},body: JSON.stringify(data), // 将JavaScript对象转换为JSON字符串并作为请求体发送}).then((response) => response.json()) // 解析响应为JSON格式.then((data) => {// 请求成功,处理返回的数据console.log("解析数据", data);logMessage("AI病例最终解析: " + JSON.stringify(data));}).catch((error) => {// 处理请求错误console.error("Error:", error);});};// 更新连接状态function updateStatus(status) {document.getElementById("status").textContent = status;document.getElementById("status").style.color =status === "已连接" ? "green" : "red";}// 生成 UUIDfunction generateUUID() {return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>(c ^(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)).replace(/-/g, "");}// 打开WebSocket连接function connectWebSocket() {const appkey = document.getElementById("appkey").value;const token = document.getElementById("token").value;const socketUrl = `wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1?token=${token}`;websocket = new WebSocket(socketUrl);websocket.onopen = function () {updateStatus("已连接");logMessage("连接到 WebSocket 服务器");var startTranscriptionMessage = {header: {appkey: appkey,namespace: "SpeechTranscriber",name: "StartTranscription",task_id: generateUUID(),message_id: generateUUID(),},payload: {format: "pcm",sample_rate: 16000,enable_intermediate_result: true,enable_punctuation_prediction: true,enable_inverse_text_normalization: true,},};websocket.send(JSON.stringify(startTranscriptionMessage));};const concatText = (data) => {if (data.payload && data.payload.index) {let index = data.payload.index;if (index === 1) {currentDialogueArr.push(data.payload);} else if (index === lastIndex) {currentDialogueArr.push(data.payload);}if (index > lastIndex) {lastIndex++;allText +=currentDialogueArr[currentDialogueArr.length - 1]?.result;currentDialogueArr = [];}}console.log("结果", allText);};websocket.onmessage = function (event) {// logMessage("服务端: " + event.data);const message = JSON.parse(event.data);concatText(message);if (message.header.name === "TranscriptionStarted") {// 启用开始录音按钮document.getElementById("startButton").disabled = false;document.getElementById("stopButton").disabled = false;}};websocket.onerror = function (event) {updateStatus("错误");logMessage("WebSocket 错误: " + event);};websocket.onclose = function () {updateStatus("断开连接");logMessage("与 WebSocket 服务器断开");};document.getElementById("disconnectButton").disabled = false;}// 断开WebSocket连接function disconnectWebSocket() {if (websocket) {websocket.close();}document.getElementById("disconnectButton").disabled = true;updateStatus("未连接");}// 日志消息function logMessage(message) {const messagesDiv = document.getElementById("messages");const messageElement = document.createElement("div");messageElement.textContent = message;messagesDiv.appendChild(messageElement);messagesDiv.scrollTop = messagesDiv.scrollHeight;}// 开始录音let inputData16 = null;async function startRecording() {try {// 获取音频输入设备audioStream = await navigator.mediaDevices.getUserMedia({audio: true,});audioContext = new (window.AudioContext || window.webkitAudioContext)({sampleRate: 16000,});audioInput = audioContext.createMediaStreamSource(audioStream);// 设置缓冲区大小为2048的脚本处理器scriptProcessor = audioContext.createScriptProcessor(2048, 1, 1);scriptProcessor.onaudioprocess = function (event) {const inputData = event.inputBuffer.getChannelData(0);inputData16 = new Int16Array(inputData.length);for (let i = 0; i < inputData.length; ++i) {inputData16[i] = Math.max(-1, Math.min(1, inputData[i])) * 0x7fff; // PCM 16-bit}if (websocket && websocket.readyState === WebSocket.OPEN) {websocket.send(inputData16.buffer);// logMessage("发送音频数据块");}};audioInput.connect(scriptProcessor);scriptProcessor.connect(audioContext.destination);} catch (e) {logMessage("录音失败: " + e);}}// 停止录音function stopRecording() {//加上最后一句allText += currentDialogueArr[currentDialogueArr.length - 1]?.result;console.log("加上最后一句", allText);// 发送给AI大模型aiCase(allText);if (scriptProcessor) {scriptProcessor.disconnect();}if (audioInput) {audioInput.disconnect();}if (audioStream) {audioStream.getTracks().forEach((track) => track.stop());}if (audioContext) {audioContext.close();}document.getElementById("startButton").disabled = true;document.getElementById("stopButton").disabled = true;}</script>

http://www.ppmy.cn/ops/169787.html

相关文章

AI小白的第七天:必要的数学知识(概率)

概率 Probability 1. 概率的定义 概率是一个介于 0 和 1 之间的数&#xff0c;表示某个事件发生的可能性&#xff1a; 0&#xff1a;事件不可能发生。1&#xff1a;事件必然发生。0 到 1 之间&#xff1a;事件发生的可能性大小。 例如&#xff0c;掷一枚公平的硬币&#xf…

C++学习笔记(二十六)——deque

一、std::deque &#xff08;1&#xff09;deque与其适用场景 std::deque&#xff08;双端队列&#xff0c;double-ended queue&#xff09;是 C STL&#xff08;标准模板库&#xff09;中的序列容器&#xff0c;类似于 std::vector&#xff0c;但支持在两端高效地插入和删除…

HDFS相关的面试题

以下是150道HDFS相关的面试题&#xff0c;涵盖了HDFS的基本概念、架构、操作、数据存储、高可用性、权限管理、性能优化、容错机制、与MapReduce的结合、安全性、数据压缩、监控与管理、与YARN的关系、数据一致性、数据备份与恢复等方面&#xff0c;希望对你有所帮助。 HDFS基本…

C语言简介

C语言是一种通用的、过程式的编程语言&#xff0c;由Dennis Ritchie在20世纪70年代初于贝尔实验室开发。它最初是为UNIX操作系统设计的&#xff0c;但后来因其高效、灵活和可移植性强的特点&#xff0c;成为了一种广泛使用的编程语言。C语言对许多现代编程语言&#xff08;如C、…

【Hbase】查看所有表

在 HBase 中&#xff0c;查看所有表时&#xff0c;通常不需要指定命名空间&#xff0c;除非有特殊需求或配置。以下是一些具体情况&#xff1a; 默认情况下 • HBase Shell&#xff1a;使用list命令时&#xff0c;默认会列出所有命名空间中的所有表&#xff0c;而不仅仅是默认…

struts1+struts2项目兼容升级到了spring boot 2.7

原项目比较复杂&#xff0c;集成了各种框架&#xff08;struts1 struts2 spring3等&#xff09;&#xff0c;趁工作之余练练手&#xff0c;学习一下springboot。大概花了一周时间才调通。 一、调整jar版本&#xff0c;寻找合适的版本。 第一步、首先原项目JDK6&#xff0c;要…

学习记录-Ajax-自封装axios函数

目录 自封装axios函数封装axios函数实现步骤1. 准备阶段2. 实现无参get请求3.实现有参get请求4. 实现post请求 完整实例代码 自封装axios函数 封装axios函数实现步骤 1. 准备阶段 理解axios函数的底层原理&#xff0c;包括Promise,XMLHttpRequest等概念 XMLHttpRequest工作…

C#中迭代器和IEnumerator 接口和IEnumerable 接口的区别和作用

在C#里&#xff0c;迭代器、IEnumerator 接口以及 IEnumerable 接口都和集合遍历相关&#xff0c;不过它们的作用和使用场景存在差异。下面为你详细介绍&#xff1a; 1. IEnumerable 接口 作用&#xff1a;IEnumerable 接口用于表明一个类或结构可以被迭代。实现了 IEnumerab…