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.
@@ -22,166 +22,167 @@ class MyRecognizeCallback < IBMWatson::RecognizeCallback
22
22
  end
23
23
  end
24
24
 
25
- # Integration tests for the Speech to Text V1 Service
26
- class SpeechToTextV1Test < Minitest::Test
27
- include Minitest::Hooks
28
-
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
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
- def test_models
44
- output = @service.list_models.result
45
- refute_nil(output)
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
- model = @service.get_model(
48
- model_id: "ko-KR_BroadbandModel"
49
- ).result
50
- model = model
51
- refute_nil(model)
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
- begin
54
- @service.get_model(
55
- model_id: "bogus"
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
- rescue StandardError => e
58
- refute_nil(e.global_transaction_id)
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
- 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
83
+ def test_recognitions
84
+ output = @service.check_jobs.result
85
+ refute_nil(output)
86
+ end
71
87
 
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"
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
- def test_recognitions
84
- output = @service.check_jobs.result
85
- refute_nil(output)
86
- end
95
+ output = @service.list_corpora(
96
+ customization_id: customization_id
97
+ ).result
98
+ refute_nil(output)
87
99
 
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"]
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
- def test_acoustic_model
106
- list_models = @service.list_acoustic_models.result
107
- refute_nil(list_models)
105
+ def test_acoustic_model
106
+ list_models = @service.list_acoustic_models.result
107
+ refute_nil(list_models)
108
108
 
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)
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
- get_acoustic_model = @service.get_acoustic_model(
116
- customization_id: create_acoustic_model["customization_id"]
117
- ).result
118
- refute_nil(get_acoustic_model)
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
- @service.reset_acoustic_model(
121
- customization_id: get_acoustic_model["customization_id"]
122
- )
120
+ @service.reset_acoustic_model(
121
+ customization_id: get_acoustic_model["customization_id"]
122
+ )
123
123
 
124
- @service.delete_acoustic_model(
125
- customization_id: get_acoustic_model["customization_id"]
126
- )
127
- end
124
+ @service.delete_acoustic_model(
125
+ customization_id: get_acoustic_model["customization_id"]
126
+ )
127
+ end
128
128
 
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)
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
- sleep(1)
147
- speech.stop_audio # Tell the websocket object that no more audio will be added
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
- 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
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
- 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?)
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
- # Integration tests for the Text to Speech V1 Service
7
- class TextToSpeechV1Test < Minitest::Test
8
- include Minitest::Hooks
9
- attr_accessor :service
10
- def before_all
11
- @service = IBMWatson::TextToSpeechV1.new(
12
- username: ENV["TEXT_TO_SPEECH_USERNAME"],
13
- password: ENV["TEXT_TO_SPEECH_PASSWORD"]
14
- )
15
- @service.add_default_headers(
16
- headers: {
17
- "X-Watson-Learning-Opt-Out" => "1",
18
- "X-Watson-Test" => "1"
19
- }
20
- )
21
- end
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
- def test_voices
24
- output = @service.list_voices.result
25
- refute(output["voices"].nil?)
26
- voice = @service.get_voice(voice: output["voices"][0]["name"])
27
- refute(voice.nil?)
28
- end
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
- def test_speak
31
- output = @service.synthesize(
32
- text: "my voice is my passport",
33
- accept: "audio/wav",
34
- voice: "en-US_AllisonVoice"
35
- ).result
36
- refute(output.nil?)
37
- end
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
- def test_pronunciation
40
- output = @service.get_pronunciation(
41
- text: "hello"
42
- ).result
43
- refute(output["pronunciation"].nil?)
44
- end
40
+ def test_pronunciation
41
+ output = @service.get_pronunciation(
42
+ text: "hello"
43
+ ).result
44
+ refute(output["pronunciation"].nil?)
45
+ end
45
46
 
46
- def test_customizations
47
- service_response = @service.list_voice_models
48
- refute(service_response.nil?)
49
- end
47
+ def test_customizations
48
+ service_response = @service.list_voice_models
49
+ refute(service_response.nil?)
50
+ end
50
51
 
51
- def test_custom_words
52
- customization_id = @service.create_voice_model(
53
- name: "test_integration_customization",
54
- description: "customization for tests"
55
- ).result["customization_id"]
56
- words = @service.list_words(customization_id: customization_id).result["words"]
57
- assert(words.length.zero?)
58
- @service.add_word(
59
- customization_id: customization_id,
60
- word: "ACLs",
61
- translation: "ackles"
62
- )
63
- words = [{ "word" => "MACLs", "translation" => "mackles" }]
64
- @service.add_words(
65
- customization_id: customization_id,
66
- words: words
67
- )
68
- @service.delete_word(
69
- customization_id: customization_id,
70
- word: "ACLs"
71
- )
72
- word = @service.get_word(
73
- customization_id: customization_id,
74
- word: "MACLs"
75
- ).result
76
- assert(word["translation"] == "mackles")
77
- @service.delete_voice_model(
78
- customization_id: customization_id
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
- # Integration tests for the Tone Analyzer V3 Service
7
- class ToneAnalyzerV3Test < Minitest::Test
8
- def test_tone
9
- tone_text = File.read(Dir.getwd + "/resources/personality.txt")
10
- service = IBMWatson::ToneAnalyzerV3.new(
11
- version: "2017-09-21",
12
- username: ENV["TONE_ANALYZER_USERNAME"],
13
- password: ENV["TONE_ANALYZER_PASSWORD"]
14
- )
15
- service.add_default_headers(
16
- headers: {
17
- "X-Watson-Learning-Opt-Out" => "1",
18
- "X-Watson-Test" => "1"
19
- }
20
- )
21
- service_response = service.tone(
22
- tone_input: tone_text,
23
- content_type: "text/plain"
24
- )
25
- assert((200..299).cover?(service_response.status))
26
- end
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
- def test_tone_with_args
29
- tone_text = File.read(Dir.getwd + "/resources/personality.txt")
30
- service = IBMWatson::ToneAnalyzerV3.new(
31
- version: "2017-09-21",
32
- username: ENV["TONE_ANALYZER_USERNAME"],
33
- password: ENV["TONE_ANALYZER_PASSWORD"]
34
- )
35
- service.add_default_headers(
36
- headers: {
37
- "X-Watson-Learning-Opt-Out" => "1",
38
- "X-Watson-Test" => "1"
39
- }
40
- )
41
- service_response = service.tone(
42
- tone_input: tone_text,
43
- content_type: "text/plain",
44
- sentences: false
45
- )
46
- assert((200..299).cover?(service_response.status))
47
- end
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
- def test_tone_chat
50
- service = IBMWatson::ToneAnalyzerV3.new(
51
- version: "2017-09-21",
52
- username: ENV["TONE_ANALYZER_USERNAME"],
53
- password: ENV["TONE_ANALYZER_PASSWORD"]
54
- )
55
- service.add_default_headers(
56
- headers: {
57
- "X-Watson-Learning-Opt-Out" => "1",
58
- "X-Watson-Test" => "1"
59
- }
60
- )
61
- utterances = [
62
- {
63
- "text" => "I am very happy",
64
- "user" => "glenn"
65
- }
66
- ]
67
- service_response = service.tone_chat(
68
- utterances: utterances
69
- )
70
- assert((200..299).cover?(service_response.status))
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