Class: Google::Cloud::Speech::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/speech/service.rb

Overview

methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, credentials, host: nil, timeout: nil, client_config: nil) ⇒ Service

Creates a new Service instance.



32
33
34
35
36
37
38
39
# File 'lib/google/cloud/speech/service.rb', line 32

def initialize project, credentials, host: nil, timeout: nil,
               client_config: nil
  @project = project
  @credentials = credentials
  @host = host || V1beta1::SpeechApi::SERVICE_ADDRESS
  @timeout = timeout
  @client_config = client_config || {}
end

Instance Attribute Details

#client_configObject

Returns the value of attribute client_config.



28
29
30
# File 'lib/google/cloud/speech/service.rb', line 28

def client_config
  @client_config
end

#credentialsObject

Returns the value of attribute credentials.



28
29
30
# File 'lib/google/cloud/speech/service.rb', line 28

def credentials
  @credentials
end

#hostObject

Returns the value of attribute host.



28
29
30
# File 'lib/google/cloud/speech/service.rb', line 28

def host
  @host
end

#mocked_opsObject

Returns the value of attribute mocked_ops.



77
78
79
# File 'lib/google/cloud/speech/service.rb', line 77

def mocked_ops
  @mocked_ops
end

#mocked_serviceObject

Returns the value of attribute mocked_service.



64
65
66
# File 'lib/google/cloud/speech/service.rb', line 64

def mocked_service
  @mocked_service
end

#projectObject

Returns the value of attribute project.



28
29
30
# File 'lib/google/cloud/speech/service.rb', line 28

def project
  @project
end

#timeoutObject

Returns the value of attribute timeout.



28
29
30
# File 'lib/google/cloud/speech/service.rb', line 28

def timeout
  @timeout
end

Instance Method Details

#chan_credsObject



46
47
48
49
50
51
# File 'lib/google/cloud/speech/service.rb', line 46

def chan_creds
  return credentials if insecure?
  require "grpc"
  GRPC::Core::ChannelCredentials.new.compose \
    GRPC::Core::CallCredentials.new credentials.client.updater_proc
end

#channelObject



41
42
43
44
# File 'lib/google/cloud/speech/service.rb', line 41

def channel
  require "grpc"
  GRPC::Core::Channel.new host, nil, chan_creds
end

#get_op(name) ⇒ Object



99
100
101
# File 'lib/google/cloud/speech/service.rb', line 99

def get_op name
  execute { ops.get_operation name }
end

#insecure?Boolean



79
80
81
# File 'lib/google/cloud/speech/service.rb', line 79

def insecure?
  credentials == :this_channel_is_insecure
end

#inspectObject



103
104
105
# File 'lib/google/cloud/speech/service.rb', line 103

def inspect
  "#{self.class}(#{@project})"
end

#opsObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/google/cloud/speech/service.rb', line 66

def ops
  return mocked_ops if mocked_ops
  @ops ||= \
    Google::Longrunning::OperationsApi.new(
      service_path: host,
      channel: channel,
      timeout: timeout,
      client_config: client_config,
      app_name: "gcloud-ruby",
      app_version: Google::Cloud::Speech::VERSION)
end

#recognize_async(audio, config) ⇒ Object



89
90
91
92
93
# File 'lib/google/cloud/speech/service.rb', line 89

def recognize_async audio, config
  execute do
    service.async_recognize config, audio, options: default_options
  end
end

#recognize_stream(request_enum) ⇒ Object



95
96
97
# File 'lib/google/cloud/speech/service.rb', line 95

def recognize_stream request_enum
  service.speech_stub.streaming_recognize request_enum
end

#recognize_sync(audio, config) ⇒ Object



83
84
85
86
87
# File 'lib/google/cloud/speech/service.rb', line 83

def recognize_sync audio, config
  execute do
    service.sync_recognize config, audio, options: default_options
  end
end

#serviceObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/google/cloud/speech/service.rb', line 53

def service
  return mocked_service if mocked_service
  @service ||= \
    V1beta1::SpeechApi.new(
      service_path: host,
      channel: channel,
      timeout: timeout,
      client_config: client_config,
      app_name: "gcloud-ruby",
      app_version: Google::Cloud::Speech::VERSION)
end