voice_text_api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b85509670c08ffcade0d1ef1f6268fdeee90816
4
- data.tar.gz: 50564598e1d7b3b55d6175280c74e265806cd1c9
3
+ metadata.gz: 88b7d1c6fe2918713532506ea0153b1541ace307
4
+ data.tar.gz: 72f3b40b2f76ab6718dece8bebd10cf008a19d73
5
5
  SHA512:
6
- metadata.gz: 28defe53bf374ee8fd2eeb581486144369768557bc8e889349684c396add72dd7bbb5064633d6f92fe80d19353d7747c3ed708987884dfd6920f69df36ab7d60
7
- data.tar.gz: 497e9e45b93990c3f3945121f8620391a060e715ddc6e731f1cabed8ba6973eb15b709ceea87eb7cfc8f1e7d38f1a9bf82f62ddeeb1478c6886c9a14f7e46515
6
+ metadata.gz: 7128f6b5f893c22049252248d638707db7e52117a4d3a246f3cf15c4f5402cec5c58444de23f5e8d4442834480885bdc757c6312fe3e45c51d3aa023405ffd5b
7
+ data.tar.gz: 0321fe8aceb8b5c1e0d098391d2f7d68990802faeda2a4f03fc547cdf9a75f55e8549e7aabd753c62ee0123c5d529409a07d0635ae8a569150c93922909afe32
@@ -6,16 +6,9 @@ class VoiceTextAPI
6
6
  class BadRequest < StandardError; end
7
7
  class Unauthoeized < StandardError; end
8
8
 
9
- # speakers
10
- SHOW = :show
11
- HARUKA = :haruka
12
- HIKARI = :hikari
13
- TAKERU = :takeru
14
-
15
- # emotions
16
- HAPPINESS = :happiness
17
- ANGER = :anger
18
- SADNESS = :sadness
9
+ ENDPOINT = URI('https://api.voicetext.jp/v1/tts')
10
+ SPEAKERS = %w(show haruka hikari takeru)
11
+ EMOTIONS = %w(happiness anger sadness)
19
12
 
20
13
  # emotion levels
21
14
  HIGHT = 2
@@ -25,15 +18,14 @@ class VoiceTextAPI
25
18
  @api_key = api_key
26
19
  end
27
20
 
28
- def tts(text, speaker = :show, emotion: nil, emotion_level: 1, pitch: 100, speed: 100, volume: 100)
21
+ def tts(text, speaker = :show, emotion: nil, emotion_level: NORMAL, pitch: 100, speed: 100, volume: 100)
22
+ validate_parameters(speaker, emotion, emotion_level, pitch, speed, volume)
23
+
29
24
  res = nil
30
- uri = URI('https://api.voicetext.jp/v1/tts')
31
- https = Net::HTTP.new(uri.host, 443)
25
+ https = Net::HTTP.new(ENDPOINT.host, 443)
32
26
  https.use_ssl = true
33
27
  https.start do |https|
34
- req = Net::HTTP::Post.new(uri.path)
35
- req.basic_auth(@api_key, '')
36
- req.body = body(text, speaker, emotion, emotion_level, pitch, speed, volume)
28
+ req = create_request(https, text, speaker, emotion, emotion_level, pitch, speed, volume)
37
29
  res = https.request(req)
38
30
  end
39
31
 
@@ -50,14 +42,28 @@ class VoiceTextAPI
50
42
  end
51
43
 
52
44
  private
53
- def body(text, speaker, emotion, emotion_level, pitch, speed, volume)
54
- s = "text=#{ERB::Util.u(text)};speaker=#{ERB::Util.u(speaker)}"
45
+ def validate_parameters(speaker, emotion, emotion_level, pitch, speed, volume)
46
+ raise ArgumentError.new("wrong speaker: #{speaker}" ) unless SPEAKERS.index(speaker.to_s)
47
+ if speaker != :show && emotion != nil
48
+ raise ArgumentError.new("wrong emotion: #{emotion}" ) unless EMOTIONS.index(emotion.to_s)
49
+ end
50
+ raise ArgumentError.new("wrong emotion_level: #{emotion_level}" ) unless (1..2).include?(emotion_level)
51
+ raise ArgumentError.new("wrong pitch: #{pitch}" ) unless (50..200).include?(pitch)
52
+ raise ArgumentError.new("wrong speed: #{speed}" ) unless (50..200).include?(speed)
53
+ raise ArgumentError.new("wrong volume: #{volume}" ) unless (50..200).include?(volume)
54
+ end
55
+
56
+ def create_request(session, text, speaker, emotion, emotion_level, pitch, speed, volume)
57
+ req = Net::HTTP::Post.new(ENDPOINT.path)
58
+ req.basic_auth(@api_key, '')
59
+ s = "text=#{ERB::Util.u(text.encode('UTF-8'))};speaker=#{ERB::Util.u(speaker)}"
55
60
  s << ";emotion=#{ERB::Util.u(emotion)}" if emotion
56
61
  s << ";emotion_level=#{emotion_level.to_i}" unless emotion_level.to_i == 1
57
62
  s << ";pitch=#{pitch.to_i}" unless pitch.to_i == 100
58
63
  s << ";speed=#{speed.to_i}" unless speed.to_i == 100
59
64
  s << ";volume=#{volume.to_i}" unless volume.to_i == 100
65
+ req.body = s
60
66
 
61
- return s
67
+ return req
62
68
  end
63
69
  end
@@ -1,3 +1,3 @@
1
1
  class VoiceTextAPI
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voice_text_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-09 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler