Whisperをインストール際にエラーでドハマりしてしまったので手順を残す

WhisperをWindows環境において走らせるための手順です。

Anaconda、Python、CUDA、PyTorch、Chocotray、ffmpeg、そしてOpenAIのWhisperパッケージをインストール方法。

また、MP4ファイルをMP3に変換する方法と、Whisperを起動し、音声から文字を出力する方法についても説明していきます。

 

https://openai.com/blog/whisper/

https://github.com/openai/whisper

 

環境:

windows10

Python環境構築

 

Pythonの使い勝手を良くするために、ANACONDAをインストールします。

公式ウェブサイト(https://www.anaconda.com/)からAnacondaをダウンロードし、インストールしてください。

Pythonを無駄にいじったことがある経験があれば、新規の環境をつくることをおすすめします。

下図の左下「create」から3.10くらいのPython環境を構築。

anacondaの操作説明

一応、Pythonの公式URLも

https://www.python.org/downloads/

 

メモ

元々の環境で走らせていたら、

ModuleNotFoundError: No module named

tqdm

wheel

tiktoken

numba

pep517

など様々なエラーが出てきて詰みました。

 

Gitをインストール

https://gitforwindows.org/をダウンロードし、インストールしてください。

 

CUDAをインストール

CUDAをダウンロードし、インストールしてください。

https://developer.nvidia.com/cuda-toolkit-archive

PyTorchをインストール

PyTorchをインストールするために、公式ウェブサイト(https://pytorch.org/)を参照して、適切なコマンドを実行してください。

 

 

FFMPEGをインストール

ffmpegをインストールしていきますが、Windows Powershellを使って進めて行きます。

chocolateyをインストール

管理者権限でWindows Powershellを開き、以下のコマンドを実行して、Chocotrayをインストールしてください。

インストールのコードはこちらの公式サイトから最新のものを取得してください。

https://chocolatey.org/install

2023年3月現在で以下のコードです

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’))

ffmpegをインストール

ffmpegをインストールするために、管理者権限でWindows Powershellを開き、以下のコマンドを実行してください。

choco install ffmpeg

だいたいこんな感じになります

Rustをインストール

pip install setuptools-rust

 

Whisperをインストール

Whisperパッケージをインストールするために、以下のコマンドを実行してください。

pip install git+https://github.com/openai/whisper.git

 

MP4ファイルをMP3に変換

MP4ファイルをMP3に変換するために、以下のPythonコードを使用してください。

import ffmpeg

# 入力
stream = ffmpeg.input(“test.mp4”)
# 出力
stream = ffmpeg.output(stream, “test.mp3”)
# 実行
ffmpeg.run(stream)

Whisperを起動

Whisperを起動するために、以下のコマンドを実行してください。

whisper test.mp3 –language Japanese –model small

めも

modelについては、

容量、機能が小さい順から

tiny

base

small

medium

large

large-v2

とあります。

以上が、Windows環境でのWhisperの準備と使用方法です。

今回クソがつくほどハマってしまったのでメモ代わりに。

 

保管庫:

https://visualstudio.microsoft.com/ja/

https://developer.nvidia.com/cuda-gpus#compute

https://developer.nvidia.com/developer-program

 

参考:

https://qiita.com/samezi/items/7ed2c1e57213bdcfa707

https://qiita.com/tatefuku_hiroshi/items/f060052856dcc2918e69

https://qiita.com/diesekiefer/items/00d8c1507829b58a62ab

https://self-development.info/%E3%81%BB%E3%81%BC%E5%AE%8C%E7%92%A7%E3%81%AA%E6%96%87%E5%AD%97%E8%B5%B7%E3%81%93%E3%81%97%E3%81%8C%E3%81%A7%E3%81%8D%E3%82%8Bai%E9%9F%B3%E5%A3%B0%E8%AA%8D%E8%AD%98whisper%E3%81%AE%E3%82%A4%E3%83%B3/

https://self-development.info/%E3%80%90%E7%B0%A1%E5%8D%98%E3%80%91python%E3%81%A7%E5%8B%95%E7%94%BB%E3%81%8B%E3%82%89%E9%9F%B3%E5%A3%B0%EF%BC%88mp3%E3%83%BBwav%EF%BC%89%E3%82%92%E6%8A%BD%E5%87%BA%E3%81%99%E3%82%8B%E6%96%B9/

https://gigazine.net/news/20220929-openai-whisper-install-and-usage/

関連記事