Speech-to-Text V2 は、認識ツールと呼ばれる Google Cloud リソースをサポートしています。認識ツールは、保存され再利用可能な認識構成を表します。認識ツールを使用して、アプリケーションの音声文字変換やトラフィックを論理的にグループ化できます。
始める前に
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
クライアント ライブラリは、アプリケーションのデフォルト認証情報を使用することによって、Google API で簡単に認証を行い、これらの API にリクエストを送信できます。アプリケーションのデフォルト認証情報を使用すると、ベースとなるコードを変更することなく、ローカルでアプリケーションのテストを行ったり、アプリケーションをデプロイしたりできます。詳細については、クライアント ライブラリを使用するための認証をご覧ください。
また、クライアント ライブラリがインストールされていることを確認してください。
認識ツールについて
認識ツールは構成可能で再利用可能な認識構成です。頻繁に使用される認識構成を使用して認識ツールを作成すると、認識リクエストを簡素化し、リクエストのサイズを削減できます。
認識ツールの重要な要素は、デフォルト構成です。これは、この認識ツールが実行するすべての認識リクエストの構成です。このデフォルト値は、リクエストごとにオーバーライドできます。特定の認識ツールのリクエストで必要となる機能のデフォルト構成をそのまま使用する場合もあれば、特定のリクエストで特定の機能をオーバーライドする場合もあります。
認識ツールをできる限り再利用するようにしてください。リクエストごとに認識ツールを作成すると、アプリケーションのレイテンシが大幅に増加し、リソースの割り当てを消費します。統合や設定の際に少数の認識ツールを作成し、認識リクエストではそれらを再利用するようにしてください。
認識ツールを作成する
認識リクエストの送信の際に使用できる認識ツールを作成する例を次に示します。
Python
既存の認識ツールを使用してリクエストを送信する
同じ認識ツールを使用した複数の認識リクエストを送信する例を次に示します。
Python
認識ツールの機能を有効にする
認識ツールを使用すると、句読点入力の自動化や冒とく的な表現のフィルタリングなど、さまざまな認識の機能を有効にできます。
認識ツールで句読点入力の自動化を有効にする例を次に示します。この認識ツールを使用すると、認識リクエストで句読点入力の自動化が有効になります。
Python
認識リクエストで認識ツールの機能をオーバーライドする
認識ツールで複数の機能を有効にし、認識リクエストで句読点入力の自動化を無効にする例を次に示します。
Python
認識ツールなしでリクエストを送信する
認識リクエストでは、認識ツールは省略可能です。認識ツールなしでリクエストを作成するには、リクエストを行うロケーションで、認識ツールのリソース ID _
を使用します。以下に例を示します。
Python
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の操作を行います。
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
コンソール
gcloud
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
次のステップ
- 短い音声ファイルの文字変換を行う。
- ストリーミング音声を文字に変換する方法を学習する。
- 長い音声ファイルを文字に変換する方法を学習する。
- ベスト プラクティスのドキュメントで、最高のパフォーマンスと精度を実現するための方法やヒントを確認する。