class Voicetext
Constants
- VERSION
Public Class Methods
emotions()
click to toggle source
# File lib/voicetext.rb, line 13 def emotions ['happiness', 'anger', 'sadness'] end
new(api_key)
click to toggle source
# File lib/voicetext.rb, line 19 def initialize(api_key) @api_key = api_key end
speakers()
click to toggle source
# File lib/voicetext.rb, line 9 def speakers ['show', 'haruka', 'hikari', 'takeru'] end
Public Instance Methods
tts(text, speaker, options = {})
click to toggle source
# File lib/voicetext.rb, line 23 def tts(text, speaker, options = {}) 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, options) res = https.request(req) end res.body end
valid_pitch_range?(pitch)
click to toggle source
# File lib/voicetext.rb, line 37 def valid_pitch_range?(pitch) pitch.between?(50, 200) end
valid_speed_range?(speed)
click to toggle source
# File lib/voicetext.rb, line 41 def valid_speed_range?(speed) speed.between?(50, 400) end
valid_volume_range?(volume)
click to toggle source
# File lib/voicetext.rb, line 45 def valid_volume_range?(volume) volume.between?(50, 200) end
Private Instance Methods
body(text, speaker, options)
click to toggle source
# File lib/voicetext.rb, line 51 def body(text, speaker, options) data = "text=#{text}&speaker=#{speaker}" data << "&emotion=#{options[:emotion]}" if options[:emotion] data << "&emotion_level=#{options[:emotion_level]}" if options[:emotion_level] data << "&pitch#{options[:pitch]}" if options[:pitch] data << "&speed#{options[:speed]}" if options[:speed] data << "&volume#{volume[:volume]}" if options[:volume] data end