Speech Client#

Basic client for Google Cloud Speech API.

class google.cloud.speech.client.Client(credentials=None, _http=None, _use_grpc=None)[source]#

Bases: google.cloud.client.Client

Client to bundle configuration needed for API requests.

  • credentials (Credentials) – (Optional) The OAuth2 Credentials to use for this client. If not passed (and if no _http object is passed), falls back to the default inferred from the environment.
  • _http (Http) – (Optional) HTTP object to make requests. Can be any object that defines request() with the same interface as request(). If not passed, an _http object is created that is bound to the credentials for the current object. This parameter should be considered private, and could change in the future.
  • _use_grpc (bool) – (Optional) Explicitly specifies whether to use the gRPC transport (via GAX) or HTTP. If unset, falls back to the GOOGLE_CLOUD_DISABLE_GRPC environment variable. This parameter should be considered private, and could change in the future.
SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)#

The scopes required for authenticating as an API consumer.

sample(content=None, source_uri=None, stream=None, encoding=None, sample_rate_hertz=None)[source]#

Factory: construct Sample to use when making recognize requests.

  • content (bytes) – (Optional) Bytes containing audio data.
  • source_uri (str) – (Optional) URI that points to a file that contains audio data bytes as specified in RecognitionConfig. Currently, only Google Cloud Storage URIs are supported, which must be specified in the following format: gs://bucket_name/object_name.
  • stream (file) – (Optional) File like object to stream.
  • encoding (str) – encoding of audio data sent in all RecognitionAudio messages, can be one of: LINEAR16, FLAC, MULAW, AMR, AMR_WB
  • sample_rate_hertz (int) – Sample rate in Hertz of the audio data sent in all requests. Valid values are: 8000-48000. For best results, set the sampling rate of the audio source to 16000 Hz. If that’s not possible, use the native sample rate of the audio source (instead of re-sampling).
Return type:



Instance of Sample.


Helper for speech-related API calls.