本地部署语音转文字(whisper,SpeechRecognition)

本地部署语音转文字

1.whisper

1.首先安装Chocolatey

https://github.com/openai/whisper

以管理员身份运行PowerShell

python 复制代码
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco -v#查看版本确定安装成功
Set-ExecutionPolicy AllSigned
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

2.安装

python 复制代码
choco install ffmpeg
pip install setuptools-rust
pip install -U openai-whisper

3.使用

python 复制代码
whisper 1207.m4a --language Chinese --model medium --device cuda:0 

2.SpeechRecognition

1.环境

python 复制代码
pip install SpeechRecognition
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pocketsphinx

2.中文包

在这个虚拟环境的\site-packages\speech_recognition\pocketsphinx-data目录下添加zh-CN中文包。

3.格式转化

因为这个离线只支持一下三种格式,所以利用ffmpeg将语音转换成wav格式,这个包在装whisper的时候已经装好了,所以直接用:

python 复制代码
 ffmpeg -i 12072.m4a output.wav
  • 1.WAV
    2.AIFF/AIFF-C
    3.FLAC

4.运行

python 复制代码
import speech_recognition as sr
audio_file = 'output.wav'
r = sr.Recognizer()
with sr.AudioFile(audio_file) as source:
    audio = r.record(source)
# 识别音频文件
result = r.recognize_sphinx(audio, language="zh-CN")
print(result)

3.效果

相关推荐
不喝可乐_16 小时前
在win11 中 whisper-large-v3-turbo 的简单使用
whisper
毛毛的毛毛4 天前
如何使用OPENAI的Whisper功能进行音频字母提取功能
whisper
Secede.7 天前
Whisper+T5-translate实现python实时语音翻译
开发语言·python·whisper
烤鸭的世界我们不懂7 天前
Python + WhisperX:解锁语音识别的高效新姿势
python·whisper·语音识别
落杉丶23 天前
[ASR]faster-whisper报错Could not locate cudnn_ops64_9.dll
python·whisper
drebander1 个月前
Whisper-Medium 模型:音频转文本的原理、实践与硬件推荐
whisper·音视频
drebander1 个月前
Whisper-Tiny 模型:音频转文本的原理与实践
whisper·音视频
大模型之路1 个月前
OpenAI Whisper:语音识别技术的革新者—深入架构与参数
人工智能·whisper·语音识别
南棱笑笑生1 个月前
20250109使用M6000显卡在Ubuntu20.04.6下跑whisper来识别中英文字幕
whisper
飘逸高铁侠1 个月前
使用 whisper和ffmpeg 烧录视频的中英文双语字幕
ffmpeg·whisper·音视频