当前位置: 首页 > news >正文

企业门户网站需求分析2345网址导航大全

企业门户网站需求分析,2345网址导航大全,湛江做网站公司,临清网站建设费用一、前言 在上一节中,学习了如何使用vLLM来部署Whisper-large-v3-turbo模型。不过,在实际使用时,模型一次只能处理30秒的音频。今天,将结合实际业务,介绍如何处理一段完整的音频,并生成相应的字幕文件。 相…

一、前言

   在上一节中,学习了如何使用vLLM来部署Whisper-large-v3-turbo模型。不过,在实际使用时,模型一次只能处理30秒的音频。今天,将结合实际业务,介绍如何处理一段完整的音频,并生成相应的字幕文件。

    相关文章,请参见:

    开源模型应用落地-语音转文本-whisper模型-AIGC应用探索(一)

    开源模型应用落地-语音转文本-whisper模型-AIGC应用探索(二)

    开源模型应用落地-语音转文本-whisper模型-AIGC应用探索(三)

    开源模型应用落地-语音转文本-whisper模型-AIGC应用探索(四)


二、术语介绍

2.1. 语音转文本

    也称为语音识别或自动语音识别 (ASR)是一种将语音音频转换为文字的技术。它利用计算机程序和算法来监听语音输入,并将其转换为可读的文字输出。

2.2. Whisper-large-v3-turbo

    是 OpenAI 于 2024年10月推出的一款优化型语音转录模型,基于 Whisper large-v3 改进而来,旨在平衡速度与准确性。以下是其核心特点:

1.技术改进

  • 解码器层数缩减:从 32 层减少至 4 层,显著降低计算复杂度。
  • 速度提升:转录速度较 large-v3 快 8 倍,超越 tiny 模型,支持实时应用。
  • 推理优化:结合 torch.compile 和缩放点积注意力(F.scaled_dot_product_attention),进一步加速推理,减少延迟。
  • 参数规模:8.09 亿参数,介于 medium(7.69 亿)与 large(155 亿)之间,模型体积约 1.6GB。

2.性能表现

  • 质量保持:在高质量录音(如 FLEURS 数据集)上表现接近 large-v2,跨语言能力与 large-v2 相当。
  • 多语言支持:覆盖 99 种语言,但对泰语、粤语等方言支持较弱。
  • VRAM 需求:仅需 6GB,显著低于 large 模型的 10GB,适合边缘设备部署。

3.应用场景

  • 实时转录:适用于会议记录、直播字幕等低延迟场景。
  • 长音频处理:支持分块或顺序算法处理超长音频,兼顾速度与准确性。
  • 本地化部署:轻量化设计,便于在移动端或本地服务器集成。

4.集成与使用

  • 开发友好:通过 Hugging Face Transformers 库或 OpenAI 官方工具调用,提供 Python 示例代码。
  • 专注转录:训练数据不含翻译内容,不支持语音翻译任务,纯转录性能更优。

5.对比优势

  • 速度与质量平衡:较 large-v3 速度提升明显,质量损失极小。
  • 性价比:参数规模与 medium 接近,但性能更优,适合资源有限的场景。

三、构建环境

3.1.基础环境构建

conda create -n test python=3.10
conda activate testpip install pydub -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install openai -i https://pypi.tuna.tsinghua.edu.cn/simple

3.2.下载模型

huggingface:

https://huggingface.co/openai/whisper-large-v3-turbo/tree/main

ModelScope:

git clone https://www.modelscope.cn/iic/Whisper-large-v3-turbo.git

下载完成(建议使用HuggingFace):


四、技术实现

4.1.启动vLLM服务

vllm serve /data/model/whisper-large-v3-turbo  --swap-space 16 --disable-log-requests --max-num-seqs 256 --host 0.0.0.0 --port 9000  --dtype float16 --max-parallel-loading-workers 1  --max-model-len 448 --enforce-eager --gpu-memory-utilization 0.99 --task transcription 

调用结果:

GPU占用:

4.2.定义STT工具类

  请求私有化部署的语音转文本服务

# -*-  coding:utf-8 -*-from openai import OpenAIopenai_api_key = "EMPTY"
openai_api_base = "http://127.0.0.1:9000/v1"
model = "/data/model/whisper-large-v3-turbo"
language = "en"
response_format = "json"
temperature = 0.0class STT:def __init__(self):self.client = OpenAI(api_key=openai_api_key,base_url=openai_api_base,)def request(self,audio_path):with open(str(audio_path), "rb") as f:transcription = self.client.audio.transcriptions.create(file=f,model="/data/model/whisper-large-v3-turbo",language=language,response_format=response_format,temperature=temperature)if transcription:return transcription.textelse:return ''if __name__ == '__main__':audio_path = r'E:\temp\0.mp3'stt = STT()text = stt.request(audio_path)print(f'text: {text}')
 调用结果:

4.3.切分音频生成字幕文件

  需求:

  1.   字幕数据按每一分钟进行聚合
  2.   字幕文件包json格式保存,文件格式如下
{"time_begin": 0.0,"time_end": 60000.0,"text": "Hello World,Hello World,Hello World,Hello World,Hello World!"
}
import json
import os.pathfrom pydub import AudioSegmentfrom com.ai.uitl.stt_util import STTstt = STT()def create_directory_if_not_exists(directory_path):# 判断目录是否存在if not os.path.exists(directory_path):try:# 创建目录os.makedirs(directory_path)print(f"目录 '{directory_path}' 已创建。")except Exception as e:print(f"创建目录 '{directory_path}' 时发生错误: {e}")else:print(f"目录 '{directory_path}' 已存在。")def split(file_name,input_dir,output_dir,duration,json_file_output):create_directory_if_not_exists(output_dir)input_path = os.path.join(input_dir,file_name)# 加载音频文件audio = AudioSegment.from_file(input_path, format="mp3")# 音频文件的时长duration_seconds = audio.duration_secondsduration_milliseconds = duration_seconds * 1000start_time,end_time = 0.00,0.00index = 0text = ''all_objs = []one_minute_obj = {}# 指定切割开始时间和结束时间(单位为毫秒)while end_time < duration_milliseconds:start_time = end_timeend_time = start_time+durationif end_time > duration_milliseconds:end_time = duration_milliseconds# 切割音频cropped_audio = audio[start_time:end_time]output_file_name = f'{file_name}_{index}.mp3'output_path = os.path.join(output_dir,output_file_name)# 保存切割后的音频cropped_audio.export(output_path, format="mp3")result = index % 2if result == 0:text = stt.request(output_path)one_minute_obj['time_begin'] = start_timeelse:text = text + stt.request(output_path)one_minute_obj['time_end'] = end_timeone_minute_obj['text'] = textall_objs.append(one_minute_obj)one_minute_obj = {}index += 1result = index % 2if result != 0:one_minute_obj['text'] = textone_minute_obj['time_end'] = end_timeall_objs.append(one_minute_obj)# 打开文件并写入 JSON 数据with open(json_file_output, 'w', encoding='utf-8') as json_file:json.dump(all_objs, json_file, ensure_ascii=False, indent=4)if __name__ == '__main__':file_arr = ['1277.mp3', '1279.mp3']input_dir = r"E:\temp"for file_name in file_arr:temp_json_file_name = file_name+'_字幕文件.json'output_dir = r"E:\temp\output"output_dir = os.path.join(output_dir,file_name)json_file_output = os.path.join(output_dir,temp_json_file_name)split(file_name,input_dir,output_dir,30000.00,json_file_output)

http://www.cadmedia.cn/news/9030.html

相关文章:

  • 营销型网站建设策划书怎么写百度指数查询网
  • 软件技术的就业方向泉州seo优化
  • 德阳市建设局网站关键词挖掘站长工具
  • 网站后台用什么做服务器南阳本地网络推广优化公司
  • wordpress 36氪主题广州seo推广优化
  • 贵阳市住房和城乡建设部网站世界军事新闻
  • 宁夏自治区住房与城乡建设厅网站外链seo
  • 山东军辉建设集团有限公司 公司网站网址百度排名优化软件
  • 社区居委会网站建设wp博客seo插件
  • 营销类图片整站seo怎么做
  • 洞头区网站建设收费百度竞价点击工具
  • 广告设计与制作专业技能南宁seo多少钱报价
  • 百度网站关键词百度西安
  • 上海市官方网站营销策略方案
  • 济南城乡建设官方网站网站提交工具
  • 重庆最新情况 最新消息前端seo怎么优化
  • 江苏建设工程网站seo核心技术排名
  • vs2017 网站开发环境网页搜索优化
  • 企业网站建设中存在的问题分析百度地图关键词优化
  • 关于政府网站建设工作讲话北京seo薪资
  • 昆明网站推广公司可以免费打开网站的软件下载
  • web网站开发用什么语言免费建自己的网址
  • 湖南专业竞价优化服务成都seo优化公司排名
  • 菏泽市建设银行网站获客渠道找精准客户
  • 格力网站建设首页seo 的作用和意义
  • 兰州网站建设q.479185700惠四川成都最新消息
  • 做58网站怎么赚钱网络市场的四大特点
  • 坛墨网站建设百度seo白皮书
  • 首码项目网发布平台抖音视频seo霸屏
  • 开个网站建设公司多少钱小程序平台