2
1

More than 1 year has passed since last update.

WhisperXを日本語で試してみた

Posted at

WhisperXの紹介動画

こちらの動画を見たので日本語でも試してみました。普通に動きますね。
https://youtu.be/KtAFU_xeHr4

WhisperXとは

Whisperで書き起こした文章のタイムスタンプを単語単位で求めるソフトウェアです。
https://github.com/m-bain/whisperX

Whisperの書き起こし結果にはsegmentsというタイムスタンプ付きのデータがあるのですが、こちらはあまり細かいタイムスタンプが得られません。文章単位ならよいのですが、文節や単語レベルでのタイムスタンプが欲しい時には使えません。

WhisperXを使うと単語単位のタイムスタンプに変換してくれます。日本語の場合は1文字レベルでのタイムスタンプを求めることができます。

インストール

Whisperとffmpegのインストールは終わっているとします。

pip install git+https://github.com/m-bain/whisperx.git

実行

本家のサンプルに日本語の指定を足しただけです。指定はしなくても動きます。

import whisperx

device = "cuda" 
audio_file = "sample.mp3"

# transcribe with original whisper
model = whisperx.load_model("large", device)
result = model.transcribe(audio_file, language="ja")

# load alignment model and metadata
model_a, metadata = whisperx.load_align_model(language_code=result["language"], device=device)

# align whisper output
result_aligned = whisperx.align(result["segments"], model_a, metadata, audio_file, device)

# 文章単位のタイムスタンプ
for seg in result_aligned["segments"]: # after alignment
    print(seg['start'], ':', seg['end'], ':', seg['text'])

# 文字単位のタイムスタンプ
for seg in result_aligned["word_segments"]: # after alignment
    print(seg['start'], ':', seg['end'], ':', seg['text'])

結果

今回はYoutubeからVTuber高嶺ルイさんの切り抜き動画の音声を書き起こしています。

139.9403734439834 : 149.3999585062241 : みなさんあったかねはいホロライブの規制秘密結社ホロックスの女幹部 高音るいと思うしまーす
...
120.0 : 122.76 : me
122.76 : 125.76 : me
139.9403734439834 : 140.1207468879668 : み
140.22095435684648 : 140.361244813278 : な
140.4213692946058 : 140.44141078838175 : さ
140.50153526970954 : 140.56165975103733 : ん
140.68190871369293 : 140.86228215767633 : あ
141.10278008298755 : 141.14286307053942 : っ
141.16290456431534 : 141.1829460580913 : た
141.26311203319503 : 141.32323651452282 : か
141.40340248962656 : 142.0447302904564 : ね
142.1449377593361 : 142.2651867219917 : は
142.28522821576763 : 142.42551867219916 : い
142.4455601659751 : 142.48564315352698 : ホ
142.58585062240664 : 142.72614107883817 : ロ
142.74618257261412 : 142.82634854771783 : ラ
142.84639004149378 : 142.88647302904565 : イ
142.90651452282157 : 142.92655601659752 : ブ
142.94659751037344 : 142.9866804979253 : の
143.1670539419087 : 143.18709543568465 : 規
143.30734439834026 : 143.38751037344397 : 制
143.48771784232366 : 143.58792531120332 : 秘
143.60796680497924 : 143.76829875518672 : 密
143.84846473029046 : 144.00879668049794 : 結
144.02883817427386 : 144.08896265560168 : 社
144.18917012448134 : 144.26933609958508 : ホ
144.289377593361 : 144.38958506224066 : ロ
144.4096265560166 : 144.42966804979253 : ッ
144.44970954356847 : 144.4697510373444 : ク
144.54991701244813 : 144.56995850622408 : ス
144.67016597510374 : 144.7703734439834 : の
144.890622406639 : 145.31149377593363 : 女 幹
145.5319502074689 : 146.1933195020747 : 部  
146.3135684647303 : 146.47390041493776 : 高
146.61419087136932 : 146.63423236514524 : 音
146.71439834024898 : 146.83464730290459 : る
146.8546887966805 : 146.97493775933611 : い
147.17535269709543 : 147.27556016597512 : と
147.29560165975104 : 147.315643153527 : 思
147.3356846473029 : 147.35572614107886 : う
147.41585062240665 : 147.53609958506226 : し
147.57618257261413 : 147.95697095435685 : ま
147.99705394190872 : 149.33983402489628 : ー
149.37991701244815 : 149.3999585062241 : す
2
1
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
2
1