Cloud Speech-to-Text V1p1beta1 API - Class Google::Cloud::Speech::V1p1beta1::Speech::Client (v0.18.1)

Reference documentation and code samples for the Cloud Speech-to-Text V1p1beta1 API class Google::Cloud::Speech::V1p1beta1::Speech::Client.

Client for the Speech service.

Service that implements Google Cloud Speech API.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the Speech Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all Speech clients
::Google::Cloud::Speech::V1p1beta1::Speech::Client.configure do |config|
  config.timeout = 10.0
end

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the Speech Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#initialize

def initialize() { |config| ... } -> Client

Create a new Speech client object.

Yields
  • (config) — Configure the Speech client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Speech::V1p1beta1::Speech::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Speech::V1p1beta1::Speech::Client.new do |config|
  config.timeout = 10.0
end

#long_running_recognize

def long_running_recognize(request, options = nil) -> ::Gapic::Operation
def long_running_recognize(config: nil, audio: nil, output_config: nil) -> ::Gapic::Operation

Performs asynchronous speech recognition: receive results via the google.longrunning.Operations interface. Returns either an Operation.error or an Operation.response which contains a LongRunningRecognizeResponse message. For more information on asynchronous speech recognition, see the how-to.

Overloads
def long_running_recognize(request, options = nil) -> ::Gapic::Operation
Pass arguments to long_running_recognize via a request object, either of type LongRunningRecognizeRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Speech::V1p1beta1::LongRunningRecognizeRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def long_running_recognize(config: nil, audio: nil, output_config: nil) -> ::Gapic::Operation
Pass arguments to long_running_recognize via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/speech/v1p1beta1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Speech::V1p1beta1::Speech::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Speech::V1p1beta1::LongRunningRecognizeRequest.new

# Call the long_running_recognize method.
result = client.long_running_recognize request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#operations_client

def operations_client() -> ::Google::Cloud::Speech::V1p1beta1::Speech::Operations

Get the associated client for long-running operations.

#recognize

def recognize(request, options = nil) -> ::Google::Cloud::Speech::V1p1beta1::RecognizeResponse
def recognize(config: nil, audio: nil) -> ::Google::Cloud::Speech::V1p1beta1::RecognizeResponse

Performs synchronous speech recognition: receive results after all audio has been sent and processed.

Overloads
def recognize(request, options = nil) -> ::Google::Cloud::Speech::V1p1beta1::RecognizeResponse
Pass arguments to recognize via a request object, either of type RecognizeRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Speech::V1p1beta1::RecognizeRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def recognize(config: nil, audio: nil) -> ::Google::Cloud::Speech::V1p1beta1::RecognizeResponse
Pass arguments to recognize via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/speech/v1p1beta1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Speech::V1p1beta1::Speech::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Speech::V1p1beta1::RecognizeRequest.new

# Call the recognize method.
result = client.recognize request

# The returned object is of type Google::Cloud::Speech::V1p1beta1::RecognizeResponse.
p result

#streaming_recognize

def streaming_recognize(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::Speech::V1p1beta1::StreamingRecognizeResponse>

Performs bidirectional streaming speech recognition: receive results while sending audio. This method is only available via the gRPC API (not REST).

Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/speech/v1p1beta1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Speech::V1p1beta1::Speech::Client.new

# Create an input stream.
input = Gapic::StreamInput.new

# Call the streaming_recognize method to start streaming.
output = client.streaming_recognize input

# Send requests on the stream. For each request object, set fields by
# passing keyword arguments. Be sure to close the stream when done.
input << Google::Cloud::Speech::V1p1beta1::StreamingRecognizeRequest.new
input << Google::Cloud::Speech::V1p1beta1::StreamingRecognizeRequest.new
input.close

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Speech::V1p1beta1::StreamingRecognizeResponse
output.each do |current_response|
  p current_response
end