OpenAI Whisperは、現時点でGoogle音声合成に代わる最も優れたオープンソースの音声合成です。100の言語でネイティブに動作し(自動検出)、句読点を追加し、必要であれば結果を翻訳することもできる。この記事では、Whisperをインストールし、本番環境にデプロイする方法を紹介します。
Googleの自動音声認識(Speech-to-Text)APIは非常に人気があります。このAPIは、125言語の音声・動画ファイルの文字起こしが可能で、電話の文字起こし、医療の文字起こしなど、特定のAIモデルを提案しています。
このAPIには、コンテンツのフィルタリング、自動句読点(現時点ではベータ版のみ)、話者の日記化(これもベータ版)といった素晴らしい追加機能もあります。
最後に、同社のAPIはオンプレミスに設置することができます。ただ、オンプレミスのAIモデルは、APIの利用状況を報告するためにGoogleにデータを送り続けることになるので、プライバシーの観点から懸念されるかもしれない点には注意が必要です。
Googleの価格設定は、基本的な音声テキスト化は$0.006 / 15秒、ビデオ起こしや電話起こしなど特定のユースケースは$0.009 / 15秒となっています。
例えば、サポートチームにかかってきた電話を自動的に分析したいとします(後でセンチメント分析やエンティティ抽出を行うため)。5人のサポート担当者が1日に4時間ずつ顧客と電話で話すとすると、Googleの音声テキスト化APIは月々1,400ドルかかることになる。
コストやプライバシーが気になる方は、オープンソースの代替品に乗り換えてみてはいかがでしょうか。OpenAI Whisperです。
Whisperは、OpenAIが公開したばかりのオープンソースのAIモデルです。
OpenAIには、優れたAIプロジェクトをオープンソース化してきた歴史があります。例えば、GPT-2は数年前にOpenAIによって開発されました。当時は、これまで作られた中で最高の生成型自然言語処理モデルで、GPT-3、GPT-J、OPT、Bloom...など、より高度なモデルへの道を開いてくれました。最近、Tritonという素晴らしいCUDAプログラミングフレームワークもリリースされました。
しかし、OpenAIのすべてのモデルがオープンソース化されているわけではありません。彼らの最もエキサイティングな2つのモデル。GPT-3とDALL-Eは、まだプライベートモデルで、有料のAPIを通してのみ使用することができます。
Whisperは、音声テキスト化のエコシステムに嵐を巻き起こしている。入力言語を自動的に検出し、約100言語のテキストを書き起こし、その結果に自動的に句読点を付け、さらに必要に応じて翻訳を行うことができるのである。精度は非常に高く、このモデルはあらゆる種類の入力(音声、ビデオ、電話、医学的議論など)に適用することができます。
もちろん、Whisperのもう一つの大きな利点は、自分のサーバーに自分で展開できることで、これはプライバシーの観点からも素晴らしいことです。
Whisperはもちろん無料ですが、自分でインストールする場合は、ある程度人間の時間を費やし、基盤となるサーバーやGPUの費用を支払う必要があります。もし、管理されたバージョンの恩恵を受けたいなら、NLP CloudのようなAPIを使うことができます。 今すぐNLPクラウドでWhisperを無料でお試しください。.
とりあえずWhisperをインストールして配備したい場合、2つのオプションがあります。ひとつはOpenAIのwhisper Pythonライブラリを使う方法、もうひとつはWhisperのHugging Face Transformers実装を使う方法です。両方の解決策を探ってみましょう。
この解決策は最もシンプルなものです。基本的にはOpenAIの指示に従う必要があります。 WhisperプロジェクトのGithubリポジトリにある.
First install the whisper Python lib:
pip install git+https://github.com/openai/whisper.git
Then install ffmpeg on your system if it is not the case yet:
# 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
Several flavors of Whisper are available: tiny, base, small, medium, and large. Of course the bigger the better, so if you are looking for state of the art results we recommend the large version. Here is a very simply Python script that opens an mp3 audio file stored on your disk, automatically detects the input language, and transcribes it:
import whisper
model = whisper.load_model("large")
result = model.transcribe("audio.mp3")
print(result["text"])
Simple isn't it?
In order to use Hugging Face's implementation of Whisper you will first need to install HF Transfomers, librosa, and Pytorch:
pip install transformers
pip install librosa
pip install torch
You also need to install ffmpeg (see above).
Now, here is a Python script that does transcription in English:
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import librosa
speech, _ = librosa.load("audio.mp3")
processor = WhisperProcessor.from_pretrained("openai/whisper-large")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language = "en", task = "transcribe")
input_features = processor(speech, return_tensors="pt").input_features
predicted_ids = model.generate(input_features)
transcription = processor.batch_decode(predicted_ids)
print(processor.batch_decode(predicted_ids, skip_special_tokens = True))
There are 2 limitations with this Hugging Face implementation. First you need to manually set the source language (no automatic input language detection is implemented yet). And secondly no automatic chunking is applied, which means that you cannot transcribe content that is larger than 30 seconds...
Maybe these limitations will be solved in future releases?
A nice thing though is that there is a Tensorflow implementation available too, which means that you can use XLA compilation and get much faster response times.
上で見たように、ウィスパーはインストールがかなり簡単です。しかし、それは高度なハードウェアを必要とします。大型のモデルを使用する場合は、GPUを推奨します。
whisper Python lib(上記参照)を使用する場合、約10GBのRAMと11GBのVRAMが必要です。つまり、実際には最低でも16GBのGPUが必要になります。例えばNVIDIA Tesla T4、あるいはNVIDIA A10などが考えられます。
テスラT4では、30秒の音声を6秒程度で書き写すことになります。
上記のデフォルトのパフォーマンスを向上させたい場合、いくつかの戦略を検討することができます。
OpenAI Whisperは音声テキスト化の世界における革命である。このオープンソースモデルのおかげで、初めて誰でも簡単に最先端の自動音声認識を利用できるようになり、WhisperはGoogle音声テキストAPIの良い代替品となった。
しかし、このようなAIモデルをインストールし、展開することは、ハードウェアが必要であるため、まだ困難です。Whisperの大型バージョンは、コンシューマー向けハードウェアでは実際に動作させることができないのです。
インフラを気にせず手軽にWhisperを試したい方は、ぜひNLP Cloud APIでお試しください。 今すぐNLPクラウドでWhisperを無料でお試しください。.
Julien Salinas
NLPクラウド社CTO