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

相关推荐
Swift社区2 天前
用 Whisper 打破沉默:AI 语音技术如何重塑无障碍沟通方式?
人工智能·whisper
dgiij12 天前
openai-whisper-asr-webservice接入dify
docker·ai·node.js·whisper
allnlei13 天前
whisper相关的开源项目 (asr)
whisper·asr
phper818 天前
开源音视频转文字工具:基于 Vosk 和 Whisper 的多语言语音识别项目
whisper·音视频·语音识别
AI360labs_atyun19 天前
使用 Whisper 生成视频字幕:从提取音频到批量处理
人工智能·科技·ai·whisper·音视频·教育
waterHBO1 个月前
python + whisper 读取蓝牙耳机, 转为文字
python·whisper
代码骑士1 个月前
基于whisper和ffmpeg语音转文本小程序
whisper
Luke Ewin2 个月前
一个基于OpenAI Whisper开发的音视频字幕文件生成工具
人工智能·whisper·音视频·语音识别·asr·语音转写·视频字幕生成
Encarta19932 个月前
【语音识别】vLLM 部署 Whisper 语音识别模型指南
人工智能·whisper·语音识别
JHC0000002 个月前
ubuntu 下调用系统麦克风,以及faster-whisper-medium 处理音频转写文本
ubuntu·whisper·音视频