Class: IvonaSpeechCloud::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ivona_speech_cloud/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ IvonaSpeechCloud::Client

Initializes a new Client object

Parameters:

  • options (Hash) (defaults to: {})

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
# File 'lib/ivona_speech_cloud/client.rb', line 12

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  yield(self) if block_given?
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



6
7
8
# File 'lib/ivona_speech_cloud/client.rb', line 6

def access_key
  @access_key
end

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/ivona_speech_cloud/client.rb', line 6

def body
  @body
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/ivona_speech_cloud/client.rb', line 6

def path
  @path
end

#regionObject

Returns the value of attribute region.



6
7
8
# File 'lib/ivona_speech_cloud/client.rb', line 6

def region
  @region
end

#secret_keyObject

Returns the value of attribute secret_key.



6
7
8
# File 'lib/ivona_speech_cloud/client.rb', line 6

def secret_key
  @secret_key
end

Instance Method Details

#content_typeString

Returns:

  • (String)


82
83
84
# File 'lib/ivona_speech_cloud/client.rb', line 82

def content_type
  "application/json"
end

#create_speech(*options) ⇒ String

Returns the audio representation of the text

Parameters:

  • options (Array)

    A customizable set of options.

Returns:

  • (String)


24
25
26
# File 'lib/ivona_speech_cloud/client.rb', line 24

def create_speech(*options)
  CreateSpeech.new(self, options).run
end

#credentialsHash

Returns:

  • (Hash)


38
39
40
41
42
43
44
# File 'lib/ivona_speech_cloud/client.rb', line 38

def credentials
  {
    access_key: access_key,
    secret_key: secret_key,
    region: region
  }
end

#credentials?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/ivona_speech_cloud/client.rb', line 107

def credentials?
  credentials.values.all?
end

#dateTime

Returns:

  • (Time)


71
72
73
# File 'lib/ivona_speech_cloud/client.rb', line 71

def date
  @date ||= Time.now.utc
end

#endpointString

Returns:

  • (String)


56
57
58
# File 'lib/ivona_speech_cloud/client.rb', line 56

def endpoint
  "https://#{host}"
end

#headersHash

Returns:

  • (Hash)


97
98
99
100
101
102
103
104
# File 'lib/ivona_speech_cloud/client.rb', line 97

def headers
  @headers ||= {
    "Content-Type" => content_type,
    "Host" => host,
    "X-Amz-Content-SHA256" => x_amz_content_sha256,
    "X-Amz-Date" => x_amz_date
  }
end

#hostString

Returns:

  • (String)


61
62
63
# File 'lib/ivona_speech_cloud/client.rb', line 61

def host
  "tts.#{region}.ivonacloud.com"
end

#list_voices(options) ⇒ Hash

Returns a list of TTS voices available. The list can be filtered by passing a language and/or gender parameter.

Parameters:

  • options (Hash)

Returns:

  • (Hash)


33
34
35
# File 'lib/ivona_speech_cloud/client.rb', line 33

def list_voices(options)
  ListVoices.new(self, options).run
end

#signed_headersHash

Returns:

  • (Hash)


87
88
89
# File 'lib/ivona_speech_cloud/client.rb', line 87

def signed_headers
  signer.sign("POST", uri, headers, body)
end

#signerAWS4::Signer

Returns:

  • (AWS4::Signer)


92
93
94
# File 'lib/ivona_speech_cloud/client.rb', line 92

def signer
  @signer ||= AWS4::Signer.new(credentials)
end

#uriURI::HTTPS

Returns:

  • (URI::HTTPS)


47
48
49
50
51
52
53
# File 'lib/ivona_speech_cloud/client.rb', line 47

def uri
  @uri = begin
    uri = URI(endpoint)
    uri.path = path if path
    uri
  end
end

#x_amz_content_sha256(body = "") ⇒ String

Parameters:

  • body (String) (defaults to: "")

Returns:

  • (String)


77
78
79
# File 'lib/ivona_speech_cloud/client.rb', line 77

def x_amz_content_sha256(body="")
  Digest::SHA256.new.update(body).hexdigest
end

#x_amz_dateString

Returns:

  • (String)


66
67
68
# File 'lib/ivona_speech_cloud/client.rb', line 66

def x_amz_date
  date.strftime("%Y%m%dT%H%M%SZ")
end