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

相关推荐
心动啊1211 天前
了解语音识别模型Whisper
人工智能·whisper·语音识别
半壶清水1 天前
【开源免费】使用 Python + Whisper + PyDub 自动切割长音频文件
开发语言·python·语言模型·开源·whisper
熊猫钓鱼>_>11 天前
基于Trae/Whisper/FFmpeg与Knowledge Graph MCP技术开发语音生成会议纪要智能应用
开发语言·人工智能·python·深度学习·ffmpeg·whisper·trae
未来之窗软件服务12 天前
幽冥大陆(七十一) Whisper-ASR网页对接语音识别—东方仙盟练气期
javascript·whisper·语音识别·仙盟创梦ide·东方仙盟
未来之窗软件服务13 天前
幽冥大陆(六十九) Whisper-CLI —东方仙盟练气期
人工智能·whisper·语音识别·仙盟创梦ide·东方仙盟
红苕稀饭66614 天前
Whisper-Flamingo论文阅读
论文阅读·whisper
CrankZ14 天前
幕译 1.7--本地字幕生成与翻译--支持macOS,Windows
macos·whisper
未来之窗软件服务18 天前
幽冥大陆(五十七)ASR whisper-cli命令行使用 C语言—东方仙盟筑基期
c语言·开发语言·whisper·仙盟创梦ide·东方仙盟·东方仙盟自动化·东方仙盟商业开发
手揽回忆怎么睡23 天前
Java集成whisper.cpp
java·开发语言·whisper
YXWik623 天前
Linux安装Whisper(C++版)音频解析文本
linux·c++·whisper