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/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 the Google Cloud Speech API.
  3. Setup Authentication.

Installation

$ gem install google-cloud-speech

Preview

SpeechClient

require "google/cloud/speech/v1"

speech_client = Google::Cloud::Speech::V1::SpeechClient.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, InterimResult, Operation, Project, Result, Stream

Constant Summary collapse

VERSION =
"0.26.0"

Class Method Summary collapse

Class Method Details

.new(project: nil, keyfile: nil, scope: nil, timeout: nil, client_config: 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 (String)

    Project identifier for the Speech service you are connecting to.

  • keyfile (String, Hash)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • 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.

Returns:



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

def self.new project: nil, keyfile: nil, scope: nil, timeout: nil,
             client_config: nil
  project ||= Google::Cloud::Speech::Project.default_project
  project = project.to_s # Always cast to a string
  fail ArgumentError, "project is missing" if project.empty?

  if keyfile.nil?
    credentials = Google::Cloud::Speech::Credentials.default scope: scope
  else
    credentials = Google::Cloud::Speech::Credentials.new(
      keyfile, scope: scope)
  end

  Google::Cloud::Speech::Project.new(
    Google::Cloud::Speech::Service.new(
      project, credentials, timeout: timeout,
                            client_config: client_config))
end