Reference documentation and code samples for the Cloud Speech-to-Text V1 API class Google::Cloud::Speech::V1::Speech::Client.
Client for the Speech service.
Service that implements Google Cloud Speech API.
Inherits
- Object
Methods
.configure
def self.configure() { |config| ... } -> Client::Configuration
- (config) — Configure the Client client.
- config (Client::Configuration)
# Modify the configuration for all Speech clients ::Google::Cloud::Speech::V1::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.
- (config) — Configure the Client client.
- config (Client::Configuration)
#initialize
def initialize() { |config| ... } -> Client
Create a new Speech client object.
- (config) — Configure the Speech client.
- config (Client::Configuration)
- (Client) — a new instance of Client
# Create a client using the default configuration client = ::Google::Cloud::Speech::V1::Speech::Client.new # Create a client using a custom configuration client = ::Google::Cloud::Speech::V1::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.
def long_running_recognize(request, options = nil) -> ::Gapic::Operation
long_running_recognize
via a request object, either of type
LongRunningRecognizeRequest or an equivalent Hash.
- request (::Google::Cloud::Speech::V1::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
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).
- config (::Google::Cloud::Speech::V1::RecognitionConfig, ::Hash) — Required. Provides information to the recognizer that specifies how to process the request.
- audio (::Google::Cloud::Speech::V1::RecognitionAudio, ::Hash) — Required. The audio data to be recognized.
- output_config (::Google::Cloud::Speech::V1::TranscriptOutputConfig, ::Hash) — Optional. Specifies an optional destination for the recognition results.
- (response, operation) — Access the result along with the RPC operation
- response (::Gapic::Operation)
- operation (::GRPC::ActiveCall::Operation)
- (::Gapic::Operation)
- (::Google::Cloud::Error) — if the RPC is aborted.
Basic example
require "google/cloud/speech/v1" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Speech::V1::Speech::Client.new # Create a request. To set request fields, pass in keyword arguments. request = Google::Cloud::Speech::V1::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::V1::Speech::Operations
Get the associated client for long-running operations.
#recognize
def recognize(request, options = nil) -> ::Google::Cloud::Speech::V1::RecognizeResponse
def recognize(config: nil, audio: nil) -> ::Google::Cloud::Speech::V1::RecognizeResponse
Performs synchronous speech recognition: receive results after all audio has been sent and processed.
def recognize(request, options = nil) -> ::Google::Cloud::Speech::V1::RecognizeResponse
recognize
via a request object, either of type
RecognizeRequest or an equivalent Hash.
- request (::Google::Cloud::Speech::V1::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::V1::RecognizeResponse
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).
- config (::Google::Cloud::Speech::V1::RecognitionConfig, ::Hash) — Required. Provides information to the recognizer that specifies how to process the request.
- audio (::Google::Cloud::Speech::V1::RecognitionAudio, ::Hash) — Required. The audio data to be recognized.
- (response, operation) — Access the result along with the RPC operation
- response (::Google::Cloud::Speech::V1::RecognizeResponse)
- operation (::GRPC::ActiveCall::Operation)
- (::Google::Cloud::Error) — if the RPC is aborted.
Basic example
require "google/cloud/speech/v1" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Speech::V1::Speech::Client.new # Create a request. To set request fields, pass in keyword arguments. request = Google::Cloud::Speech::V1::RecognizeRequest.new # Call the recognize method. result = client.recognize request # The returned object is of type Google::Cloud::Speech::V1::RecognizeResponse. p result
#streaming_recognize
def streaming_recognize(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::Speech::V1::StreamingRecognizeResponse>
Performs bidirectional streaming speech recognition: receive results while sending audio. This method is only available via the gRPC API (not REST).
- request (::Gapic::StreamInput, ::Enumerable<::Google::Cloud::Speech::V1::StreamingRecognizeRequest, ::Hash>) — An enumerable of Google::Cloud::Speech::V1::StreamingRecognizeRequest instances.
- options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
- (response, operation) — Access the result along with the RPC operation
- response (::Enumerable<::Google::Cloud::Speech::V1::StreamingRecognizeResponse>)
- operation (::GRPC::ActiveCall::Operation)
- (::Enumerable<::Google::Cloud::Speech::V1::StreamingRecognizeResponse>)
- (::Google::Cloud::Error) — if the RPC is aborted.
Basic example
require "google/cloud/speech/v1" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Speech::V1::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::V1::StreamingRecognizeRequest.new input << Google::Cloud::Speech::V1::StreamingRecognizeRequest.new input.close # The returned object is a streamed enumerable yielding elements of type # ::Google::Cloud::Speech::V1::StreamingRecognizeResponse output.each do |current_response| p current_response end