ソフトウェア/whisper の履歴(No.2)
更新OpenAI の Whisper を使って授業動画に正しい字幕を付けたい†
Microsoft Stream の標準機能で動画に字幕を付けられるのだけれど、 精度が悪すぎて残念な感じになっている。
OpenAI の Whisper を使うとより正確な文字起こしができそうなので試してみます。
Docker を使うと簡単に動かせるようです†
https://dev.classmethod.jp/articles/openai_whisper_only_local_cpu/ を参考に、
LANG:console $ mkdir whisper $ cd whisper $ cat << EOS >Dockerfile FROM python:3.9-slim WORKDIR /workspace RUN apt update && apt install -y \ build-essential \ gcc \ git \ ffmpeg \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade pip RUN pip install git+https://github.com/openai/whisper.git EOS $ docker build -t whisper . $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE whisper latest 5f346a2f452e 40 minutes ago 3.52GB python 3.9-slim 690ca4c8a70d 6 hours ago 125MB $ alias whisper='docker run --rm -v $(pwd):/workspace/ whisper whisper' $ whisper --language ja --model medium audio.mp3 | tee script.txt
のようにして、簡単に動かすことができました。
ただ、GPU を使わないとかな~り時間がかかるみたい。。。
cuda が使えるなら、PyTorch が自動的に認識して cuda による高速な処理が可能になるみたい。
ああ、上記の書き方だと毎回データをダウンロードしに行っちゃうから、 「データを保存する場所」を別途 volume として分けておく必要がありそうですね。要検討。
字幕データがそのまま得られる†
コマンド一発で vtt ファイルができるので、それを Microsoft Stream にアップロードすれば字幕データを置き換えられます。
区切りを調整したい?†
デフォルトだと文と文との間を認識せずに行分けされてしまうみたいに感じられるので、これを調整できないものか検討中。
Microsoft Stream で変換した結果:
線形代数bの授業を続けます数理不躾、竹内です この動画は、春学期の復讐1となっています ええまず線形代数という言葉からですけれども、うんとこの線形代 数の線形皆さんもわかりますよね 意味はええと関数fっていうのが線形であるっていうのはどういう 意味かというと、これは? エックスとyを足してからエフを適用するのと、fを適用 してから多数のと 結果が変わらないよっていうことです あるいはscalarばいしてからエフを適用するのと、fを適用 してからscalarヴァイスの音で結果が変わらないと こういう関数のことを線形な関数と言うのでした でこの2つのええ 条件は?1つにまとめてしまってscalarバイトはを計算して からエフを適用するのと、fを適用してからscalarバイトは を計算するのとが等しいと書いても同じことになります
whisper (medium) で変換した結果:
線形大数Bの授業を続けます 数理 物質系竹内です この動画は春学期 の復習1となっています まず線形大数 という言葉からですけれども この 線形大数の線形 皆さんも分かります よね 意味は 関数Fっていうのが 線形であるっていうのはどういう 意味かっていうと これは xとyを 足してからFを適用するのと Fを適用 してから足すのと 結果が変わらない よっていうことです あるいは スカラーバイしてからFを適用する のと Fを適用してからスカラーバイ するのとで結果が変わらないと こういう関数のことを線形な関数 と言うのでした この二つの条件 は一つにまとめてしまって スカラーバイ とYを計算してからFを適用する のと Fを適用してからスカラーバイ とYを計算するのとが等しいと 書いても同じことになります この条件とこの条件は同値な条件 になります
本来言いたかった内容:
線形代数Bの授業を続けます 数理物質系武内です この動画は「春学期の復習1」となっています まず線形代数という言葉からですけれども この線形代数の「線形」 皆さんもう分かりますよね 意味は、関数 f っていうのが線形であるっていうのは どういう意味かっていうと これは x と y を足してから f を適用するのと f を適用してから足すのと 結果が変わらないよ、っていうことです あるいは、スカラー倍してから f を適用するのと f を適用してからスカラー倍するのとで結果が変わらないと。 こういう関数のことを「線形な関数」と言うのでした。 この二つの条件は一つにまとめてしまって スカラー倍と和を計算してからFを適用する のと f を適用してからスカラー倍と和を計算するのとが等しいと 書いても同じことになります この条件とこの条件は同値な条件になります
比べてみると whisper の変換精度がかなり高いことが分かります。
ただ、whisper は分の区切りで改行してくれないので、そこだけ不満。
オプションを見直す†
--temperature TEMPERATURE temperature to use for sampling (default: 0) --best_of BEST_OF number of candidates when sampling with non-zero temperature (default: 5) --beam_size BEAM_SIZE number of beams in beam search, only applicable when temperature is zero (default: 5) --patience PATIENCE optional patience value to use in beam decoding, as in https://arxiv.org/abs/2204.05424, the default (1.0) is equivalent to conventional beam search (default: None) --length_penalty LENGTH_PENALTY optional token length penalty coefficient (alpha) as in https://arxiv.org/abs/1609.08144, uses simple length normalization by default (default: None) --suppress_tokens SUPPRESS_TOKENS comma-separated list of token ids to suppress during sampling; '-1' will suppress most special characters except common punctuations (default: -1) --initial_prompt INITIAL_PROMPT optional text to provide as a prompt for the first window. (default: None) --condition_on_previous_text CONDITION_ON_PREVIOUS_TEXT if True, provide the previous output of the model as a prompt for the next window; disabling may make the text inconsistent across windows, but the model becomes less prone to getting stuck in a failure loop (default: True) --fp16 FP16 whether to perform inference in fp16; True by default (default: True) --temperature_increment_on_fallback TEMPERATURE_INCREMENT_ON_FALLBACK temperature to increase when falling back when the decoding fails to meet either of the thresholds below (default: 0.2) --compression_ratio_threshold COMPRESSION_RATIO_THRESHOLD if the gzip compression ratio is higher than this value, treat the decoding as failed (default: 2.4) --logprob_threshold LOGPROB_THRESHOLD if the average log probability is lower than this value, treat the decoding as failed (default: -1.0) --no_speech_threshold NO_SPEECH_THRESHOLD if the probability of the <|nospeech|> token is higher than this value AND the decoding has failed due to `logprob_threshold`, consider the segment as silence (default: 0.6) --threads THREADS number of threads used by torch for CPU inference; supercedes MKL_NUM_THREADS/OMP_NUM_THREADS (default: 0)
あー、どこかでこれらの意味を解説してたりしないかな・・・
Counter: 3519 (from 2010/06/03),
today: 2,
yesterday: 3