ibm_watson 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +258 -0
  3. data/bin/console +14 -0
  4. data/bin/setup +8 -0
  5. data/lib/ibm_watson.rb +16 -0
  6. data/lib/ibm_watson/assistant_v1.rb +1997 -0
  7. data/lib/ibm_watson/detailed_response.rb +21 -0
  8. data/lib/ibm_watson/discovery_v1.rb +2039 -0
  9. data/lib/ibm_watson/iam_token_manager.rb +166 -0
  10. data/lib/ibm_watson/language_translator_v3.rb +411 -0
  11. data/lib/ibm_watson/natural_language_classifier_v1.rb +309 -0
  12. data/lib/ibm_watson/natural_language_understanding_v1.rb +297 -0
  13. data/lib/ibm_watson/personality_insights_v3.rb +260 -0
  14. data/lib/ibm_watson/speech_to_text_v1.rb +2153 -0
  15. data/lib/ibm_watson/text_to_speech_v1.rb +716 -0
  16. data/lib/ibm_watson/tone_analyzer_v3.rb +287 -0
  17. data/lib/ibm_watson/version.rb +3 -0
  18. data/lib/ibm_watson/visual_recognition_v3.rb +579 -0
  19. data/lib/ibm_watson/watson_api_exception.rb +41 -0
  20. data/lib/ibm_watson/watson_service.rb +180 -0
  21. data/lib/ibm_watson/websocket/recognize_callback.rb +32 -0
  22. data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +162 -0
  23. data/rakefile +45 -0
  24. data/test/integration/test_assistant_v1.rb +645 -0
  25. data/test/integration/test_discovery_v1.rb +200 -0
  26. data/test/integration/test_iam_assistant_v1.rb +707 -0
  27. data/test/integration/test_language_translator_v3.rb +81 -0
  28. data/test/integration/test_natural_language_classifier_v1.rb +69 -0
  29. data/test/integration/test_natural_language_understanding_v1.rb +98 -0
  30. data/test/integration/test_personality_insights_v3.rb +95 -0
  31. data/test/integration/test_speech_to_text_v1.rb +187 -0
  32. data/test/integration/test_text_to_speech_v1.rb +81 -0
  33. data/test/integration/test_tone_analyzer_v3.rb +72 -0
  34. data/test/integration/test_visual_recognition_v3.rb +64 -0
  35. data/test/test_helper.rb +22 -0
  36. data/test/unit/test_assistant_v1.rb +1598 -0
  37. data/test/unit/test_discovery_v1.rb +1144 -0
  38. data/test/unit/test_iam_token_manager.rb +165 -0
  39. data/test/unit/test_language_translator_v3.rb +461 -0
  40. data/test/unit/test_natural_language_classifier_v1.rb +187 -0
  41. data/test/unit/test_natural_language_understanding_v1.rb +132 -0
  42. data/test/unit/test_personality_insights_v3.rb +172 -0
  43. data/test/unit/test_speech_to_text_v1.rb +755 -0
  44. data/test/unit/test_text_to_speech_v1.rb +336 -0
  45. data/test/unit/test_tone_analyzer_v3.rb +200 -0
  46. data/test/unit/test_vcap_using_personality_insights.rb +150 -0
  47. data/test/unit/test_visual_recognition_v3.rb +345 -0
  48. metadata +302 -0
@@ -0,0 +1,716 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 IBM All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # ### Service Overview
18
+ # The IBM® Text to Speech service provides an API that uses IBM's speech-synthesis
19
+ # capabilities to synthesize text into natural-sounding speech in a variety of languages,
20
+ # dialects, and voices. The service supports at least one male or female voice, sometimes
21
+ # both, for each language. The audio is streamed back to the client with minimal delay.
22
+ # For more information about the service, see the [IBM® Cloud
23
+ # documentation](https://console.bluemix.net/docs/services/text-to-speech/index.html).
24
+ #
25
+ # ### API usage guidelines
26
+ # * **Audio formats:** The service can produce audio in many formats (MIME types). See
27
+ # [Specifying an audio
28
+ # format](https://console.bluemix.net/docs/services/text-to-speech/http.html#format).
29
+ # * **SSML:** Many methods refer to the Speech Synthesis Markup Language (SSML). SSML is
30
+ # an XML-based markup language that provides text annotation for speech-synthesis
31
+ # applications. See [Using
32
+ # SSML](https://console.bluemix.net/docs/services/text-to-speech/SSML.html) and [Using IBM
33
+ # SPR](https://console.bluemix.net/docs/services/text-to-speech/SPRs.html).
34
+ # * **Word translations:** Many customization methods accept sounds-like or phonetic
35
+ # translations for words. Phonetic translations are based on the SSML phoneme format for
36
+ # representing a word. You can specify them in standard International Phonetic Alphabet
37
+ # (IPA) representation
38
+ #
39
+ # <phoneme alphabet="ipa" ph="təmˈɑto"></phoneme>
40
+ #
41
+ # or in the proprietary IBM Symbolic Phonetic Representation (SPR)
42
+ #
43
+ # <phoneme alphabet="ibm" ph="1gAstroEntxrYFXs"></phoneme>
44
+ #
45
+ # See [Understanding
46
+ # customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
47
+ # * **WebSocket interface:** The service also offers a WebSocket interface for speech
48
+ # synthesis. The WebSocket interface supports both plain text and SSML input, including
49
+ # the SSML <mark> element and word timings. See [The WebSocket
50
+ # interface](https://console.bluemix.net/docs/services/text-to-speech/websockets.html).
51
+ # * **Customization IDs:** Many methods accept a customization ID, which is a Globally
52
+ # Unique Identifier (GUID). Customization IDs are hexadecimal strings that have the format
53
+ # `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
54
+ # * **`X-Watson-Learning-Opt-Out`:** By default, all Watson services log requests and
55
+ # their results. Logging is done only to improve the services for future users. The logged
56
+ # data is not shared or made public. To prevent IBM from accessing your data for general
57
+ # service improvements, set the `X-Watson-Learning-Opt-Out` request header to `true` for
58
+ # all requests. You must set the header on each request that you do not want IBM to access
59
+ # for general service improvements.
60
+ #
61
+ # Methods of the customization interface do not log words and translations that you use
62
+ # to build custom voice models. Your training data is never used to improve the service's
63
+ # base models. However, the service does log such data when a custom model is used with a
64
+ # synthesize request. You must set the `X-Watson-Learning-Opt-Out` request header to
65
+ # `true` to prevent IBM from accessing the data to improve the service.
66
+ # * **`X-Watson-Metadata`:** This header allows you to associate a customer ID with data
67
+ # that is passed with a request. If necessary, you can use the **Delete labeled data**
68
+ # method to delete the data for a customer ID. See [Information
69
+ # security](https://console.bluemix.net/docs/services/text-to-speech/information-security.html).
70
+
71
+ require "concurrent"
72
+ require "erb"
73
+ require "json"
74
+ require_relative "./detailed_response"
75
+
76
+ require_relative "./watson_service"
77
+
78
+ module IBMWatson
79
+ ##
80
+ # The Text to Speech V1 service.
81
+ class TextToSpeechV1
82
+ include Concurrent::Async
83
+ ##
84
+ # @!method initialize(args)
85
+ # Construct a new client for the Text to Speech service.
86
+ #
87
+ # @param args [Hash] The args to initialize with
88
+ # @option args url [String] The base url to use when contacting the service (e.g.
89
+ # "https://stream.watsonplatform.net/text-to-speech/api").
90
+ # The base url may differ between Bluemix regions.
91
+ # @option args username [String] The username used to authenticate with the service.
92
+ # Username and password credentials are only required to run your
93
+ # application locally or outside of Bluemix. When running on
94
+ # Bluemix, the credentials will be automatically loaded from the
95
+ # `VCAP_SERVICES` environment variable.
96
+ # @option args password [String] The password used to authenticate with the service.
97
+ # Username and password credentials are only required to run your
98
+ # application locally or outside of Bluemix. When running on
99
+ # Bluemix, the credentials will be automatically loaded from the
100
+ # `VCAP_SERVICES` environment variable.
101
+ # @option args iam_api_key [String] An API key that can be used to request IAM tokens. If
102
+ # this API key is provided, the SDK will manage the token and handle the
103
+ # refreshing.
104
+ # @option args iam_access_token [String] An IAM access token is fully managed by the application.
105
+ # Responsibility falls on the application to refresh the token, either before
106
+ # it expires or reactively upon receiving a 401 from the service as any requests
107
+ # made with an expired token will fail.
108
+ # @option args iam_url [String] An optional URL for the IAM service API. Defaults to
109
+ # 'https://iam.ng.bluemix.net/identity/token'.
110
+ def initialize(args = {})
111
+ @__async_initialized__ = false
112
+ super()
113
+ defaults = {}
114
+ defaults[:url] = "https://stream.watsonplatform.net/text-to-speech/api"
115
+ defaults[:username] = nil
116
+ defaults[:password] = nil
117
+ defaults[:iam_api_key] = nil
118
+ defaults[:iam_access_token] = nil
119
+ defaults[:iam_url] = nil
120
+ args = defaults.merge(args)
121
+ @watson_service = WatsonService.new(
122
+ vcap_services_name: "text_to_speech",
123
+ url: args[:url],
124
+ username: args[:username],
125
+ password: args[:password],
126
+ iam_api_key: args[:iam_api_key],
127
+ iam_access_token: args[:iam_access_token],
128
+ iam_url: args[:iam_url],
129
+ use_vcap_services: true
130
+ )
131
+ end
132
+
133
+ # :nocov:
134
+ def add_default_headers(headers: {})
135
+ @watson_service.add_default_headers(headers: headers)
136
+ end
137
+
138
+ def _iam_access_token(iam_access_token:)
139
+ @watson_service._iam_access_token(iam_access_token: iam_access_token)
140
+ end
141
+
142
+ def _iam_api_key(iam_api_key:)
143
+ @watson_service._iam_api_key(iam_api_key: iam_api_key)
144
+ end
145
+
146
+ # @return [DetailedResponse]
147
+ def request(args)
148
+ @watson_service.request(args)
149
+ end
150
+
151
+ # @note Chainable
152
+ # @param headers [Hash] Custom headers to be sent with the request
153
+ # @return [self]
154
+ def headers(headers)
155
+ @watson_service.headers(headers)
156
+ self
157
+ end
158
+
159
+ def password=(password)
160
+ @watson_service.password = password
161
+ end
162
+
163
+ def password
164
+ @watson_service.password
165
+ end
166
+
167
+ def username=(username)
168
+ @watson_service.username = username
169
+ end
170
+
171
+ def username
172
+ @watson_service.username
173
+ end
174
+
175
+ def url=(url)
176
+ @watson_service.url = url
177
+ end
178
+
179
+ def url
180
+ @watson_service.url
181
+ end
182
+ # :nocov:
183
+ #########################
184
+ # Voices
185
+ #########################
186
+
187
+ ##
188
+ # @!method list_voices
189
+ # List voices.
190
+ # Lists all voices available for use with the service. The information includes the
191
+ # name, language, gender, and other details about the voice. To see information
192
+ # about a specific voice, use the **Get a voice** method.
193
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
194
+ def list_voices
195
+ headers = {
196
+ }
197
+ method_url = "/v1/voices"
198
+ response = request(
199
+ method: "GET",
200
+ url: method_url,
201
+ headers: headers,
202
+ accept_json: true
203
+ )
204
+ response
205
+ end
206
+
207
+ ##
208
+ # @!method get_voice(voice:, customization_id: nil)
209
+ # Get a voice.
210
+ # Gets information about the specified voice. The information includes the name,
211
+ # language, gender, and other details about the voice. Specify a customization ID to
212
+ # obtain information for that custom voice model of the specified voice. To list
213
+ # information about all available voices, use the **List voices** method.
214
+ # @param voice [String] The voice for which information is to be returned.
215
+ # @param customization_id [String] The customization ID (GUID) of a custom voice model for which information is to be
216
+ # returned. You must make the request with service credentials created for the
217
+ # instance of the service that owns the custom model. Omit the parameter to see
218
+ # information about the specified voice with no customization.
219
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
220
+ def get_voice(voice:, customization_id: nil)
221
+ raise ArgumentError("voice must be provided") if voice.nil?
222
+ headers = {
223
+ }
224
+ params = {
225
+ "customization_id" => customization_id
226
+ }
227
+ method_url = "/v1/voices/%s" % [ERB::Util.url_encode(voice)]
228
+ response = request(
229
+ method: "GET",
230
+ url: method_url,
231
+ headers: headers,
232
+ params: params,
233
+ accept_json: true
234
+ )
235
+ response
236
+ end
237
+ #########################
238
+ # Synthesis
239
+ #########################
240
+
241
+ ##
242
+ # @!method synthesize(text:, accept: nil, voice: nil, customization_id: nil)
243
+ # Synthesize audio.
244
+ # Synthesizes text to spoken audio, returning the synthesized audio stream as an
245
+ # array of bytes. You can pass a maximum of 5 KB of text. Use the `Accept` header
246
+ # or the `accept` query parameter to specify the requested format (MIME type) of the
247
+ # response audio. By default, the service uses `audio/ogg;codecs=opus`. For detailed
248
+ # information about the supported audio formats and sampling rates, see [Specifying
249
+ # an audio
250
+ # format](https://console.bluemix.net/docs/services/text-to-speech/http.html#format).
251
+ #
252
+ #
253
+ # If a request includes invalid query parameters, the service returns a `Warnings`
254
+ # response header that provides messages about the invalid parameters. The warning
255
+ # includes a descriptive message and a list of invalid argument strings. For
256
+ # example, a message such as `\"Unknown arguments:\"` or `\"Unknown url query
257
+ # arguments:\"` followed by a list of the form `\"invalid_arg_1, invalid_arg_2.\"`
258
+ # The request succeeds despite the warnings.
259
+ # @param text [String] The text to synthesize.
260
+ # @param accept [String] The requested audio format (MIME type) of the audio. You can use the `Accept`
261
+ # header or the `accept` query parameter to specify the audio format. (For the
262
+ # `audio/l16` format, you can optionally specify `endianness=big-endian` or
263
+ # `endianness=little-endian`; the default is little endian.) For detailed
264
+ # information about the supported audio formats and sampling rates, see [Specifying
265
+ # an audio
266
+ # format](https://console.bluemix.net/docs/services/text-to-speech/http.html#format).
267
+ # @param voice [String] The voice to use for synthesis.
268
+ # @param customization_id [String] The customization ID (GUID) of a custom voice model to use for the synthesis. If a
269
+ # custom voice model is specified, it is guaranteed to work only if it matches the
270
+ # language of the indicated voice. You must make the request with service
271
+ # credentials created for the instance of the service that owns the custom model.
272
+ # Omit the parameter to use the specified voice with no customization.
273
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
274
+ def synthesize(text:, accept: nil, voice: nil, customization_id: nil)
275
+ raise ArgumentError("text must be provided") if text.nil?
276
+ headers = {
277
+ "Accept" => accept
278
+ }
279
+ params = {
280
+ "voice" => voice,
281
+ "customization_id" => customization_id
282
+ }
283
+ data = {
284
+ "text" => text
285
+ }
286
+ method_url = "/v1/synthesize"
287
+ response = request(
288
+ method: "POST",
289
+ url: method_url,
290
+ headers: headers,
291
+ params: params,
292
+ json: data,
293
+ accept_json: false
294
+ )
295
+ response
296
+ end
297
+ #########################
298
+ # Pronunciation
299
+ #########################
300
+
301
+ ##
302
+ # @!method get_pronunciation(text:, voice: nil, format: nil, customization_id: nil)
303
+ # Get pronunciation.
304
+ # Gets the phonetic pronunciation for the specified word. You can request the
305
+ # pronunciation for a specific format. You can also request the pronunciation for a
306
+ # specific voice to see the default translation for the language of that voice or
307
+ # for a specific custom voice model to see the translation for that voice model.
308
+ #
309
+ # **Note:** This method is currently a beta release.
310
+ # @param text [String] The word for which the pronunciation is requested.
311
+ # @param voice [String] A voice that specifies the language in which the pronunciation is to be returned.
312
+ # All voices for the same language (for example, `en-US`) return the same
313
+ # translation.
314
+ # @param format [String] The phoneme format in which to return the pronunciation. Omit the parameter to
315
+ # obtain the pronunciation in the default format.
316
+ # @param customization_id [String] The customization ID (GUID) of a custom voice model for which the pronunciation is
317
+ # to be returned. The language of a specified custom model must match the language
318
+ # of the specified voice. If the word is not defined in the specified custom model,
319
+ # the service returns the default translation for the custom model's language. You
320
+ # must make the request with service credentials created for the instance of the
321
+ # service that owns the custom model. Omit the parameter to see the translation for
322
+ # the specified voice with no customization.
323
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
324
+ def get_pronunciation(text:, voice: nil, format: nil, customization_id: nil)
325
+ raise ArgumentError("text must be provided") if text.nil?
326
+ headers = {
327
+ }
328
+ params = {
329
+ "text" => text,
330
+ "voice" => voice,
331
+ "format" => format,
332
+ "customization_id" => customization_id
333
+ }
334
+ method_url = "/v1/pronunciation"
335
+ response = request(
336
+ method: "GET",
337
+ url: method_url,
338
+ headers: headers,
339
+ params: params,
340
+ accept_json: true
341
+ )
342
+ response
343
+ end
344
+ #########################
345
+ # Custom models
346
+ #########################
347
+
348
+ ##
349
+ # @!method create_voice_model(name:, language: nil, description: nil)
350
+ # Create a custom model.
351
+ # Creates a new empty custom voice model. You must specify a name for the new custom
352
+ # model. You can optionally specify the language and a description for the new
353
+ # model. The model is owned by the instance of the service whose credentials are
354
+ # used to create it.
355
+ #
356
+ # **Note:** This method is currently a beta release.
357
+ # @param name [String] The name of the new custom voice model.
358
+ # @param language [String] The language of the new custom voice model. Omit the parameter to use the the
359
+ # default language, `en-US`.
360
+ # @param description [String] A description of the new custom voice model. Specifying a description is
361
+ # recommended.
362
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
363
+ def create_voice_model(name:, language: nil, description: nil)
364
+ raise ArgumentError("name must be provided") if name.nil?
365
+ headers = {
366
+ }
367
+ data = {
368
+ "name" => name,
369
+ "language" => language,
370
+ "description" => description
371
+ }
372
+ method_url = "/v1/customizations"
373
+ response = request(
374
+ method: "POST",
375
+ url: method_url,
376
+ headers: headers,
377
+ json: data,
378
+ accept_json: true
379
+ )
380
+ response
381
+ end
382
+
383
+ ##
384
+ # @!method list_voice_models(language: nil)
385
+ # List custom models.
386
+ # Lists metadata such as the name and description for all custom voice models that
387
+ # are owned by an instance of the service. Specify a language to list the voice
388
+ # models for that language only. To see the words in addition to the metadata for a
389
+ # specific voice model, use the **List a custom model** method. You must use
390
+ # credentials for the instance of the service that owns a model to list information
391
+ # about it.
392
+ #
393
+ # **Note:** This method is currently a beta release.
394
+ # @param language [String] The language for which custom voice models that are owned by the requesting
395
+ # service credentials are to be returned. Omit the parameter to see all custom voice
396
+ # models that are owned by the requester.
397
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
398
+ def list_voice_models(language: nil)
399
+ headers = {
400
+ }
401
+ params = {
402
+ "language" => language
403
+ }
404
+ method_url = "/v1/customizations"
405
+ response = request(
406
+ method: "GET",
407
+ url: method_url,
408
+ headers: headers,
409
+ params: params,
410
+ accept_json: true
411
+ )
412
+ response
413
+ end
414
+
415
+ ##
416
+ # @!method update_voice_model(customization_id:, name: nil, description: nil, words: nil)
417
+ # Update a custom model.
418
+ # Updates information for the specified custom voice model. You can update metadata
419
+ # such as the name and description of the voice model. You can also update the words
420
+ # in the model and their translations. Adding a new translation for a word that
421
+ # already exists in a custom model overwrites the word's existing translation. A
422
+ # custom model can contain no more than 20,000 entries. You must use credentials for
423
+ # the instance of the service that owns a model to update it.
424
+ #
425
+ # **Note:** This method is currently a beta release.
426
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
427
+ # with service credentials created for the instance of the service that owns the
428
+ # custom model.
429
+ # @param name [String] A new name for the custom voice model.
430
+ # @param description [String] A new description for the custom voice model.
431
+ # @param words [Array[Word]] An array of `Word` objects that provides the words and their translations that are
432
+ # to be added or updated for the custom voice model. Pass an empty array to make no
433
+ # additions or updates.
434
+ # @return [nil]
435
+ def update_voice_model(customization_id:, name: nil, description: nil, words: nil)
436
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
437
+ headers = {
438
+ }
439
+ data = {
440
+ "name" => name,
441
+ "description" => description,
442
+ "words" => words
443
+ }
444
+ method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
445
+ request(
446
+ method: "POST",
447
+ url: method_url,
448
+ headers: headers,
449
+ json: data,
450
+ accept_json: true
451
+ )
452
+ nil
453
+ end
454
+
455
+ ##
456
+ # @!method get_voice_model(customization_id:)
457
+ # Get a custom model.
458
+ # Gets all information about a specified custom voice model. In addition to metadata
459
+ # such as the name and description of the voice model, the output includes the words
460
+ # and their translations as defined in the model. To see just the metadata for a
461
+ # voice model, use the **List custom models** method.
462
+ #
463
+ # **Note:** This method is currently a beta release.
464
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
465
+ # with service credentials created for the instance of the service that owns the
466
+ # custom model.
467
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
468
+ def get_voice_model(customization_id:)
469
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
470
+ headers = {
471
+ }
472
+ method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
473
+ response = request(
474
+ method: "GET",
475
+ url: method_url,
476
+ headers: headers,
477
+ accept_json: true
478
+ )
479
+ response
480
+ end
481
+
482
+ ##
483
+ # @!method delete_voice_model(customization_id:)
484
+ # Delete a custom model.
485
+ # Deletes the specified custom voice model. You must use credentials for the
486
+ # instance of the service that owns a model to delete it.
487
+ #
488
+ # **Note:** This method is currently a beta release.
489
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
490
+ # with service credentials created for the instance of the service that owns the
491
+ # custom model.
492
+ # @return [nil]
493
+ def delete_voice_model(customization_id:)
494
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
495
+ headers = {
496
+ }
497
+ method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
498
+ request(
499
+ method: "DELETE",
500
+ url: method_url,
501
+ headers: headers,
502
+ accept_json: true
503
+ )
504
+ nil
505
+ end
506
+ #########################
507
+ # Custom words
508
+ #########################
509
+
510
+ ##
511
+ # @!method add_words(customization_id:, words:)
512
+ # Add custom words.
513
+ # Adds one or more words and their translations to the specified custom voice model.
514
+ # Adding a new translation for a word that already exists in a custom model
515
+ # overwrites the word's existing translation. A custom model can contain no more
516
+ # than 20,000 entries. You must use credentials for the instance of the service that
517
+ # owns a model to add words to it.
518
+ #
519
+ # **Note:** This method is currently a beta release.
520
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
521
+ # with service credentials created for the instance of the service that owns the
522
+ # custom model.
523
+ # @param words [Array[Word]] The **Add custom words** method accepts an array of `Word` objects. Each object
524
+ # provides a word that is to be added or updated for the custom voice model and the
525
+ # word's translation.
526
+ #
527
+ # The **List custom words** method returns an array of `Word` objects. Each object
528
+ # shows a word and its translation from the custom voice model. The words are listed
529
+ # in alphabetical order, with uppercase letters listed before lowercase letters. The
530
+ # array is empty if the custom model contains no words.
531
+ # @return [nil]
532
+ def add_words(customization_id:, words:)
533
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
534
+ raise ArgumentError("words must be provided") if words.nil?
535
+ headers = {
536
+ }
537
+ data = {
538
+ "words" => words
539
+ }
540
+ method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)]
541
+ request(
542
+ method: "POST",
543
+ url: method_url,
544
+ headers: headers,
545
+ json: data,
546
+ accept_json: true
547
+ )
548
+ nil
549
+ end
550
+
551
+ ##
552
+ # @!method list_words(customization_id:)
553
+ # List custom words.
554
+ # Lists all of the words and their translations for the specified custom voice
555
+ # model. The output shows the translations as they are defined in the model. You
556
+ # must use credentials for the instance of the service that owns a model to list its
557
+ # words.
558
+ #
559
+ # **Note:** This method is currently a beta release.
560
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
561
+ # with service credentials created for the instance of the service that owns the
562
+ # custom model.
563
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
564
+ def list_words(customization_id:)
565
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
566
+ headers = {
567
+ }
568
+ method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)]
569
+ response = request(
570
+ method: "GET",
571
+ url: method_url,
572
+ headers: headers,
573
+ accept_json: true
574
+ )
575
+ response
576
+ end
577
+
578
+ ##
579
+ # @!method add_word(customization_id:, word:, translation:, part_of_speech: nil)
580
+ # Add a custom word.
581
+ # Adds a single word and its translation to the specified custom voice model. Adding
582
+ # a new translation for a word that already exists in a custom model overwrites the
583
+ # word's existing translation. A custom model can contain no more than 20,000
584
+ # entries. You must use credentials for the instance of the service that owns a
585
+ # model to add a word to it.
586
+ #
587
+ # **Note:** This method is currently a beta release.
588
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
589
+ # with service credentials created for the instance of the service that owns the
590
+ # custom model.
591
+ # @param word [String] The word that is to be added or updated for the custom voice model.
592
+ # @param translation [String] The phonetic or sounds-like translation for the word. A phonetic translation is
593
+ # based on the SSML format for representing the phonetic string of a word either as
594
+ # an IPA translation or as an IBM SPR translation. A sounds-like is one or more
595
+ # words that, when combined, sound like the word.
596
+ # @param part_of_speech [String] **Japanese only.** The part of speech for the word. The service uses the value to
597
+ # produce the correct intonation for the word. You can create only a single entry,
598
+ # with or without a single part of speech, for any word; you cannot create multiple
599
+ # entries with different parts of speech for the same word. For more information,
600
+ # see [Working with Japanese
601
+ # entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
602
+ # @return [nil]
603
+ def add_word(customization_id:, word:, translation:, part_of_speech: nil)
604
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
605
+ raise ArgumentError("word must be provided") if word.nil?
606
+ raise ArgumentError("translation must be provided") if translation.nil?
607
+ headers = {
608
+ }
609
+ data = {
610
+ "translation" => translation,
611
+ "part_of_speech" => part_of_speech
612
+ }
613
+ method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
614
+ request(
615
+ method: "PUT",
616
+ url: method_url,
617
+ headers: headers,
618
+ json: data,
619
+ accept_json: true
620
+ )
621
+ nil
622
+ end
623
+
624
+ ##
625
+ # @!method get_word(customization_id:, word:)
626
+ # Get a custom word.
627
+ # Gets the translation for a single word from the specified custom model. The output
628
+ # shows the translation as it is defined in the model. You must use credentials for
629
+ # the instance of the service that owns a model to list its words.
630
+ #
631
+ # **Note:** This method is currently a beta release.
632
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
633
+ # with service credentials created for the instance of the service that owns the
634
+ # custom model.
635
+ # @param word [String] The word that is to be queried from the custom voice model.
636
+ # @return [DetailedResponse] A `DetailedResponse` object representing the response.
637
+ def get_word(customization_id:, word:)
638
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
639
+ raise ArgumentError("word must be provided") if word.nil?
640
+ headers = {
641
+ }
642
+ method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
643
+ response = request(
644
+ method: "GET",
645
+ url: method_url,
646
+ headers: headers,
647
+ accept_json: true
648
+ )
649
+ response
650
+ end
651
+
652
+ ##
653
+ # @!method delete_word(customization_id:, word:)
654
+ # Delete a custom word.
655
+ # Deletes a single word from the specified custom voice model. You must use
656
+ # credentials for the instance of the service that owns a model to delete its words.
657
+ #
658
+ #
659
+ # **Note:** This method is currently a beta release.
660
+ # @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
661
+ # with service credentials created for the instance of the service that owns the
662
+ # custom model.
663
+ # @param word [String] The word that is to be deleted from the custom voice model.
664
+ # @return [nil]
665
+ def delete_word(customization_id:, word:)
666
+ raise ArgumentError("customization_id must be provided") if customization_id.nil?
667
+ raise ArgumentError("word must be provided") if word.nil?
668
+ headers = {
669
+ }
670
+ method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
671
+ request(
672
+ method: "DELETE",
673
+ url: method_url,
674
+ headers: headers,
675
+ accept_json: true
676
+ )
677
+ nil
678
+ end
679
+ #########################
680
+ # User data
681
+ #########################
682
+
683
+ ##
684
+ # @!method delete_user_data(customer_id:)
685
+ # Delete labeled data.
686
+ # Deletes all data that is associated with a specified customer ID. The method
687
+ # deletes all data for the customer ID, regardless of the method by which the
688
+ # information was added. The method has no effect if no data is associated with the
689
+ # customer ID. You must issue the request with credentials for the same instance of
690
+ # the service that was used to associate the customer ID with the data.
691
+ #
692
+ # You associate a customer ID with data by passing the `X-Watson-Metadata` header
693
+ # with a request that passes the data. For more information about customer IDs and
694
+ # about using this method, see [Information
695
+ # security](https://console.bluemix.net/docs/services/text-to-speech/information-security.html).
696
+ # @param customer_id [String] The customer ID for which all data is to be deleted.
697
+ # @return [nil]
698
+ def delete_user_data(customer_id:)
699
+ raise ArgumentError("customer_id must be provided") if customer_id.nil?
700
+ headers = {
701
+ }
702
+ params = {
703
+ "customer_id" => customer_id
704
+ }
705
+ method_url = "/v1/user_data"
706
+ request(
707
+ method: "DELETE",
708
+ url: method_url,
709
+ headers: headers,
710
+ params: params,
711
+ accept_json: true
712
+ )
713
+ nil
714
+ end
715
+ end
716
+ end