Class: IvonaSpeechCloud::Client
- Inherits:
-
Object
- Object
- IvonaSpeechCloud::Client
- Defined in:
- lib/ivona_speech_cloud/client.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#body ⇒ Object
Returns the value of attribute body.
-
#path ⇒ Object
Returns the value of attribute path.
-
#region ⇒ Object
Returns the value of attribute region.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #content_type ⇒ String
-
#create_speech(*options) ⇒ String
Returns the audio representation of the text.
- #credentials ⇒ Hash
- #credentials? ⇒ Boolean
- #date ⇒ Time
- #endpoint ⇒ String
- #headers ⇒ Hash
- #host ⇒ String
-
#initialize(options = {}) {|_self| ... } ⇒ IvonaSpeechCloud::Client
constructor
Initializes a new Client object.
-
#list_voices(options) ⇒ Hash
Returns a list of TTS voices available.
- #signed_headers ⇒ Hash
- #signer ⇒ AWS4::Signer
- #uri ⇒ URI::HTTPS
- #x_amz_content_sha256(body = "") ⇒ String
- #x_amz_date ⇒ String
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ IvonaSpeechCloud::Client
Initializes a new Client object
12 13 14 15 16 17 18 |
# File 'lib/ivona_speech_cloud/client.rb', line 12 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Attribute Details
#access_key ⇒ Object
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 |
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/ivona_speech_cloud/client.rb', line 6 def body @body end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/ivona_speech_cloud/client.rb', line 6 def path @path end |
#region ⇒ Object
Returns the value of attribute region.
6 7 8 |
# File 'lib/ivona_speech_cloud/client.rb', line 6 def region @region end |
#secret_key ⇒ Object
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_type ⇒ 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
24 25 26 |
# File 'lib/ivona_speech_cloud/client.rb', line 24 def create_speech(*) CreateSpeech.new(self, ).run end |
#credentials ⇒ 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
107 108 109 |
# File 'lib/ivona_speech_cloud/client.rb', line 107 def credentials? credentials.values.all? end |
#date ⇒ Time
71 72 73 |
# File 'lib/ivona_speech_cloud/client.rb', line 71 def date @date ||= Time.now.utc end |
#endpoint ⇒ String
56 57 58 |
# File 'lib/ivona_speech_cloud/client.rb', line 56 def endpoint "https://#{host}" end |
#headers ⇒ 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 |
#host ⇒ 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.
33 34 35 |
# File 'lib/ivona_speech_cloud/client.rb', line 33 def list_voices() ListVoices.new(self, ).run end |
#signed_headers ⇒ Hash
87 88 89 |
# File 'lib/ivona_speech_cloud/client.rb', line 87 def signed_headers signer.sign("POST", uri, headers, body) end |
#signer ⇒ AWS4::Signer
92 93 94 |
# File 'lib/ivona_speech_cloud/client.rb', line 92 def signer @signer ||= AWS4::Signer.new(credentials) end |
#uri ⇒ 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
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_date ⇒ 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 |