Qwen3-ASR-1.7B企业实操:ASR结果接入Elasticsearch构建语音检索库

news2026/3/17 14:20:47
Qwen3-ASR-1.7B企业实操ASR结果接入Elasticsearch构建语音检索库1. 引言语音数据检索的挑战与解决方案语音数据正在成为企业重要的数字资产从会议录音、客服通话到培训讲座每天都会产生大量语音内容。但这些数据如果只是简单存储就像把书堆在仓库里却不做索引想要查找特定内容时只能大海捞针。传统的手工转录和关键词搜索效率低下特别是当需要从成千上万小时录音中快速定位某个技术讨论、客户需求或决策点时人工处理几乎不可能完成。Qwen3-ASR-1.7B语音识别模型为企业提供了高精度的语音转文字能力而Elasticsearch则是业界领先的全文搜索引擎。将两者结合就能构建一个强大的语音检索系统让企业能够像搜索文档一样快速检索语音内容。本文将手把手带你完成从语音识别到检索库搭建的完整流程即使你是刚接触这两个技术的新手也能跟着一步步实现。2. 环境准备与快速部署2.1 Qwen3-ASR-1.7B模型部署首先我们需要部署语音识别服务。Qwen3-ASR-1.7B是一个支持多语言的语音识别模型识别准确率高且部署简单。部署步骤在云平台镜像市场搜索ins-asr-1.7b-v1镜像选择对应的计算规格建议16GB以上显存点击部署等待实例启动完成约1-2分钟实例启动后通过7860端口访问Web界面测试功能测试语音识别是否正常工作# 简单的API测试脚本 import requests # 替换为你的实例IP api_url http://你的实例IP:7861/asr # 准备测试音频文件 files {audio: open(test_audio.wav, rb)} data {language: auto} response requests.post(api_url, filesfiles, datadata) print(识别结果:, response.json())如果返回类似下面的结果说明识别服务正常运行{ language: Chinese, text: 这是一个测试音频语音识别功能正常 }2.2 Elasticsearch环境搭建接下来部署Elasticsearch服务这里我们使用Docker快速搭建# 创建Elasticsearch容器 docker run -d --name elasticsearch \ -p 9200:9200 -p 9300:9300 \ -e discovery.typesingle-node \ -e xpack.security.enabledfalse \ docker.elastic.co/elasticsearch/elasticsearch:8.11.0 # 安装中文分词插件重要 docker exec -it elasticsearch \ bin/elasticsearch-plugin install analysis-icu # 重启服务使插件生效 docker restart elasticsearch验证Elasticsearch是否正常运行curl -X GET localhost:9200/?pretty应该能看到返回的版本信息等数据。3. 构建语音检索系统的核心架构3.1 系统整体设计我们的语音检索系统包含三个核心组件语音识别服务Qwen3-ASR处理音频文件生成文字稿数据处理管道清洗、分词、丰富识别结果检索索引Elasticsearch存储和检索文本内容音频文件 → Qwen3-ASR识别 → 文本预处理 → Elasticsearch索引 → 检索接口3.2 数据模型设计在Elasticsearch中我们需要设计合适的映射结构来存储语音识别结果# 索引映射设计 mapping { mappings: { properties: { audio_id: {type: keyword}, original_filename: {type: keyword}, duration: {type: float}, language: {type: keyword}, transcript: { type: text, analyzer: icu_analyzer # 使用中文分词 }, speakers: {type: keyword}, # 说话人信息可选 timestamp: {type: date}, metadata: {type: object} # 其他元数据 } } }4. 完整实现代码与步骤4.1 语音识别结果获取首先编写从Qwen3-ASR获取识别结果的函数import requests import json from typing import Dict, Any class ASRClient: def __init__(self, base_url: str): self.base_url base_url.rstrip(/) self.api_url f{self.base_url}:7861/asr def transcribe_audio(self, audio_path: str, language: str auto) - Dict[str, Any]: 调用ASR服务进行语音识别 try: with open(audio_path, rb) as audio_file: files {audio: audio_file} data {language: language} response requests.post(self.api_url, filesfiles, datadata) response.raise_for_status() return response.json() except Exception as e: print(f识别失败: {str(e)}) return None # 使用示例 asr_client ASRClient(http://你的实例IP) result asr_client.transcribe_audio(meeting.wav) print(f识别语言: {result[language]}) print(f识别内容: {result[text]})4.2 Elasticsearch数据导入创建Elasticsearch客户端和数据导入函数from elasticsearch import Elasticsearch from datetime import datetime import hashlib class ElasticsearchClient: def __init__(self, hosts: list [localhost:9200]): self.client Elasticsearch(hosts) self.index_name audio_transcripts def create_index(self): 创建索引并配置中文分词 if not self.client.indices.exists(indexself.index_name): mapping { mappings: { properties: { audio_id: {type: keyword}, original_filename: {type: keyword}, duration: {type: float}, language: {type: keyword}, transcript: { type: text, analyzer: icu_analyzer, fields: { keyword: {type: keyword} } }, timestamp: {type: date}, processed_at: {type: date} } }, settings: { analysis: { analyzer: { icu_analyzer: { tokenizer: icu_tokenizer } } } } } self.client.indices.create( indexself.index_name, bodymapping ) print(f索引 {self.index_name} 创建成功) def index_transcript(self, audio_path: str, asr_result: dict): 将识别结果导入Elasticsearch # 生成唯一ID audio_id hashlib.md5(audio_path.encode()).hexdigest() document { audio_id: audio_id, original_filename: audio_path.split(/)[-1], language: asr_result.get(language, unknown), transcript: asr_result.get(text, ), timestamp: datetime.now(), processed_at: datetime.now() } try: response self.client.index( indexself.index_name, idaudio_id, bodydocument ) print(f文档索引成功: {response[_id]}) return response except Exception as e: print(f索引失败: {str(e)}) return None # 初始化Elasticsearch客户端 es_client ElasticsearchClient() es_client.create_index()4.3 批量处理管道编写完整的批量处理脚本实现从音频到检索库的全流程import os import glob from tqdm import tqdm def process_audio_directory(audio_dir: str, asr_client: ASRClient, es_client: ElasticsearchClient): 批量处理目录中的所有音频文件 # 支持多种音频格式 audio_extensions [*.wav, *.mp3, *.m4a, *.flac] audio_files [] for extension in audio_extensions: audio_files.extend(glob.glob(os.path.join(audio_dir, extension))) print(f找到 {len(audio_files)} 个音频文件) success_count 0 for audio_file in tqdm(audio_files, desc处理音频文件): try: # 语音识别 asr_result asr_client.transcribe_audio(audio_file) if not asr_result: continue # 导入Elasticsearch es_client.index_transcript(audio_file, asr_result) success_count 1 except Exception as e: print(f处理文件 {audio_file} 时出错: {str(e)}) continue print(f处理完成成功处理 {success_count}/{len(audio_files)} 个文件) # 使用示例 if __name__ __main__: asr_client ASRClient(http://你的实例IP) es_client ElasticsearchClient() # 处理指定目录下的所有音频文件 process_audio_directory(/path/to/your/audio/files, asr_client, es_client)5. 高级检索功能实现5.1 智能搜索接口实现基于Elasticsearch的智能搜索功能class AudioSearch: def __init__(self, es_client: ElasticsearchClient): self.es_client es_client self.index_name audio_transcripts def search_transcripts(self, query: str, language: str None, size: int 10, from_: int 0): 搜索语音转录内容 search_body { query: { bool: { must: [ { multi_match: { query: query, fields: [transcript^3, original_filename], fuzziness: AUTO } } ] } }, highlight: { fields: { transcript: {} } }, size: size, from: from_ } # 添加语言过滤 if language: search_body[query][bool][filter] [ {term: {language: language}} ] try: response self.es_client.client.search( indexself.index_name, bodysearch_body ) return self._format_search_results(response) except Exception as e: print(f搜索失败: {str(e)}) return [] def _format_search_results(self, response: dict) - list: 格式化搜索结果 results [] for hit in response.get(hits, {}).get(hits, []): source hit[_source] highlight hit.get(highlight, {}).get(transcript, []) results.append({ audio_id: hit[_id], filename: source[original_filename], language: source[language], score: hit[_score], transcript: source[transcript], highlight: highlight[0] if highlight else None, timestamp: source[timestamp] }) return results def get_statistics(self): 获取统计信息 aggs_body { size: 0, aggs: { languages: { terms: {field: language} }, total_duration: { sum: {field: duration} } } } response self.es_client.client.search( indexself.index_name, bodyaggs_body ) return response[aggregations] # 使用搜索功能 search_engine AudioSearch(es_client) results search_engine.search_transcripts(项目进度汇报, languageChinese) for result in results: print(f文件: {result[filename]}) print(f相关度: {result[score]:.3f}) if result[highlight]: print(f匹配内容: {result[highlight]}) print(---)5.2 语音检索Web界面使用Flask构建简单的Web检索界面from flask import Flask, render_template, request, jsonify app Flask(__name__) search_engine AudioSearch(es_client) app.route(/) def index(): return render_template(search.html) app.route(/api/search) def search_api(): query request.args.get(q, ) language request.args.get(lang, ) page int(request.args.get(page, 1)) size 10 results search_engine.search_transcripts( queryquery, languagelanguage if language else None, sizesize, from_(page-1)*size ) return jsonify({ results: results, total: len(results), page: page }) app.route(/api/stats) def stats_api(): statistics search_engine.get_statistics() return jsonify(statistics) if __name__ __main__: app.run(debugTrue, port5000)相应的HTML模板templates/search.html!DOCTYPE html html head title语音内容检索系统/title style .search-result { margin: 20px 0; padding: 15px; border: 1px solid #ddd; } .highlight { background-color: yellow; font-weight: bold; } /style /head body h1语音内容检索/h1 input typetext idsearchInput placeholder输入搜索关键词... button onclicksearch()搜索/button div idresults/div script async function search() { const query document.getElementById(searchInput).value; const response await fetch(/api/search?q${encodeURIComponent(query)}); const data await response.json(); const resultsDiv document.getElementById(results); resultsDiv.innerHTML ; data.results.forEach(result { let content result.highlight || result.transcript; if (result.highlight) { content content.replace(/em(.*?)\/em/g, span classhighlight$1/span); } resultsDiv.innerHTML div classsearch-result h3${result.filename}/h3 p语言: ${result.language} | 相关度: ${result.score.toFixed(3)}/p p${content}/p /div ; }); } /script /body /html6. 企业级部署建议6.1 性能优化策略索引优化# 优化索引设置 optimized_settings { settings: { number_of_shards: 3, number_of_replicas: 1, refresh_interval: 30s, index: { max_result_window: 1000000 } } }批量处理优化def bulk_index_transcripts(transcripts: list): 批量索引文档提高性能 actions [] for transcript in transcripts: action { _index: audio_transcripts, _id: transcript[audio_id], _source: transcript } actions.append(action) from elasticsearch.helpers import bulk success, failed bulk(es_client.client, actions) return success, failed6.2 监控与维护设置监控告警和定期维护任务def check_system_health(): 系统健康检查 # 检查ASR服务 asr_health requests.get(f{asr_client.base_url}:7861/health).status_code # 检查Elasticsearch es_health es_client.client.cluster.health() return { asr_service: healthy if asr_health 200 else unhealthy, es_cluster: es_health[status], index_count: es_client.client.count(indexaudio_transcripts)[count] } # 定期清理旧数据 def cleanup_old_data(days: int 365): 清理指定天数前的数据 query { query: { range: { timestamp: { lt: fnow-{days}d/d } } } } es_client.client.delete_by_query( indexaudio_transcripts, bodyquery )7. 总结通过本文的实践我们成功构建了一个完整的企业级语音检索系统。这个系统能够高效处理语音数据利用Qwen3-ASR-1.7B进行准确的多语言语音识别智能检索内容基于Elasticsearch实现全文搜索和高亮显示易于扩展维护采用模块化设计方便后续功能扩展实际应用价值会议内容检索快速查找历史会议中的决策和讨论客服质量监控分析客户反馈和客服表现培训材料管理建立可搜索的知识库合规审计快速定位需要的语音记录下一步改进方向添加说话人分离功能区分不同发言者实现实时语音流处理支持直播场景加入情感分析识别语音中的情绪倾向构建更丰富的管理界面和权限控制这个解决方案特别适合有大量语音数据需要管理和检索的企业帮助它们从海量语音内容中挖掘价值信息提升知识管理效率。获取更多AI镜像想探索更多AI镜像和应用场景访问 CSDN星图镜像广场提供丰富的预置镜像覆盖大模型推理、图像生成、视频生成、模型微调等多个领域支持一键部署。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2419676.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…