梦见你的名字 发表于 2025-3-2 15:44:33

语音识别(whisper摆设)

whisper摆设
地址:https://github.com/openai/whisper?tab=readme-ov-file
我们使用 Python 3.9.9 和PyTorch 1.10.1 来练习和测试我们的模型,但代码库预计与 Python 3.8-3.11 和最新的 PyTorch 版本兼容。代码库还依赖于一些 Python 包,最著名的是OpenAI 的 tiktoken,用于快速标记器实现。您可以使用以下下令下载并安装(或更新到)最新版本的 Whisper:
pip install -U openai-whisper
大概,以下下令将今后存储库中提取并安装最新的提交及其 Python 依赖项:
pip install git+https://github.com/openai/whisper.git
要将包更新至此存储库的最新版本,请运行:
pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git
它还需要ffmpeg在你的体系上安装下令行工具,大多数包管理器都可以提供该工具:
# on Ubuntu or Debian
sudo apt update && sudo apt install ffmpeg

# on Arch Linux
sudo pacman -S ffmpeg

# on MacOS using Homebrew (https://brew.sh/)
brew install ffmpeg

# on Windows using Chocolatey (https://chocolatey.org/)
choco install ffmpeg

# on Windows using Scoop (https://scoop.sh/)
scoop install ffmpeg
可用型号和语言

有六种模型大小,其中四种只有英语版本,提供速度和正确性的权衡。以下是可用模型的名称及其相对于大型模型的近似内存要求和推理速度。以下相对速度是通过在 A100 上转录英语语音来测量的,实际速度可能会因多种因素而有很大差异,包罗语言、说话速度和可用的硬件。
尺寸参数纯英语模式多语言模型所需 VRAM相对速度微小的三十九 米tiny.entiny约 1 GB~10X根据74 米base.enbase约 1 GB~7倍小的244 米small.ensmall约 2 GB~4倍中等的769 米medium.enmedium约 5 GB~2倍大的1550 米不适用large~10 GB1x涡轮809 米不适用turbo约 6 GB~8倍 中文的话建议turbo模型大概large模型
以下下令将使用turbo模型转灌音频文件中的语音:
whisper audio.flac audio.mp3 audio.wav --model turbo
import whisper
import torch
import logging

# 设置日志配置,记录时间和信息
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
logging.info('============================')

# 检查并设置设备
device = "cuda" if torch.cuda.is_available() else "cpu"
logging.info(f"Using device: {device}")

# 加载模型到 GPU
model = whisper.load_model("turbo", device=device)

# 加载音频并将其转换为张量,并转移到 GPU
audio = whisper.load_audio("output_combined.wav")
audio_tensor = torch.tensor(audio).to(device)# 将 numpy 数组转换为 PyTorch 张量并移动到 GPU

# 转录音频文件
result = model.transcribe(audio_tensor)

# 打印转录结果并记录日志
logging.info("Transcription result: %s", result["text"])
这里建议使用GPU目前测试4090D是cpu的3呗
注意:如果电脑没有装过torch就用官方文档建议的摆设,如果有建议使用gpu
如果翻译中文使用最大的两个模型都行.比较废资源,显卡越好结果越好.
https://i-blog.csdnimg.cn/direct/f3506d1946634caa95026db560e8b90c.png
实际结果,我租的4090d显卡识别2分钟灌音转笔墨大概速度18秒左右吧,应该还可以优化.

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 语音识别(whisper摆设)