클래스 SpeechAsyncClient (2.15.0)

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를 구현하는 서비스입니다.

속성

전송

클라이언트 인스턴스에서 사용한 전송을 반환합니다.

반환
유형설명
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, .SpeechTransport]

사용할 전송입니다. None으로 설정하면 전송이 자동으로 선택됩니다.

client_options ClientOptions

클라이언트의 맞춤 옵션입니다. transport 인스턴스가 제공되면 적용되지 않습니다. (1) api_endpoint 속성을 사용하여 클라이언트에서 제공하는 기본 엔드포인트를 재정의할 수 있습니다. GOOGLE_API_USE_MTLS_ENDPOINT 환경 변수를 사용하여 엔드포인트를 재정의할 수도 있습니다('always'(항상 기본 mTLS 엔드포인트 사용), 'never'(항상 기본 일반 엔드포인트 사용), 'auto'(클라이언트 인증서가 있는 경우 기본 mTLS 엔드포인트로 자동 전환, 기본값)). 하지만 api_endpoint 속성이 제공되면 우선합니다. (2) GOOGLE_API_USE_CLIENT_CERTIFICATE 환경 변수가 'true'인 경우 client_cert_source 속성을 사용하여 상호 TLS 전송을 위한 클라이언트 인증서를 제공할 수 있습니다. 제공되지 않으면 기본 SSL 클라이언트 인증서가 있는 경우 사용됩니다. GOOGLE_API_USE_CLIENT_CERTIFICATE가 'false'이거나 설정되지 않은 경우 클라이언트 인증서가 사용되지 않습니다.

예외
유형설명
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

클라이언트의 맞춤 옵션입니다. 이 메서드에서는 api_endpointclient_cert_source 속성만 사용할 수 있습니다.

예외
유형설명
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 .operations_pb2.GetOperationRequest

요청 객체입니다. GetOperation 메서드의 요청 메시지입니다.

retry google.api_core.retry.Retry

재시도해야 하는 오류(있는 경우)의 지정입니다.

timeout float

이 요청의 제한 시간입니다.

metadata Sequence[Tuple[str, str]]

요청과 함께 메타데이터로 전송되어야 하는 문자열입니다.

반환
유형설명
.operations_pb2.OperationOperation 객체

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 .operations_pb2.ListOperationsRequest

요청 객체입니다. ListOperations 메서드의 요청 메시지입니다.

retry google.api_core.retry.Retry

재시도해야 하는 오류(있는 경우)의 지정입니다.

timeout float

이 요청의 제한 시간입니다.

metadata Sequence[Tuple[str, str]]

요청과 함께 메타데이터로 전송되어야 하는 문자열입니다.

반환
유형설명
.operations_pb2.ListOperationsResponseListOperations 메서드의 응답 메시지입니다.

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]]

요청 객체입니다. LongRunningRecognize 메서드에 대해 클라이언트가 보낸 최상위 메시지입니다.

config RecognitionConfig

필수 항목입니다. 인식기에 요청 처리 방식을 지정하는 정보를 제공합니다. 이는 request 인스턴스의 config 필드에 해당합니다. request이 제공된 경우 이를 설정하면 안 됩니다.

audio RecognitionAudio

필수 항목입니다. 인식할 오디오 데이터입니다. 이는 request 인스턴스의 audio 필드에 해당합니다. request이 제공된 경우 이를 설정하면 안 됩니다.

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 호출에서 반환된 Operation의 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]]

요청 객체입니다. Recognize 메서드에 대해 클라이언트가 보낸 최상위 메시지입니다.

config RecognitionConfig

필수 항목입니다. 인식기에 요청 처리 방식을 지정하는 정보를 제공합니다. 이는 request 인스턴스의 config 필드에 해당합니다. request이 제공된 경우 이를 설정하면 안 됩니다.

audio RecognitionAudio

필수 항목입니다. 인식할 오디오 데이터입니다. 이는 request 인스턴스의 audio 필드에 해당합니다. request이 제공된 경우 이를 설정하면 안 됩니다.

retry google.api_core.retry.Retry

재시도해야 하는 오류(있는 경우)의 지정입니다.

timeout float

이 요청의 제한 시간입니다.

metadata Sequence[Tuple[str, str]]

요청과 함께 메타데이터로 전송되어야 하는 문자열입니다.

반환
유형설명
google.cloud.speech_v1p1beta1.types.RecognizeResponseRecognize 메서드에서 클라이언트에 반환되는 유일한 메시지입니다. 결과가 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
    ]
]

양방향 스트리밍 음성 인식을 수행합니다. 오디오 전송 중에 결과를 수신합니다. 이 메서드는 gRPC API (REST 아님)를 통해서만 사용할 수 있습니다.

# 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[google.cloud.speech_v1p1beta1.types.StreamingRecognizeRequest]

요청 객체 AsyncIterator입니다. StreamingRecognize 메서드에 대해 클라이언트가 보낸 최상위 메시지입니다. 여러 StreamingRecognizeRequest 메시지가 전송됩니다. 첫 번째 메시지는 streaming_config 메시지를 포함해야 하며 audio_content를 포함해서는 안 됩니다. 이후의 모든 메시지는 audio_content를 포함해야 하며 streaming_config 메시지를 포함해서는 안 됩니다.

retry google.api_core.retry.Retry

재시도해야 하는 오류(있는 경우)의 지정입니다.

timeout float

이 요청의 제한 시간입니다.

metadata Sequence[Tuple[str, str]]

요청과 함께 메타데이터로 전송되어야 하는 문자열입니다.

반환
유형설명
AsyncIterable[google.cloud.speech_v1p1beta1.types.StreamingRecognizeResponse]StreamingRecognizeResponse는 StreamingRecognize에서 클라이언트로 반환하는 유일한 메시지입니다. 0개 이상의 StreamingRecognizeResponse 메시지가 클라이언트로 다시 스트리밍됩니다. 인식 가능한 오디오가 없고 single_utterance가 false로 설정되어 있으면 메시지가 클라이언트로 다시 스트리밍되지 않습니다. 다음은 오디오를 처리하는 동안 반환될 수 있는 일련의 StreamingRecognizeResponses의 예입니다. 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에는 두 개의 중간 \results이 포함되어 있습니다. 첫 번째 부분은 안정성이 높고 변경될 가능성이 낮습니다. 두 번째 부분은 안정성이 낮으며 변경될 가능성이 매우 높습니다. UI 디자이너는 안정성이 높은 결과만 표시할 수 있습니다. - 위에 표시된 특정 안정성 및 신뢰도 값은 참고용입니다. 실제 값은 다를 수 있습니다. - 각 응답에서 error, speech_event_type, 하나 이상의 반복되는 results 필드 중 하나만 설정됩니다.