Class: Vocalware::Client
- Inherits:
-
Object
- Object
- Vocalware::Client
- Defined in:
- lib/vocalware/client.rb
Overview
Vocalware client, which uses Vocalware’s REST API to generate speech.
Constant Summary collapse
- DEFAULT_ATTRS =
Default attributes
{ :protocol => 'http', :host => 'www.vocalware.com', :path => '/tts/gen.php', :ext => 'mp3' }
Instance Attribute Summary collapse
-
#account_id ⇒ Object
account id (ACC).
-
#api_id ⇒ Object
API id (API).
-
#ext ⇒ Object
whether “mp3” or “swf”.
-
#host ⇒ Object
host to which request will be set.
- #http_client ⇒ Object
-
#path ⇒ Object
path as part of URL to send request.
- #port ⇒ Object
-
#protocol ⇒ Object
whether “http” or “https”.
-
#secret_phrase ⇒ Object
secret phrase.
-
#voice ⇒ Object
voice.
Instance Method Summary collapse
-
#build_url(text, opts = {}) ⇒ String
Build URL where request will be sent.
-
#gen(text, opts = {}) ⇒ String
Generate speech from passed text.
-
#initialize(attrs = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(attrs = {}) ⇒ Client
Returns a new instance of Client.
60 61 62 63 64 65 66 67 |
# File 'lib/vocalware/client.rb', line 60 def initialize(attrs = {}) DEFAULT_ATTRS.merge(attrs).each do |attr_name, value| send("#{attr_name}=", value) end @http_client ||= Faraday.new validate! end |
Instance Attribute Details
#account_id ⇒ Object
account id (ACC)
21 22 23 |
# File 'lib/vocalware/client.rb', line 21 def account_id @account_id end |
#api_id ⇒ Object
API id (API)
24 25 26 |
# File 'lib/vocalware/client.rb', line 24 def api_id @api_id end |
#ext ⇒ Object
whether “mp3” or “swf”
33 34 35 |
# File 'lib/vocalware/client.rb', line 33 def ext @ext end |
#host ⇒ Object
host to which request will be set
36 37 38 |
# File 'lib/vocalware/client.rb', line 36 def host @host end |
#http_client ⇒ Object
48 49 50 |
# File 'lib/vocalware/client.rb', line 48 def http_client @http_client end |
#path ⇒ Object
path as part of URL to send request
39 40 41 |
# File 'lib/vocalware/client.rb', line 39 def path @path end |
#port ⇒ Object
45 46 47 |
# File 'lib/vocalware/client.rb', line 45 def port @port end |
#protocol ⇒ Object
whether “http” or “https”
42 43 44 |
# File 'lib/vocalware/client.rb', line 42 def protocol @protocol end |
#secret_phrase ⇒ Object
secret phrase
27 28 29 |
# File 'lib/vocalware/client.rb', line 27 def secret_phrase @secret_phrase end |
#voice ⇒ Object
voice
30 31 32 |
# File 'lib/vocalware/client.rb', line 30 def voice @voice end |
Instance Method Details
#build_url(text, opts = {}) ⇒ String
Build URL where request will be sent.
88 89 90 91 92 |
# File 'lib/vocalware/client.rb', line 88 def build_url(text, opts = {}) attrs = to_hash.merge(opts) attrs[:text] = text.strip Request.new(attrs).to_url end |
#gen(text, opts = {}) ⇒ String
Generate speech from passed text.
76 77 78 79 |
# File 'lib/vocalware/client.rb', line 76 def gen(text, opts = {}) url = build_url(text, opts) send_request(url) end |