Module: Google::Cloud::Speech

Defined in:
lib/google/cloud/speech.rb,
lib/google/cloud/speech/v1.rb,
lib/google/cloud/speech/audio.rb,
lib/google/cloud/speech/result.rb,
lib/google/cloud/speech/stream.rb,
lib/google/cloud/speech/convert.rb,
lib/google/cloud/speech/project.rb,
lib/google/cloud/speech/service.rb,
lib/google/cloud/speech/version.rb,
lib/google/cloud/speech/operation.rb,
lib/google/cloud/speech/credentials.rb,
lib/google/cloud/speech/v1/doc/overview.rb,
lib/google/cloud/speech/v1/speech_client.rb,
lib/google/cloud/speech/v1/cloud_speech_pb.rb,
lib/google/cloud/speech/v1/cloud_speech_services_pb.rb,
lib/google/cloud/speech/v1/doc/google/cloud/speech/v1/cloud_speech.rb

Overview

Ruby Client for Google Cloud Speech API (Alpha)

Google Cloud Speech API: Google Cloud Speech API.

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Google Cloud Speech API.
  4. Setup Authentication.

Installation

$ gem install google-cloud-speech

Preview

SpeechClient

require "google/cloud/speech"

speech_client = Google::Cloud::Speech.new
language_code = "en-US"
sample_rate_hertz = 44100
encoding = :FLAC
config = {
  language_code: language_code,
  sample_rate_hertz: sample_rate_hertz,
  encoding: encoding
}
uri = "gs://gapic-toolkit/hello.flac"
audio = { uri: uri }
response = speech_client.recognize(config, audio)

Next Steps

Defined Under Namespace

Modules: V1 Classes: Audio, Credentials, InterimResult, Operation, Project, Result, Stream

Constant Summary collapse

VERSION =
"0.28.0"

Class Method Summary collapse

Class Method Details

.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::Speech::Project

Creates a new object for connecting to the Speech service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

audio = speech.audio "path/to/audio.raw",
                     encoding: :linear16,
                     language: "en-US",
                     sample_rate: 16000

Parameters:

  • project_id (String)

    Project identifier for the Speech service you are connecting to. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials)

    The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials)

  • scope (String, Array<String>)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/speech
  • timeout (Integer)

    Default timeout to use in requests. Optional.

  • client_config (Hash)

    A hash of values to override the default behavior of the API client. Optional.

  • project (String)

    Alias for the project_id argument. Deprecated.

  • keyfile (String)

    Alias for the credentials argument. Deprecated.

Returns:



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/google/cloud/speech.rb', line 225

def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
             client_config: nil, project: nil, keyfile: nil
  project_id ||= (project || Speech::Project.default_project_id)
  project_id = project_id.to_s # Always cast to a string
  fail ArgumentError, "project_id is missing" if project_id.empty?

  credentials ||= (keyfile || Speech::Credentials.default(scope: scope))
  unless credentials.is_a? Google::Auth::Credentials
    credentials = Speech::Credentials.new credentials, scope: scope
  end

  Speech::Project.new(
    Speech::Service.new(
      project_id, credentials, timeout: timeout,
                               client_config: client_config))
end