Amazon Transcribeのリアルタイム文字起こしを試してみた

2018.11.23

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Amazon Transcribeがリアルタイム文字起こしに対応しました。 従来は非同期な文字起こししかできませんでしたが、今後は音声入力アプリのようにインタラクティブな文字入力ができるようになります。

Amazon Web Services ブログ : Amazon Transcribe でリアルタイムの文字起こしがサポート可能になりました

音声をリアルタイム文字起こしするデモアプリが公開されているため、早速動かしてみました。

Amazon Transcribeの対応言語

Amazon Transcribeは以下の言語の文字起こしに対応しています。

  • 英語(アメリカ)
  • 英語(イギリス) ※ 2018/11/15 から
  • 英語(オーストラリア) ※ 2018/11/15 から
  • スペイン語
  • フランス語(カナダ)※ 2018/11/15 から

また、2018/11/16 より 以下の言語のプレビュー対応が始まっています。

  • フランス語(汎用)
  • ドイツ語
  • ポルトガル語(ブラジル)

日本語対応は気長に待ちましょう。

やってみた

デモアプリは入力音源として、次の2種類の入力に対応しています。

  • マイク音声
  • 音声ファイル

今回は前者を利用します。

事前インストール

デモアプリは AWS SDK for Java 2.0 を利用しているため、

  • Maven
  • Java 1.8+

をインストールしてください。

デモアプリのビルド

GitHub のレポジトリ aws-samples/aws-transcribe-streaming-example-java で公開されています。

ソースコードを git clone もしくは Zip 形式でダウンロードし、 Maven でビルドします。

git cloneする場合

$ git clone https://github.com/aws-samples/aws-transcribe-streaming-example-java.git
$ cd aws-transcribe-streaming-example-java
$ mvn clean package

AWS アカウント情報の指定

リージョンの指定

Amazon Transcribe は以下のリージョンで利用可能です。

リージョン論理名 物理名
US East (N. Virginia) us-east-1
US East (Ohio) us-east-2
US West (Oregon) us-west-1
Asia Pacific (Sydney) ap-southeast-2
Canada (Central) ca-central-1
EU (Ireland) eu-wast-1

この表に従い、利用リージョンを環境変数で指定します。

「US East (N. Virginia)」 の場合は、以下の様にします。

$ export AWS_REGION=us-east-1

クレデンシャルの指定

API 操作で利用するクレデンシャルを環境変数で指定します。

$ export AWS_ACCESS_KEY_ID=<your access key>
$ export AWS_SECRET_KEY=<your secret key>

デフォルトプロファイルを利用する場合は、この設定は不要です。

アプリの起動

最後にアプリを起動します。

$ java -jar target/aws-transcribe-sample-application-1.0-SNAPSHOT-jar-with-dependencies.jar

"Start Microphone Transcription" ボタンを起動し、ターミナルにトレースバックが表示されていなければ、成功です。

デモ環境

題材として Creative Commons な次の EC2 に関する米語の動画を利用しました。

字幕が用意されているため、文字起こし精度の評価が容易です。

ブラウザで動画を再生し、Mac ビルトインのマイクで音声を拾って、リアルタイムに文字起こしします。

文字起こし結果を確認

  • YouTube の字幕
  • Transcribe の非同期文字起こし
  • Transcribe のリアルタイム文字起こし

で文字起こし結果を比較しました。

全体は4分近くと長いため、一部だけを抜粋します。

動画開始箇所 字幕 バッチ リアルタイム
00:00 Whatever kind of application you run, it's pretty certain that you're going to need servers. Whatever kind of application you run, it's pretty certain that you're going to need service. Was that a kind of application you run. It's pretty certain that you're going to need service.
00:40 Amazon Elastic Compute Cloud or Amazon EC2 makes it easy for you to obtain virtual servers also known as compute instances in the cloud quickly and inexpensively. Amazon elastic, compute cloud or amazon to makes it easy for you to obtain virtual servers, also known as compute instances in the cloud quickly and inexpensively. I was an elastic computer cloud. I wasn't easy to make it easy for you to obtain virtual servers, also known as computer instances in the cloud quickly and inexpensively.
00:50 You simply choose the instant type you want, the template you'd like to use, which could be based on Windows or Linux and launch the quantity you need. He simply choose the instant saipi want temperature you'd like to use, which could be based on windows or lurks and launch the quantity you need. Simply choose the instance I want temperature would like to use which could be based on windows or looks. Launch the quantity you need.

今回試した1動画だけをもとに判断を下すと、バッチ方式のほうがリアルタイム方式よりも少しだけ正確に文字起こし出来ているという印象を持ちました。

1文目のようにシンプルで短い英文は軽微な修正で済むレベルのクオリティですが、2・3文目のように、文の切れ目多かったり、テクニカル用語が頻出する文章は、リアルタイムの方で誤りが目立ちました。

文字起こしの単位

一定のタイムフレームごとにバッファリングしながら文字起こしされ、このブロック単位で処理が確定します。

ターミナルログからこの動きがよくわかります。

実際には以下の様になります。

Come on.
I can't allow you.
I can't allow you to
I can't allow you to
I can't allow you to obtain
I can't allow you to obtain comm.
I can't allow you to obtain compute.
I can't allow you to obtain compute.
I can't allow you to obtain compute kapow.
I can't allow you to obtain compute a pass.
I can't allow you to obtain computer capacity.
I can't allow you to obtain computer capacity.
I can't allow you to obtain computer capacity, sir.
I can't allow you to obtain computer capacity.
I can't allow you to obtain computer capacity. Significant.
I can't allow you to obtain computer capacity. Significant dis
I can't allow you to obtain computer capacity a significant discount.
I can't allow you to obtain computer capacity a significant discount.
I can't allow you to obtain computer capacity a significant discount beyond
I can't allow you to obtain computer capacity a significant discount beyond
I can't allow you to obtain computer capacity a significant discount the on demand
I can't allow you to obtain computer capacity a significant discount the on demand
I can't allow you to obtain computer capacity a significant discount the on demand price. ← 確定
We
We know
We know that.
We know that, sir.
We know that.
We know that secure.
We know that security.
We know that security is

専門用語の認識率を高める

なお、AWS や EC2 のような専門用語をうまく識別できていない件については、カスタム語彙を利用することで、単語の認識率が改善します。

文字起こしサービスAmazon Transcribeがカスタム語彙に対応しました

【新機能】Amazon Transcribeのカスタム語彙が頭字語に対応しました

HTTP/2 の採用

リアルタイムで文字起こしするには、双方向の通信

  • クライアントからサーバーに文字起こしする音声をストリーム
  • サーバーからクライアントに文字起こしされたテキストをストリーム

が発生します。

この機能は HTTP/2 の双方向通信で実現されています。

Q: Does Amazon Transcribe support real-time transcriptions?

Yes. Amazon Transcribe enables users to open a bidirectional stream over HTTP2. Users can send an audio stream to the service while receiving a text stream in return in real time.

https://aws.amazon.com/transcribe/faqs/

先ごろ GA になった AWS SDK for Java 2 系は HTTP/2 通信に対応しており、このデモアプリでも早速活用されています。

最後に

従来の Amazon Transcribe は非同期に処理されるため、あくまでもアーカイブされた音源への応用が主体でした。 今回のリアルタイム対応により、一般ユーザーの慣れ親しむ音声入力と同じようなインタフェースを提供できるようになりました。

また、8月の Kinesis に続き(AWS News Blog : Amazon Kinesis Data Streams Adds Enhanced Fan-Out and HTTP/2 for Faster Streaming)、Transcribe でも HTTP/2 の API が提供された点も見逃せません。 Java V2 以外の SDK でも HTTP/2 対応が急速に進み、HTTP/2 通信の特性をいかした API がどんどん増えていくと思われます。

なお、AWS CLI(とベースを共有している Python SDK) は現時点で HTTP/2 に対応していないようです。

それでは。

参考