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 +4 -4
- data/lib/voice_text_api.rb +25 -19
- data/lib/voice_text_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88b7d1c6fe2918713532506ea0153b1541ace307
|
4
|
+
data.tar.gz: 72f3b40b2f76ab6718dece8bebd10cf008a19d73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7128f6b5f893c22049252248d638707db7e52117a4d3a246f3cf15c4f5402cec5c58444de23f5e8d4442834480885bdc757c6312fe3e45c51d3aa023405ffd5b
|
7
|
+
data.tar.gz: 0321fe8aceb8b5c1e0d098391d2f7d68990802faeda2a4f03fc547cdf9a75f55e8549e7aabd753c62ee0123c5d529409a07d0635ae8a569150c93922909afe32
|
data/lib/voice_text_api.rb
CHANGED
@@ -6,16 +6,9 @@ class VoiceTextAPI
|
|
6
6
|
class BadRequest < StandardError; end
|
7
7
|
class Unauthoeized < StandardError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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:
|
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
|
-
|
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 =
|
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
|
54
|
-
|
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
|
67
|
+
return req
|
62
68
|
end
|
63
69
|
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.
|
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-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|