ibm_watson 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,7 +104,9 @@ module IBMWatson
104
104
  def list_voices
105
105
  headers = {
106
106
  }
107
+
107
108
  method_url = "/v1/voices"
109
+
108
110
  response = request(
109
111
  method: "GET",
110
112
  url: method_url,
@@ -131,14 +133,17 @@ module IBMWatson
131
133
  # information about the specified voice with no customization.
132
134
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
133
135
  def get_voice(voice:, customization_id: nil)
134
- raise ArgumentError("voice must be provided") if voice.nil?
136
+ raise ArgumentError.new("voice must be provided") if voice.nil?
135
137
 
136
138
  headers = {
137
139
  }
140
+
138
141
  params = {
139
142
  "customization_id" => customization_id
140
143
  }
144
+
141
145
  method_url = "/v1/voices/%s" % [ERB::Util.url_encode(voice)]
146
+
142
147
  response = request(
143
148
  method: "GET",
144
149
  url: method_url,
@@ -155,28 +160,99 @@ module IBMWatson
155
160
  ##
156
161
  # @!method synthesize(text:, accept: nil, voice: nil, customization_id: nil)
157
162
  # Synthesize audio.
158
- # Synthesizes text to spoken audio, returning the synthesized audio stream as an
159
- # array of bytes. You can pass a maximum of 5 KB of text. Use the `Accept` header
160
- # or the `accept` query parameter to specify the requested format (MIME type) of the
161
- # response audio. By default, the service uses `audio/ogg;codecs=opus`.
163
+ # Synthesizes text to audio that is spoken in the specified voice. The service bases
164
+ # its understanding of the language for the input text on the specified voice. Use a
165
+ # voice that matches the language of the input text.
162
166
  #
163
- # If a request includes invalid query parameters, the service returns a `Warnings`
164
- # response header that provides messages about the invalid parameters. The warning
165
- # includes a descriptive message and a list of invalid argument strings. For
166
- # example, a message such as `\"Unknown arguments:\"` or `\"Unknown url query
167
- # arguments:\"` followed by a list of the form `\"invalid_arg_1, invalid_arg_2.\"`
168
- # The request succeeds despite the warnings.
167
+ # The service returns the synthesized audio stream as an array of bytes. You can
168
+ # pass a maximum of 5 KB of text to the service.
169
169
  #
170
170
  # **See also:** [Synthesizing text to
171
171
  # audio](https://console.bluemix.net/docs/services/text-to-speech/http.html#synthesize).
172
- # @param text [String] The text to synthesize.
173
- # @param accept [String] The requested audio format (MIME type) of the audio. You can use the `Accept`
174
- # header or the `accept` query parameter to specify the audio format. (For the
175
- # `audio/l16` format, you can optionally specify `endianness=big-endian` or
176
- # `endianness=little-endian`; the default is little endian.) For detailed
177
- # information about the supported audio formats and sampling rates, see [Specifying
178
- # an audio
172
+ #
173
+ # ### Audio formats (accept types)
174
+ #
175
+ # The service can return audio in the following formats (MIME types).
176
+ # * Where indicated, you can optionally specify the sampling rate (`rate`) of the
177
+ # audio. You must specify a sampling rate for the `audio/l16` and `audio/mulaw`
178
+ # formats. A specified sampling rate must lie in the range of 8 kHz to 192 kHz.
179
+ # * For the `audio/l16` format, you can optionally specify the endianness
180
+ # (`endianness`) of the audio: `endianness=big-endian` or
181
+ # `endianness=little-endian`.
182
+ #
183
+ # Use the `Accept` header or the `accept` parameter to specify the requested format
184
+ # of the response audio. If you omit an audio format altogether, the service returns
185
+ # the audio in Ogg format with the Opus codec (`audio/ogg;codecs=opus`). The service
186
+ # always returns single-channel audio.
187
+ # * `audio/basic`
188
+ #
189
+ # The service returns audio with a sampling rate of 8000 Hz.
190
+ # * `audio/flac`
191
+ #
192
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
193
+ # 22,050 Hz.
194
+ # * `audio/l16`
195
+ #
196
+ # You must specify the `rate` of the audio. You can optionally specify the
197
+ # `endianness` of the audio. The default endianness is `little-endian`.
198
+ # * `audio/mp3`
199
+ #
200
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
201
+ # 22,050 Hz.
202
+ # * `audio/mpeg`
203
+ #
204
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
205
+ # 22,050 Hz.
206
+ # * `audio/mulaw`
207
+ #
208
+ # You must specify the `rate` of the audio.
209
+ # * `audio/ogg`
210
+ #
211
+ # The service returns the audio in the `vorbis` codec. You can optionally specify
212
+ # the `rate` of the audio. The default sampling rate is 22,050 Hz.
213
+ # * `audio/ogg;codecs=opus`
214
+ #
215
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
216
+ # 22,050 Hz.
217
+ # * `audio/ogg;codecs=vorbis`
218
+ #
219
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
220
+ # 22,050 Hz.
221
+ # * `audio/wav`
222
+ #
223
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
224
+ # 22,050 Hz.
225
+ # * `audio/webm`
226
+ #
227
+ # The service returns the audio in the `opus` codec. The service returns audio
228
+ # with a sampling rate of 48,000 Hz.
229
+ # * `audio/webm;codecs=opus`
230
+ #
231
+ # The service returns audio with a sampling rate of 48,000 Hz.
232
+ # * `audio/webm;codecs=vorbis`
233
+ #
234
+ # You can optionally specify the `rate` of the audio. The default sampling rate is
235
+ # 22,050 Hz.
236
+ #
237
+ # For more information about specifying an audio format, including additional
238
+ # details about some of the formats, see [Specifying an audio
179
239
  # format](https://console.bluemix.net/docs/services/text-to-speech/http.html#format).
240
+ #
241
+ # ### Warning messages
242
+ #
243
+ # If a request includes invalid query parameters, the service returns a `Warnings`
244
+ # response header that provides messages about the invalid parameters. The warning
245
+ # includes a descriptive message and a list of invalid argument strings. For
246
+ # example, a message such as `\"Unknown arguments:\"` or `\"Unknown url query
247
+ # arguments:\"` followed by a list of the form `\"{invalid_arg_1},
248
+ # {invalid_arg_2}.\"` The request succeeds despite the warnings.
249
+ # @param text [String] The text to synthesize.
250
+ # @param accept [String] The requested format (MIME type) of the audio. You can use the `Accept` header or
251
+ # the `accept` parameter to specify the audio format. For more information about
252
+ # specifying an audio format, see **Audio formats (accept types)** in the method
253
+ # description.
254
+ #
255
+ # Default: `audio/ogg;codecs=opus`.
180
256
  # @param voice [String] The voice to use for synthesis.
181
257
  # @param customization_id [String] The customization ID (GUID) of a custom voice model to use for the synthesis. If a
182
258
  # custom voice model is specified, it is guaranteed to work only if it matches the
@@ -185,19 +261,23 @@ module IBMWatson
185
261
  # Omit the parameter to use the specified voice with no customization.
186
262
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
187
263
  def synthesize(text:, accept: nil, voice: nil, customization_id: nil)
188
- raise ArgumentError("text must be provided") if text.nil?
264
+ raise ArgumentError.new("text must be provided") if text.nil?
189
265
 
190
266
  headers = {
191
267
  "Accept" => accept
192
268
  }
269
+
193
270
  params = {
194
271
  "voice" => voice,
195
272
  "customization_id" => customization_id
196
273
  }
274
+
197
275
  data = {
198
276
  "text" => text
199
277
  }
278
+
200
279
  method_url = "/v1/synthesize"
280
+
201
281
  response = request(
202
282
  method: "POST",
203
283
  url: method_url,
@@ -239,17 +319,20 @@ module IBMWatson
239
319
  # the specified voice with no customization.
240
320
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
241
321
  def get_pronunciation(text:, voice: nil, format: nil, customization_id: nil)
242
- raise ArgumentError("text must be provided") if text.nil?
322
+ raise ArgumentError.new("text must be provided") if text.nil?
243
323
 
244
324
  headers = {
245
325
  }
326
+
246
327
  params = {
247
328
  "text" => text,
248
329
  "voice" => voice,
249
330
  "format" => format,
250
331
  "customization_id" => customization_id
251
332
  }
333
+
252
334
  method_url = "/v1/pronunciation"
335
+
253
336
  response = request(
254
337
  method: "GET",
255
338
  url: method_url,
@@ -282,16 +365,19 @@ module IBMWatson
282
365
  # recommended.
283
366
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
284
367
  def create_voice_model(name:, language: nil, description: nil)
285
- raise ArgumentError("name must be provided") if name.nil?
368
+ raise ArgumentError.new("name must be provided") if name.nil?
286
369
 
287
370
  headers = {
288
371
  }
372
+
289
373
  data = {
290
374
  "name" => name,
291
375
  "language" => language,
292
376
  "description" => description
293
377
  }
378
+
294
379
  method_url = "/v1/customizations"
380
+
295
381
  response = request(
296
382
  method: "POST",
297
383
  url: method_url,
@@ -323,10 +409,13 @@ module IBMWatson
323
409
  def list_voice_models(language: nil)
324
410
  headers = {
325
411
  }
412
+
326
413
  params = {
327
414
  "language" => language
328
415
  }
416
+
329
417
  method_url = "/v1/customizations"
418
+
330
419
  response = request(
331
420
  method: "GET",
332
421
  url: method_url,
@@ -368,8 +457,7 @@ module IBMWatson
368
457
  # model](https://console.bluemix.net/docs/services/text-to-speech/custom-models.html#cuModelsUpdate)
369
458
  # * [Adding words to a Japanese custom
370
459
  # model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
371
- # * [Understanding
372
- # customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
460
+ # * [Understanding customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
373
461
  # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
374
462
  # with service credentials created for the instance of the service that owns the
375
463
  # custom model.
@@ -380,16 +468,19 @@ module IBMWatson
380
468
  # additions or updates.
381
469
  # @return [nil]
382
470
  def update_voice_model(customization_id:, name: nil, description: nil, words: nil)
383
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
471
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
384
472
 
385
473
  headers = {
386
474
  }
475
+
387
476
  data = {
388
477
  "name" => name,
389
478
  "description" => description,
390
479
  "words" => words
391
480
  }
481
+
392
482
  method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
483
+
393
484
  request(
394
485
  method: "POST",
395
486
  url: method_url,
@@ -417,11 +508,13 @@ module IBMWatson
417
508
  # custom model.
418
509
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
419
510
  def get_voice_model(customization_id:)
420
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
511
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
421
512
 
422
513
  headers = {
423
514
  }
515
+
424
516
  method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
517
+
425
518
  response = request(
426
519
  method: "GET",
427
520
  url: method_url,
@@ -446,11 +539,13 @@ module IBMWatson
446
539
  # custom model.
447
540
  # @return [nil]
448
541
  def delete_voice_model(customization_id:)
449
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
542
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
450
543
 
451
544
  headers = {
452
545
  }
546
+
453
547
  method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
548
+
454
549
  request(
455
550
  method: "DELETE",
456
551
  url: method_url,
@@ -493,8 +588,7 @@ module IBMWatson
493
588
  # model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordsAdd)
494
589
  # * [Adding words to a Japanese custom
495
590
  # model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
496
- # * [Understanding
497
- # customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
591
+ # * [Understanding customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
498
592
  # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
499
593
  # with service credentials created for the instance of the service that owns the
500
594
  # custom model.
@@ -508,16 +602,19 @@ module IBMWatson
508
602
  # array is empty if the custom model contains no words.
509
603
  # @return [nil]
510
604
  def add_words(customization_id:, words:)
511
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
605
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
512
606
 
513
- raise ArgumentError("words must be provided") if words.nil?
607
+ raise ArgumentError.new("words must be provided") if words.nil?
514
608
 
515
609
  headers = {
516
610
  }
611
+
517
612
  data = {
518
613
  "words" => words
519
614
  }
615
+
520
616
  method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)]
617
+
521
618
  request(
522
619
  method: "POST",
523
620
  url: method_url,
@@ -545,11 +642,13 @@ module IBMWatson
545
642
  # custom model.
546
643
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
547
644
  def list_words(customization_id:)
548
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
645
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
549
646
 
550
647
  headers = {
551
648
  }
649
+
552
650
  method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)]
651
+
553
652
  response = request(
554
653
  method: "GET",
555
654
  url: method_url,
@@ -589,8 +688,7 @@ module IBMWatson
589
688
  # model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordAdd)
590
689
  # * [Adding words to a Japanese custom
591
690
  # model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
592
- # * [Understanding
593
- # customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
691
+ # * [Understanding customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
594
692
  # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
595
693
  # with service credentials created for the instance of the service that owns the
596
694
  # custom model.
@@ -607,19 +705,22 @@ module IBMWatson
607
705
  # entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
608
706
  # @return [nil]
609
707
  def add_word(customization_id:, word:, translation:, part_of_speech: nil)
610
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
708
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
611
709
 
612
- raise ArgumentError("word must be provided") if word.nil?
710
+ raise ArgumentError.new("word must be provided") if word.nil?
613
711
 
614
- raise ArgumentError("translation must be provided") if translation.nil?
712
+ raise ArgumentError.new("translation must be provided") if translation.nil?
615
713
 
616
714
  headers = {
617
715
  }
716
+
618
717
  data = {
619
718
  "translation" => translation,
620
719
  "part_of_speech" => part_of_speech
621
720
  }
721
+
622
722
  method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
723
+
623
724
  request(
624
725
  method: "PUT",
625
726
  url: method_url,
@@ -647,13 +748,15 @@ module IBMWatson
647
748
  # @param word [String] The word that is to be queried from the custom voice model.
648
749
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
649
750
  def get_word(customization_id:, word:)
650
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
751
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
651
752
 
652
- raise ArgumentError("word must be provided") if word.nil?
753
+ raise ArgumentError.new("word must be provided") if word.nil?
653
754
 
654
755
  headers = {
655
756
  }
757
+
656
758
  method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
759
+
657
760
  response = request(
658
761
  method: "GET",
659
762
  url: method_url,
@@ -680,13 +783,15 @@ module IBMWatson
680
783
  # @param word [String] The word that is to be deleted from the custom voice model.
681
784
  # @return [nil]
682
785
  def delete_word(customization_id:, word:)
683
- raise ArgumentError("customization_id must be provided") if customization_id.nil?
786
+ raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
684
787
 
685
- raise ArgumentError("word must be provided") if word.nil?
788
+ raise ArgumentError.new("word must be provided") if word.nil?
686
789
 
687
790
  headers = {
688
791
  }
792
+
689
793
  method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
794
+
690
795
  request(
691
796
  method: "DELETE",
692
797
  url: method_url,
@@ -716,14 +821,17 @@ module IBMWatson
716
821
  # @param customer_id [String] The customer ID for which all data is to be deleted.
717
822
  # @return [nil]
718
823
  def delete_user_data(customer_id:)
719
- raise ArgumentError("customer_id must be provided") if customer_id.nil?
824
+ raise ArgumentError.new("customer_id must be provided") if customer_id.nil?
720
825
 
721
826
  headers = {
722
827
  }
828
+
723
829
  params = {
724
830
  "customer_id" => customer_id
725
831
  }
832
+
726
833
  method_url = "/v1/user_data"
834
+
727
835
  request(
728
836
  method: "DELETE",
729
837
  url: method_url,
@@ -22,9 +22,9 @@
22
22
  # to respond to each customer appropriately, or to understand and improve their customer
23
23
  # conversations.
24
24
  #
25
- # **Note:** Request logging is disabled for the Tone Analyzer service. The service neither
26
- # logs nor retains data from requests and responses, regardless of whether the
27
- # `X-Watson-Learning-Opt-Out` request header is set.
25
+ # **Note:** Request logging is disabled for the Tone Analyzer service. Regardless of
26
+ # whether you set the `X-Watson-Learning-Opt-Out` request header, the service does not log
27
+ # or retain data from requests and responses.
28
28
 
29
29
  require "concurrent"
30
30
  require "erb"
@@ -97,7 +97,7 @@ module IBMWatson
97
97
  #########################
98
98
 
99
99
  ##
100
- # @!method tone(tone_input:, content_type:, sentences: nil, tones: nil, content_language: nil, accept_language: nil)
100
+ # @!method tone(tone_input:, content_type: nil, sentences: nil, tones: nil, content_language: nil, accept_language: nil)
101
101
  # Analyze general tone.
102
102
  # Use the general purpose endpoint to analyze the tone of your input content. The
103
103
  # service analyzes the content for emotional and language tones. The method always
@@ -145,27 +145,29 @@ module IBMWatson
145
145
  # as `en`. You can use different languages for **Content-Language** and
146
146
  # **Accept-Language**.
147
147
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
148
- def tone(tone_input:, content_type:, sentences: nil, tones: nil, content_language: nil, accept_language: nil)
149
- raise ArgumentError("tone_input must be provided") if tone_input.nil?
150
-
151
- raise ArgumentError("content_type must be provided") if content_type.nil?
148
+ def tone(tone_input:, content_type: nil, sentences: nil, tones: nil, content_language: nil, accept_language: nil)
149
+ raise ArgumentError.new("tone_input must be provided") if tone_input.nil?
152
150
 
153
151
  headers = {
154
152
  "Content-Type" => content_type,
155
153
  "Content-Language" => content_language,
156
154
  "Accept-Language" => accept_language
157
155
  }
156
+
158
157
  params = {
159
158
  "version" => @version,
160
159
  "sentences" => sentences,
161
160
  "tones" => tones.to_a
162
161
  }
162
+
163
163
  if content_type.start_with?("application/json") && tone_input.instance_of?(Hash)
164
164
  data = tone_input.to_json
165
165
  else
166
166
  data = tone_input
167
167
  end
168
+
168
169
  method_url = "/v3/tone"
170
+
169
171
  response = request(
170
172
  method: "POST",
171
173
  url: method_url,
@@ -209,19 +211,23 @@ module IBMWatson
209
211
  # **Accept-Language**.
210
212
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
211
213
  def tone_chat(utterances:, content_language: nil, accept_language: nil)
212
- raise ArgumentError("utterances must be provided") if utterances.nil?
214
+ raise ArgumentError.new("utterances must be provided") if utterances.nil?
213
215
 
214
216
  headers = {
215
217
  "Content-Language" => content_language,
216
218
  "Accept-Language" => accept_language
217
219
  }
220
+
218
221
  params = {
219
222
  "version" => @version
220
223
  }
224
+
221
225
  data = {
222
226
  "utterances" => utterances
223
227
  }
228
+
224
229
  method_url = "/v3/tone_chat"
230
+
225
231
  response = request(
226
232
  method: "POST",
227
233
  url: method_url,