0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

whisper.cppをMac(M4)で高速処理する[Core ML support]+実行を楽にするおまけ

Posted at

公式Doc見ながら構築していく
https://github.com/ggml-org/whisper.cpp

はじめに git clone

git clone https://github.com/ggml-org/whisper.cpp.git
cd whisper.cpp

pyenvで環境設定

pythonは3.11推奨ということだったので。
pyenv自体はbrewで入れてるよ

pyenv install 3.11.12
pyenv local 3.11.12
python -m venv .env-for-whisper
source .env-for-whisper/bin/activate

必要なものをpipでインストール

pip install ane_transformers
pip install openai-whisper
pip install coremltools
pip install torch==2.5.0

model generate

modelはmediumを使います。
(large-v1はなぞのエラーで落ちます)
(友人の話ではlarge-v3はできたよーとのこと(私は試してない))

./models/generate-coreml-model.sh medium

エラーが出る場合

まず最新のxcodeをインストールしているか確認すること!
次に以下のようなエラーが出た場合、
xcrun: error: unable to find utility "coremlc", not a developer tool or in PATH
xcrunのパスを確認しましょう。

xcode-select -p
(私の場合のoutput-> /Library/Developer/CommandLineTools)

このような場合はパス変更が必要です、以下のコマンドで変更します。

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

念のために動くか確認しておきましょう。

xcrun coremlc
coremlc: error: usage: coremlc <command> <inputdocument> <outputpath> [options ...]

動いた!

改めてmodelのgenerateとdownload

./models/generate-coreml-model.sh medium
./models/download-ggml-model.sh medium

うまくいったら以下な感じのログ出る

models/coreml-encoder-medium.mlmodelc -> models/ggml-medium-encoder.mlmodelc

あとは公式の手順通りにビルドをかける。

cmake -B build -DWHISPER_COREML=1
cmake --build build -j --config Release

サンプル音声で出力を確認

./build/bin/whisper-cli -m /Users/asadeyy/tools/whisper.cpp/models/ggml-medium.bin -f samples/jfk.wav

以下ログ(抜粋)

system_info: n_threads = 4 / 14 | WHISPER : COREML = 1 | OPENVINO = 0 | Metal : EMBED_LIBRARY = 1 | CPU : NEON = 1 | ARM_FMA = 1 | FP16_VA = 1 | MATMUL_INT8 = 1 | DOTPROD = 1 | ACCELERATE = 1 | AARCH64_REPACK = 1 |

main: processing 'samples/jfk.wav' (176000 samples, 11.0 sec), 4 threads, 1 processors, 5 beams + best of 5, lang = en, task = transcribe, timestamps = 1 ...


[00:00:00.000 --> 00:00:11.000]   And so, my fellow Americans, ask not what your country can do for you; ask what you can do for your country.

でぎだ!!!

おまけ(ailias設定して使いやすくすっぞ)

.zshrcを開こう

vim ~/.zshrc

一番下に以下を追加

alias whisper-medium='~/tools/whisper.cpp/build/bin/whisper-cli -m ~/tools/whisper.cpp/models/ggml-medium.bin -f'

こんな感じで実行できるよ!
日本語の場合はjaをいれて、文字起こしのtxtが欲しいので-otxtを付与する。

whisper-medium 音声ファイル.wav -l ja -otxt

あとがき

やっぱりcoreML使うと爆速でええですね。てか凄すぎる。
みなさんも良い文字起こしライフを!

(※本記事は以前zennのスクラップに雑書きしていたものを読みやすく再編したものです。)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?