本地部署语音转文字(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.效果

相关推荐
J心流4 天前
89ms实时Whisper,显存还降48%
whisper
iDao技术魔方8 天前
whisper.cpp 深度解析:从边缘设备到实时语音识别
人工智能·whisper·语音识别
Gc9umsbL111 天前
从FLAC到WAV:whisper.cpp中的FFmpeg音频预处理全解析
ffmpeg·whisper·音视频
Bofu-15 天前
【音频测试】03-WPF 实现声道自动验证 + Whisper 语音识别录音检测
c#·whisper·wpf·音视频·音频测试·naudio 声道控制
JK Chen18 天前
faster_whisper,视频转文字,并生成字幕文件
python·whisper·音视频
工作log20 天前
10分钟搭建本地语音识别服务 (Whisper large-v3-turbo)
人工智能·whisper·语音识别
shao91851621 天前
第10章 Streaming(上):初级音频应用(1)——项目三:自建服务器的Mini-Omni实时语音聊天机器人
ffmpeg·whisper·asr·mini-omni·自建语音服务器
code_pgf25 天前
MNN Whisper 实时 ASR 工程实现
人工智能·whisper·mnn
独占的甜蜜1 个月前
从FLAC到WAV:whisper.cpp中的FFmpeg音频预处理全解析过程
ffmpeg·whisper·音视频
独占的甜蜜1 个月前
从FLAC到WAV:whisper.cpp中的FFmpeg音频预处理全解析
ffmpeg·whisper·音视频