ibm_watson 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/bin/console +1 -0
- data/lib/ibm_watson/iam_token_manager.rb +7 -7
- data/lib/ibm_watson/version.rb +3 -1
- data/lib/ibm_watson/watson_service.rb +2 -2
- data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +3 -3
- data/rakefile +1 -1
- data/test/integration/test_assistant_v1.rb +640 -638
- data/test/integration/test_discovery_v1.rb +173 -170
- data/test/integration/test_iam_assistant_v1.rb +674 -672
- data/test/integration/test_language_translator_v3.rb +68 -66
- data/test/integration/test_natural_language_classifier_v1.rb +57 -55
- data/test/integration/test_natural_language_understanding_v1.rb +89 -87
- data/test/integration/test_personality_insights_v3.rb +87 -85
- data/test/integration/test_speech_to_text_v1.rb +143 -142
- data/test/integration/test_text_to_speech_v1.rb +71 -69
- data/test/integration/test_tone_analyzer_v3.rb +65 -63
- data/test/integration/test_visual_recognition_v3.rb +53 -51
- data/test/test_helper.rb +0 -1
- metadata +4 -18
@@ -22,166 +22,167 @@ class MyRecognizeCallback < IBMWatson::RecognizeCallback
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
unless ENV["SPEECH_TO_TEXT_USERNAME"].nil? || ENV["SPEECH_TO_TEXT_PASSWORD"].nil?
|
26
|
+
# Integration tests for the Speech to Text V1 Service
|
27
|
+
class SpeechToTextV1Test < Minitest::Test
|
28
|
+
include Minitest::Hooks
|
29
|
+
attr_accessor :service
|
30
|
+
def before_all
|
31
|
+
@service = IBMWatson::SpeechToTextV1.new(
|
32
|
+
username: ENV["SPEECH_TO_TEXT_USERNAME"],
|
33
|
+
password: ENV["SPEECH_TO_TEXT_PASSWORD"]
|
34
|
+
)
|
35
|
+
@service.add_default_headers(
|
36
|
+
headers: {
|
37
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
38
|
+
"X-Watson-Test" => "1"
|
39
|
+
}
|
40
|
+
)
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
def test_models
|
44
|
+
output = @service.list_models.result
|
45
|
+
refute_nil(output)
|
46
|
+
|
47
|
+
model = @service.get_model(
|
48
|
+
model_id: "ko-KR_BroadbandModel"
|
49
|
+
).result
|
50
|
+
model = model
|
51
|
+
refute_nil(model)
|
52
|
+
|
53
|
+
begin
|
54
|
+
@service.get_model(
|
55
|
+
model_id: "bogus"
|
56
|
+
)
|
57
|
+
rescue StandardError => e
|
58
|
+
refute_nil(e.global_transaction_id)
|
59
|
+
end
|
60
|
+
end
|
46
61
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
62
|
+
def test_recognize_await
|
63
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
64
|
+
future = @service.await.recognize(
|
65
|
+
audio: audio_file,
|
66
|
+
content_type: "audio/l16; rate=44100"
|
67
|
+
)
|
68
|
+
output = future.value.result
|
69
|
+
refute_nil(output["results"][0]["alternatives"][0]["transcript"])
|
70
|
+
end
|
52
71
|
|
53
|
-
|
54
|
-
|
55
|
-
|
72
|
+
def test_recognize_async
|
73
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
74
|
+
future = @service.async.recognize(
|
75
|
+
audio: audio_file,
|
76
|
+
content_type: "audio/l16; rate=44100"
|
56
77
|
)
|
57
|
-
|
58
|
-
|
78
|
+
future.wait!
|
79
|
+
output = future.value.result
|
80
|
+
refute_nil(output["results"][0]["alternatives"][0]["transcript"])
|
59
81
|
end
|
60
|
-
end
|
61
82
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
content_type: "audio/l16; rate=44100"
|
67
|
-
)
|
68
|
-
output = future.value.result
|
69
|
-
refute_nil(output["results"][0]["alternatives"][0]["transcript"])
|
70
|
-
end
|
83
|
+
def test_recognitions
|
84
|
+
output = @service.check_jobs.result
|
85
|
+
refute_nil(output)
|
86
|
+
end
|
71
87
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
future.wait!
|
79
|
-
output = future.value.result
|
80
|
-
refute_nil(output["results"][0]["alternatives"][0]["transcript"])
|
81
|
-
end
|
88
|
+
def test_custom_corpora
|
89
|
+
model = @service.create_language_model(
|
90
|
+
name: "integration_test_model",
|
91
|
+
base_model_name: "en-US_BroadbandModel"
|
92
|
+
).result
|
93
|
+
customization_id = model["customization_id"]
|
82
94
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
95
|
+
output = @service.list_corpora(
|
96
|
+
customization_id: customization_id
|
97
|
+
).result
|
98
|
+
refute_nil(output)
|
87
99
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
).result
|
93
|
-
customization_id = model["customization_id"]
|
94
|
-
|
95
|
-
output = @service.list_corpora(
|
96
|
-
customization_id: customization_id
|
97
|
-
).result
|
98
|
-
refute_nil(output)
|
99
|
-
|
100
|
-
@service.delete_language_model(
|
101
|
-
customization_id: customization_id
|
102
|
-
)
|
103
|
-
end
|
100
|
+
@service.delete_language_model(
|
101
|
+
customization_id: customization_id
|
102
|
+
)
|
103
|
+
end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
def test_acoustic_model
|
106
|
+
list_models = @service.list_acoustic_models.result
|
107
|
+
refute_nil(list_models)
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
create_acoustic_model = @service.create_acoustic_model(
|
110
|
+
name: "integration_test_model_ruby",
|
111
|
+
base_model_name: "en-US_BroadbandModel"
|
112
|
+
).result
|
113
|
+
refute_nil(create_acoustic_model)
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
get_acoustic_model = @service.get_acoustic_model(
|
116
|
+
customization_id: create_acoustic_model["customization_id"]
|
117
|
+
).result
|
118
|
+
refute_nil(get_acoustic_model)
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
@service.reset_acoustic_model(
|
121
|
+
customization_id: get_acoustic_model["customization_id"]
|
122
|
+
)
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
124
|
+
@service.delete_acoustic_model(
|
125
|
+
customization_id: get_acoustic_model["customization_id"]
|
126
|
+
)
|
127
|
+
end
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
129
|
+
def test_recognize_websocket_as_chunks
|
130
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
131
|
+
mycallback = MyRecognizeCallback.new
|
132
|
+
speech = @service.recognize_with_websocket(
|
133
|
+
chunk_data: true,
|
134
|
+
recognize_callback: mycallback,
|
135
|
+
interim_results: true,
|
136
|
+
timestamps: true,
|
137
|
+
max_alternatives: 2,
|
138
|
+
word_alternatives_threshold: 0.5,
|
139
|
+
model: "en-US_BroadbandModel"
|
140
|
+
)
|
141
|
+
Thread.new do
|
142
|
+
until audio_file.eof?
|
143
|
+
chunk = audio_file.read(1024)
|
144
|
+
speech.add_audio_chunk(chunk: chunk)
|
145
|
+
end
|
146
|
+
sleep(1)
|
147
|
+
speech.stop_audio # Tell the websocket object that no more audio will be added
|
145
148
|
end
|
146
|
-
|
147
|
-
|
149
|
+
thr = Thread.new { speech.start }
|
150
|
+
thr.join
|
148
151
|
end
|
149
|
-
thr = Thread.new { speech.start }
|
150
|
-
thr.join
|
151
|
-
end
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
153
|
+
def test_recognize_websocket
|
154
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
155
|
+
mycallback = MyRecognizeCallback.new
|
156
|
+
speech = @service.recognize_with_websocket(
|
157
|
+
audio: audio_file,
|
158
|
+
recognize_callback: mycallback,
|
159
|
+
interim_results: true,
|
160
|
+
timestamps: true,
|
161
|
+
max_alternatives: 2,
|
162
|
+
word_alternatives_threshold: 0.5,
|
163
|
+
model: "en-US_BroadbandModel"
|
164
|
+
)
|
165
|
+
thr = Thread.new { speech.start }
|
166
|
+
thr.join
|
167
|
+
end
|
168
168
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
169
|
+
def test_inactivity_timeout_with_websocket
|
170
|
+
audio_file = File.open(Dir.getwd + "/resources/sound-with-pause.wav")
|
171
|
+
atomic_boolean = Concurrent::AtomicBoolean.new
|
172
|
+
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
|
173
|
+
speech = @service.recognize_with_websocket(
|
174
|
+
audio: audio_file,
|
175
|
+
recognize_callback: mycallback,
|
176
|
+
interim_results: true,
|
177
|
+
inactivity_timeout: 3,
|
178
|
+
timestamps: true,
|
179
|
+
max_alternatives: 2,
|
180
|
+
word_alternatives_threshold: 0.5,
|
181
|
+
model: "en-US_BroadbandModel"
|
182
|
+
)
|
183
|
+
thr = Thread.new { speech.start }
|
184
|
+
thr.join
|
185
|
+
assert(atomic_boolean.true?)
|
186
|
+
end
|
186
187
|
end
|
187
188
|
end
|
@@ -3,79 +3,81 @@
|
|
3
3
|
require_relative("./../test_helper.rb")
|
4
4
|
require("minitest/hooks/test")
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
unless ENV["TEXT_TO_SPEECH_USERNAME"].nil? || ENV["TEXT_TO_SPEECH_PASSWORD"].nil?
|
7
|
+
# Integration tests for the Text to Speech V1 Service
|
8
|
+
class TextToSpeechV1Test < Minitest::Test
|
9
|
+
include Minitest::Hooks
|
10
|
+
attr_accessor :service
|
11
|
+
def before_all
|
12
|
+
@service = IBMWatson::TextToSpeechV1.new(
|
13
|
+
username: ENV["TEXT_TO_SPEECH_USERNAME"],
|
14
|
+
password: ENV["TEXT_TO_SPEECH_PASSWORD"]
|
15
|
+
)
|
16
|
+
@service.add_default_headers(
|
17
|
+
headers: {
|
18
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
19
|
+
"X-Watson-Test" => "1"
|
20
|
+
}
|
21
|
+
)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def test_voices
|
25
|
+
output = @service.list_voices.result
|
26
|
+
refute(output["voices"].nil?)
|
27
|
+
voice = @service.get_voice(voice: output["voices"][0]["name"])
|
28
|
+
refute(voice.nil?)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
def test_speak
|
32
|
+
output = @service.synthesize(
|
33
|
+
text: "my voice is my passport",
|
34
|
+
accept: "audio/wav",
|
35
|
+
voice: "en-US_AllisonVoice"
|
36
|
+
).result
|
37
|
+
refute(output.nil?)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def test_pronunciation
|
41
|
+
output = @service.get_pronunciation(
|
42
|
+
text: "hello"
|
43
|
+
).result
|
44
|
+
refute(output["pronunciation"].nil?)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def test_customizations
|
48
|
+
service_response = @service.list_voice_models
|
49
|
+
refute(service_response.nil?)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
52
|
+
def test_custom_words
|
53
|
+
customization_id = @service.create_voice_model(
|
54
|
+
name: "test_integration_customization",
|
55
|
+
description: "customization for tests"
|
56
|
+
).result["customization_id"]
|
57
|
+
words = @service.list_words(customization_id: customization_id).result["words"]
|
58
|
+
assert(words.length.zero?)
|
59
|
+
@service.add_word(
|
60
|
+
customization_id: customization_id,
|
61
|
+
word: "ACLs",
|
62
|
+
translation: "ackles"
|
63
|
+
)
|
64
|
+
words = [{ "word" => "MACLs", "translation" => "mackles" }]
|
65
|
+
@service.add_words(
|
66
|
+
customization_id: customization_id,
|
67
|
+
words: words
|
68
|
+
)
|
69
|
+
@service.delete_word(
|
70
|
+
customization_id: customization_id,
|
71
|
+
word: "ACLs"
|
72
|
+
)
|
73
|
+
word = @service.get_word(
|
74
|
+
customization_id: customization_id,
|
75
|
+
word: "MACLs"
|
76
|
+
).result
|
77
|
+
assert(word["translation"] == "mackles")
|
78
|
+
@service.delete_voice_model(
|
79
|
+
customization_id: customization_id
|
80
|
+
)
|
81
|
+
end
|
80
82
|
end
|
81
83
|
end
|
@@ -3,70 +3,72 @@
|
|
3
3
|
require("json")
|
4
4
|
require_relative("./../test_helper.rb")
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
6
|
+
unless ENV["TONE_ANALYZER_USERNAME"].nil? || ENV["TONE_ANALYZER_PASSWORD"].nil?
|
7
|
+
# Integration tests for the Tone Analyzer V3 Service
|
8
|
+
class ToneAnalyzerV3Test < Minitest::Test
|
9
|
+
def test_tone
|
10
|
+
tone_text = File.read(Dir.getwd + "/resources/personality.txt")
|
11
|
+
service = IBMWatson::ToneAnalyzerV3.new(
|
12
|
+
version: "2017-09-21",
|
13
|
+
username: ENV["TONE_ANALYZER_USERNAME"],
|
14
|
+
password: ENV["TONE_ANALYZER_PASSWORD"]
|
15
|
+
)
|
16
|
+
service.add_default_headers(
|
17
|
+
headers: {
|
18
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
19
|
+
"X-Watson-Test" => "1"
|
20
|
+
}
|
21
|
+
)
|
22
|
+
service_response = service.tone(
|
23
|
+
tone_input: tone_text,
|
24
|
+
content_type: "text/plain"
|
25
|
+
)
|
26
|
+
assert((200..299).cover?(service_response.status))
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
29
|
+
def test_tone_with_args
|
30
|
+
tone_text = File.read(Dir.getwd + "/resources/personality.txt")
|
31
|
+
service = IBMWatson::ToneAnalyzerV3.new(
|
32
|
+
version: "2017-09-21",
|
33
|
+
username: ENV["TONE_ANALYZER_USERNAME"],
|
34
|
+
password: ENV["TONE_ANALYZER_PASSWORD"]
|
35
|
+
)
|
36
|
+
service.add_default_headers(
|
37
|
+
headers: {
|
38
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
39
|
+
"X-Watson-Test" => "1"
|
40
|
+
}
|
41
|
+
)
|
42
|
+
service_response = service.tone(
|
43
|
+
tone_input: tone_text,
|
44
|
+
content_type: "text/plain",
|
45
|
+
sentences: false
|
46
|
+
)
|
47
|
+
assert((200..299).cover?(service_response.status))
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
50
|
+
def test_tone_chat
|
51
|
+
service = IBMWatson::ToneAnalyzerV3.new(
|
52
|
+
version: "2017-09-21",
|
53
|
+
username: ENV["TONE_ANALYZER_USERNAME"],
|
54
|
+
password: ENV["TONE_ANALYZER_PASSWORD"]
|
55
|
+
)
|
56
|
+
service.add_default_headers(
|
57
|
+
headers: {
|
58
|
+
"X-Watson-Learning-Opt-Out" => "1",
|
59
|
+
"X-Watson-Test" => "1"
|
60
|
+
}
|
61
|
+
)
|
62
|
+
utterances = [
|
63
|
+
{
|
64
|
+
"text" => "I am very happy",
|
65
|
+
"user" => "glenn"
|
66
|
+
}
|
67
|
+
]
|
68
|
+
service_response = service.tone_chat(
|
69
|
+
utterances: utterances
|
70
|
+
)
|
71
|
+
assert((200..299).cover?(service_response.status))
|
72
|
+
end
|
71
73
|
end
|
72
74
|
end
|