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

【AI实践】本地部署ASR模型OpenAI Whisper

上一篇部署了ComfyUI,【AI实践】本地部署ComfyUI-CSDN博客

打通了CUDA,torch等环境,部署其它的会方便很多。

直接复制comfyui的环境,免安装一些组件

conda env list
conda create -n whisper --clone rtx50_comfyui pip install PySocks win-inet-pton    
conda activate whisper 
cd .\workspace\   
set HTTP_PROXY=http://127.0.0.1:1080
set HTTPS_PROXY=http://127.0.0.1:1080
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080        
pip install git cloe kshttps://github.com/openai/whisper.git 
conda install -c conda-forge ffmpeg

运行下test.py,内容如下
 

import whisper 
model = whisper.load_model("base").cuda() 
print(whisper.__version__)

运行下转录whisper_transcribe.py 

import whisper # 加载模型(使用 GPU) 
model = whisper.load_model("base").cuda() # 转录示例音频 
result = model.transcribe("example.wav", language="zh") 
print(result["text"]) 
 python .\whisper_transcribe.py 

录音转录

import sounddevice as sd
import numpy as np
import whisperdef record_audio(duration=5, samplerate=16000):print(f"正在录音 {duration} 秒...")audio = sd.rec(int(duration * samplerate), samplerate=samplerate, channels=1, dtype='float32')sd.wait()print("录音结束。")return np.squeeze(audio)def save_wav(filename, audio, samplerate=16000):import scipy.io.wavfilescipy.io.wavfile.write(filename, samplerate, (audio * 32767).astype(np.int16))def transcribe(audio, samplerate=16000):model = whisper.load_model("base")# Whisper 需要文件输入,先保存为 wavtemp_wav = "temp.wav"save_wav(temp_wav, audio, samplerate)result = model.transcribe(temp_wav, language="zh")return result["text"]if __name__ == "__main__":duration = 20  # 录音时长(秒)samplerate = 16000audio = record_audio(duration, samplerate)text = transcribe(audio, samplerate)print("识别结果:", text)

http://www.dtcms.com/a/328709.html

相关文章:

  • Kafka工作机制深度解析:Broker、Partition 与消费者组协作原理
  • 自由学习记录(83)
  • Linux 软件编程:文件IO、目录IO、时间函数
  • GitHub分支保护介绍(Branch Protection)(git分支保护)(通过设置规则和权限来限制对特定分支的操作的功能)
  • 11.用反射为静态类的属性赋值 C#例子 WPF例子
  • K8S中,kubectl cordon、uncordon、drain、taint的区别
  • 计算机网络---用户数据报协议User Datagram Protocol(UDP)
  • 【Part 4 未来趋势与技术展望】第一节|技术上的抉择:三维实时渲染与VR全景视频的共生
  • vue--video使用动态src时,视频不更新
  • Java零基础笔记16(Java编程核心:存储读写数据方案—File文件操作、IO流、IO框架)
  • 利用生成式AI与大语言模型(LLM)革新自动化软件测试 —— 测试工程师必读深度解析
  • PythonDay25
  • Android实现Glide/Coil样式图/视频加载框架,Kotlin
  • 《C++进阶之继承多态》【final + 继承与友元 + 继承与静态成员 + 继承模型 + 继承和组合】
  • mapbox进阶,实现精灵图生成和拆分(小图任意大小,不固定),并简单使用
  • 选择排序专栏
  • Docker安装influxdb以及python基本操作
  • 传输层协议 TCP(1)
  • latex 中将新的一个section重新从1开始排序,而不是和前面的section继续排序
  • 更改webpack默认配置项
  • 第二十二天:指针与内存
  • 【C++详解】用红黑树封装模拟实现mymap、myset
  • 代码随想录刷题Day30
  • UnityWeb打包注意事项及与网页端通信
  • 初识c语言————排序方法
  • 【游戏开发记录】一款网游+修仙为背景的游戏
  • 美国英语 8 You‘re Going to Be Fine 早日康复
  • Dify 从入门到精通(第 32/100 篇):Dify 的日志分析与监控
  • 1688跨境寻源通API接入||跨境寻源通有哪些具体的功能和优势?
  • 反射的详解