Class: Voicetext
- Inherits:
-
Object
- Object
- Voicetext
- Defined in:
- lib/voicetext.rb,
lib/voicetext/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Voicetext
constructor
A new instance of Voicetext.
- #tts(text, speaker, options = {}) ⇒ Object
- #valid_pitch_range?(pitch) ⇒ Boolean
- #valid_speed_range?(speed) ⇒ Boolean
- #valid_volume_range?(volume) ⇒ Boolean
Constructor Details
#initialize(api_key) ⇒ Voicetext
Returns a new instance of Voicetext.
19 20 21 |
# File 'lib/voicetext.rb', line 19 def initialize(api_key) @api_key = api_key end |
Class Method Details
.emotions ⇒ Object
13 14 15 |
# File 'lib/voicetext.rb', line 13 def emotions ['happiness', 'anger', 'sadness'] end |
.speakers ⇒ Object
9 10 11 |
# File 'lib/voicetext.rb', line 9 def speakers ['show', 'haruka', 'hikari', 'takeru'] end |
Instance Method Details
#tts(text, speaker, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/voicetext.rb', line 23 def tts(text, speaker, = {}) res = nil uri = URI('https://api.voicetext.jp/v1/tts') http = Net::HTTP.new(uri.host, 443) http.use_ssl = true http.start do |https| req = Net::HTTP::Post.new(uri.path) req.basic_auth(@api_key, '') req.body = body(text, speaker, ) res = https.request(req) end res.body end |
#valid_pitch_range?(pitch) ⇒ Boolean
37 38 39 |
# File 'lib/voicetext.rb', line 37 def valid_pitch_range?(pitch) pitch.between?(50, 200) end |
#valid_speed_range?(speed) ⇒ Boolean
41 42 43 |
# File 'lib/voicetext.rb', line 41 def valid_speed_range?(speed) speed.between?(50, 400) end |
#valid_volume_range?(volume) ⇒ Boolean
45 46 47 |
# File 'lib/voicetext.rb', line 45 def valid_volume_range?(volume) volume.between?(50, 200) end |