SpeechAsyncClient(*, credentials: typing.Optional[google.auth.credentials.Credentials] = None, transport: typing.Union[str, google.cloud.speech_v1p1beta1.services.speech.transports.base.SpeechTransport] = 'grpc_asyncio', client_options: typing.Optional[google.api_core.client_options.ClientOptions] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)
Google Cloud Speech API を実装するサービス。
プロパティ
transport
クライアント インスタンスで使用されるトランスポートを返します。
戻り値 | |
---|---|
型 | 説明 |
SpeechTransport | クライアント インスタンスで使用されるトランスポート。 |
メソッド
SpeechAsyncClient
SpeechAsyncClient(*, credentials: typing.Optional[google.auth.credentials.Credentials] = None, transport: typing.Union[str, google.cloud.speech_v1p1beta1.services.speech.transports.base.SpeechTransport] = 'grpc_asyncio', client_options: typing.Optional[google.api_core.client_options.ClientOptions] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)
音声クライアントをインスタンス化します。
パラメータ | |
---|---|
名前 | 説明 |
credentials |
Optional[google.auth.credentials.Credentials]
リクエストに付加する認証情報。これらの認証情報は、サービスに対するアプリケーションを識別します。指定されていない場合、クライアントは環境から認証情報を取得しようとします。 |
transport |
Union[str,
使用するトランスポート。None に設定すると、トランスポートが自動的に選択されます。 |
client_options |
ClientOptions
クライアントのカスタム オプション。 |
例外 | |
---|---|
型 | 説明 |
google.auth.exceptions.MutualTlsChannelError | なんらかの理由で相互 TLS トランスポートの作成に失敗した場合。 |
common_billing_account_path
common_billing_account_path(billing_account: str) -> str
完全修飾された billing_account 文字列を返します。
common_folder_path
common_folder_path(folder: str) -> str
完全修飾フォルダ文字列を返します。
common_location_path
common_location_path(project: str, location: str) -> str
完全修飾ロケーション文字列を返します。
common_organization_path
common_organization_path(organization: str) -> str
完全修飾された組織文字列を返します。
common_project_path
common_project_path(project: str) -> str
完全修飾プロジェクト文字列を返します。
custom_class_path
custom_class_path(project: str, location: str, custom_class: str) -> str
完全修飾の custom_class 文字列を返します。
from_service_account_file
from_service_account_file(filename: str, *args, **kwargs)
指定された認証情報ファイルを使用して、このクライアントのインスタンスを作成します。
パラメータ | |
---|---|
名前 | 説明 |
filename |
str
サービス アカウントの秘密鍵の JSON ファイルへのパス。 |
戻り値 | |
---|---|
型 | 説明 |
SpeechAsyncClient | 構築されたクライアント。 |
from_service_account_info
from_service_account_info(info: dict, *args, **kwargs)
指定された認証情報を使用して、このクライアントのインスタンスを作成します。
パラメータ | |
---|---|
名前 | 説明 |
info |
dict
サービス アカウントの秘密鍵情報。 |
戻り値 | |
---|---|
型 | 説明 |
SpeechAsyncClient | 構築されたクライアント。 |
from_service_account_json
from_service_account_json(filename: str, *args, **kwargs)
指定された認証情報ファイルを使用して、このクライアントのインスタンスを作成します。
パラメータ | |
---|---|
名前 | 説明 |
filename |
str
サービス アカウントの秘密鍵の JSON ファイルへのパス。 |
戻り値 | |
---|---|
型 | 説明 |
SpeechAsyncClient | 構築されたクライアント。 |
get_mtls_endpoint_and_cert_source
get_mtls_endpoint_and_cert_source(
client_options: typing.Optional[
google.api_core.client_options.ClientOptions
] = None,
)
相互 TLS の API エンドポイントとクライアント証明書のソースを返します。
クライアント証明書のソースは次の順序で決定されます。(1)GOOGLE_API_USE_CLIENT_CERTIFICATE
環境変数が「true」でない場合、クライアント証明書のソースは None になります。(2)client_options.client_cert_source
が指定されている場合は、指定されたものを使用します。デフォルトのクライアント証明書ソースが存在する場合は、デフォルトのものを使用します。それ以外の場合は、クライアント証明書ソースは None になります。
API エンドポイントは次の順序で決定されます。(1)client_options.api_endpoint
が指定されている場合は、指定されたものを使用します。(2)GOOGLE_API_USE_CLIENT_CERTIFICATE
環境変数が「always」の場合はデフォルトの mTLS エンドポイントを使用し、環境変数が「never」の場合はデフォルトの API エンドポイントを使用します。それ以外の場合は、クライアント証明書のソースが存在する場合はデフォルトの mTLS エンドポイントを使用し、存在しない場合はデフォルトの API エンドポイントを使用します。
詳しくは、https://google.aip.dev/auth/4114 をご覧ください。
パラメータ | |
---|---|
名前 | 説明 |
client_options |
google.api_core.client_options.ClientOptions
クライアントのカスタム オプション。このメソッドでは、 |
例外 | |
---|---|
型 | 説明 |
google.auth.exceptions.MutualTLSChannelError | エラーが発生した場合。 |
戻り値 | |
---|---|
型 | 説明 |
Tuple[str, Callable[[], Tuple[bytes, bytes]]] | 使用する API エンドポイントとクライアント証明書のソースを返します。 |
get_operation
get_operation(
request: typing.Optional[
google.longrunning.operations_pb2.GetOperationRequest
] = None,
*,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.longrunning.operations_pb2.Operation
長時間実行オペレーションの最新状態を取得します。
パラメータ | |
---|---|
名前 | 説明 |
request |
リクエスト オブジェクト。 |
retry |
google.api_core.retry.Retry
再試行するエラー(ある場合)の指定。 |
timeout |
float
このリクエストのタイムアウト。 |
metadata |
Sequence[Tuple[str, str]]
リクエストとともにメタデータとして送信される文字列。 |
戻り値 | |
---|---|
型 | 説明 |
| Operation オブジェクト。 |
get_transport_class
get_transport_class() -> (
typing.Type[google.cloud.speech_v1p1beta1.services.speech.transports.base.SpeechTransport]
)
適切なトランスポート クラスを返します。
list_operations
list_operations(
request: typing.Optional[
google.longrunning.operations_pb2.ListOperationsRequest
] = None,
*,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.longrunning.operations_pb2.ListOperationsResponse
リクエスト内で指定したフィルタに一致する操作を一覧表示します。
パラメータ | |
---|---|
名前 | 説明 |
request |
リクエスト オブジェクト。 |
retry |
google.api_core.retry.Retry
再試行するエラー(ある場合)の指定。 |
timeout |
float
このリクエストのタイムアウト。 |
metadata |
Sequence[Tuple[str, str]]
リクエストとともにメタデータとして送信される文字列。 |
戻り値 | |
---|---|
型 | 説明 |
| ListOperations メソッドに対するレスポンス メッセージ。 |
long_running_recognize
long_running_recognize(
request: typing.Optional[
typing.Union[
google.cloud.speech_v1p1beta1.types.cloud_speech.LongRunningRecognizeRequest, dict
]
] = None,
*,
config: typing.Optional[
google.cloud.speech_v1p1beta1.types.cloud_speech.RecognitionConfig
] = None,
audio: typing.Optional[
google.cloud.speech_v1p1beta1.types.cloud_speech.RecognitionAudio
] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.api_core.operation_async.AsyncOperation
非同期音声認識を実行します。google.longrunning.Operations インターフェースを介して結果を受け取ります。LongRunningRecognizeResponse
メッセージを含む Operation.error
または Operation.response
のいずれかを返します。非同期音声認識の詳細については、<https://cloud.google.com/speech-to-text/docs/async-recognize>
をご覧ください。
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import speech_v1p1beta1
async def sample_long_running_recognize():
# Create a client
client = speech_v1p1beta1.SpeechAsyncClient()
# Initialize request argument(s)
config = speech_v1p1beta1.RecognitionConfig()
config.language_code = "language_code_value"
audio = speech_v1p1beta1.RecognitionAudio()
audio.content = b'content_blob'
request = speech_v1p1beta1.LongRunningRecognizeRequest(
config=config,
audio=audio,
)
# Make the request
operation = client.long_running_recognize(request=request)
print("Waiting for operation to complete...")
response = (await operation).result()
# Handle the response
print(response)
パラメータ | |
---|---|
名前 | 説明 |
request |
Optional[Union[google.cloud.speech_v1p1beta1.types.LongRunningRecognizeRequest, dict]]
リクエスト オブジェクト。 |
config |
RecognitionConfig
必須。認識機能にリクエストの処理方法を指定する情報を提供します。これは |
audio |
RecognitionAudio
必須。認識する音声データ。これは |
retry |
google.api_core.retry.Retry
再試行するエラー(ある場合)の指定。 |
timeout |
float
このリクエストのタイムアウト。 |
metadata |
Sequence[Tuple[str, str]]
リクエストとともにメタデータとして送信される文字列。 |
戻り値 | |
---|---|
型 | 説明 |
google.api_core.operation_async.AsyncOperation | 長時間実行オペレーションを表すオブジェクト。オペレーションの結果の型は LongRunningRecognizeResponse になります。LongRunningRecognize メソッドによってクライアントに返される唯一のメッセージ。結果は、0 個以上の連続した SpeechRecognitionResult メッセージとして含まれます。これは、google::longrunning::Operations サービスの GetOperation 呼び出しによって返されるオペレーションの result.response フィールドに含まれます。 |
parse_common_billing_account_path
parse_common_billing_account_path(path: str) -> typing.Dict[str, str]
billing_account パスを構成セグメントに解析します。
parse_common_folder_path
parse_common_folder_path(path: str) -> typing.Dict[str, str]
フォルダパスを構成セグメントに解析します。
parse_common_location_path
parse_common_location_path(path: str) -> typing.Dict[str, str]
ロケーション パスを構成セグメントに解析します。
parse_common_organization_path
parse_common_organization_path(path: str) -> typing.Dict[str, str]
組織パスを構成セグメントに解析します。
parse_common_project_path
parse_common_project_path(path: str) -> typing.Dict[str, str]
プロジェクト パスをコンポーネント セグメントに解析します。
parse_custom_class_path
parse_custom_class_path(path: str) -> typing.Dict[str, str]
custom_class パスを解析してその構成要素に分解します。
parse_phrase_set_path
parse_phrase_set_path(path: str) -> typing.Dict[str, str]
phrase_set パスを解析してその構成要素に分解します。
phrase_set_path
phrase_set_path(project: str, location: str, phrase_set: str) -> str
完全修飾された phrase_set 文字列を返します。
recognize
recognize(
request: typing.Optional[
typing.Union[google.cloud.speech_v1p1beta1.types.cloud_speech.RecognizeRequest, dict]
] = None,
*,
config: typing.Optional[
google.cloud.speech_v1p1beta1.types.cloud_speech.RecognitionConfig
] = None,
audio: typing.Optional[
google.cloud.speech_v1p1beta1.types.cloud_speech.RecognitionAudio
] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.cloud.speech_v1p1beta1.types.cloud_speech.RecognizeResponse
同期音声認識を実行します。すべての音声が送信されて処理された後に結果を受け取ります。
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import speech_v1p1beta1
async def sample_recognize():
# Create a client
client = speech_v1p1beta1.SpeechAsyncClient()
# Initialize request argument(s)
config = speech_v1p1beta1.RecognitionConfig()
config.language_code = "language_code_value"
audio = speech_v1p1beta1.RecognitionAudio()
audio.content = b'content_blob'
request = speech_v1p1beta1.RecognizeRequest(
config=config,
audio=audio,
)
# Make the request
response = await client.recognize(request=request)
# Handle the response
print(response)
パラメータ | |
---|---|
名前 | 説明 |
request |
Optional[Union[google.cloud.speech_v1p1beta1.types.RecognizeRequest, dict]]
リクエスト オブジェクト。 |
config |
RecognitionConfig
必須。認識機能にリクエストの処理方法を指定する情報を提供します。これは |
audio |
RecognitionAudio
必須。認識する音声データ。これは |
retry |
google.api_core.retry.Retry
再試行するエラー(ある場合)の指定。 |
timeout |
float
このリクエストのタイムアウト。 |
metadata |
Sequence[Tuple[str, str]]
リクエストとともにメタデータとして送信される文字列。 |
戻り値 | |
---|---|
型 | 説明 |
google.cloud.speech_v1p1beta1.types.RecognizeResponse | Recognize メソッドによってクライアントに返される唯一のメッセージ。結果は、0 個以上の連続した SpeechRecognitionResult メッセージとして含まれます。 |
streaming_recognize
streaming_recognize(
requests: typing.Optional[
typing.AsyncIterator[
google.cloud.speech_v1p1beta1.types.cloud_speech.StreamingRecognizeRequest
]
] = None,
*,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> typing.Awaitable[
typing.AsyncIterable[
google.cloud.speech_v1p1beta1.types.cloud_speech.StreamingRecognizeResponse
]
]
双方向ストリーミング音声認識を実行します。音声を送信しながら結果を受け取ります。このメソッドは、REST ではなく、gRPC API を介してのみ使用できます。
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import speech_v1p1beta1
async def sample_streaming_recognize():
# Create a client
client = speech_v1p1beta1.SpeechAsyncClient()
# Initialize request argument(s)
streaming_config = speech_v1p1beta1.StreamingRecognitionConfig()
streaming_config.config.language_code = "language_code_value"
request = speech_v1p1beta1.StreamingRecognizeRequest(
streaming_config=streaming_config,
)
# This method expects an iterator which contains
# 'speech_v1p1beta1.StreamingRecognizeRequest' objects
# Here we create a generator that yields a single `request` for
# demonstrative purposes.
requests = [request]
def request_generator():
for request in requests:
yield request
# Make the request
stream = await client.streaming_recognize(requests=request_generator())
# Handle the response
async for response in stream:
print(response)
パラメータ | |
---|---|
名前 | 説明 |
requests |
AsyncIterator[
リクエスト オブジェクトの AsyncIterator。 |
retry |
google.api_core.retry.Retry
再試行するエラー(ある場合)の指定。 |
timeout |
float
このリクエストのタイムアウト。 |
metadata |
Sequence[Tuple[str, str]]
リクエストとともにメタデータとして送信される文字列。 |
戻り値 | |
---|---|
型 | 説明 |
AsyncIterable[google.cloud.speech_v1p1beta1.types.StreamingRecognizeResponse] | StreamingRecognizeResponse は、StreamingRecognize によってクライアントに返される唯一のメッセージです。一連のゼロ個以上の StreamingRecognizeResponse メッセージがクライアントにストリーミングされます。認識可能な音声がなく、single_utterance が false に設定されている場合、メッセージはクライアントにストリーミングされません。音声の処理中に返される一連の StreamingRecognizeResponse の例を次に示します。1. results { alternatives { transcript: "tube" } stability: 0.01 } 2. results { alternatives { transcript: "to be a" } stability: 0.01 } 3. results { alternatives { transcript: "to be" } stability: 0.9 } results { alternatives { transcript: " or not to be" } stability: 0.01 } 4. results { alternatives { transcript: "to be or not to be" confidence: 0.92 } alternatives { transcript: "to bee or not to bee" } is_final: true } 5. results { alternatives { transcript: " that's" } stability: 0.01 } 6. results { alternatives { transcript: " that is" } stability: 0.9 } results { alternatives { transcript: " the question" } stability: 0.01 } 7. results { alternatives { transcript: " that is the question" confidence: 0.98 } alternatives { transcript: " that was the question" } is_final: true } 注: - 上記のレスポンスのうち、最終結果を含むのは #4 と #7 のみです。これらは is_final: true で示されています。これらを連結すると、「to be or not to be that is the question」という完全な音声文字変換テキストが生成されます。- 他のレスポンスには中間結果が含まれます。#3 と #6 には 2 つの暫定的 \results が含まれています。最初の部分は安定性が高く、変更される可能性は低くなります。2 つ目の部分は安定性が低く、変更される可能性が高くなります。UI デザイナーは、安定性の高い結果のみを表示することを選択する場合があります。- 上記の安定性と信頼性の値は、説明のみを目的としています。実際の値はこれとは異なる場合があります。- 各レスポンスでは、次のフィールドの 1 つのみが設定されます: error、speech_event_type、または 1 つ以上の(繰り返し)results。 |