@@ -92,4 +92,87 @@ def recognize_with_websocket(
9292 options . delete_if { |_ , v | v . nil? }
9393 WebSocketClient . new ( audio : audio , chunk_data : chunk_data , options : options , recognize_callback : recognize_callback , url : url , headers : headers )
9494 end
95+
96+ ##
97+ # @!method add_word(customization_id:, word_name:, word: nil, sounds_like: nil, display_as: nil)
98+ # Add a custom word.
99+ # Adds a custom word to a custom language model. The service populates the words
100+ # resource for a custom model with out-of-vocabulary (OOV) words found in each
101+ # corpus added to the model. You can use this method to add a word or to modify an
102+ # existing word in the words resource. The words resource for a model can contain a
103+ # maximum of 30 thousand custom (OOV) words, including words that the service
104+ # extracts from corpora and words that you add directly.
105+ #
106+ # You must use credentials for the instance of the service that owns a model to add
107+ # or modify a custom word for the model. Adding or modifying a custom word does not
108+ # affect the custom model until you train the model for the new data by using the
109+ # **Train a custom language model** method.
110+ #
111+ # Use the `word_name` parameter to specify the custom word that is to be added or
112+ # modified. Use the `CustomWord` object to provide one or both of the optional
113+ # `sounds_like` and `display_as` fields for the word.
114+ # * The `sounds_like` field provides an array of one or more pronunciations for the
115+ # word. Use the parameter to specify how the word can be pronounced by users. Use
116+ # the parameter for words that are difficult to pronounce, foreign words, acronyms,
117+ # and so on. For example, you might specify that the word `IEEE` can sound like `i
118+ # triple e`. You can specify a maximum of five sounds-like pronunciations for a
119+ # word. For information about pronunciation rules, see [Using the sounds_like
120+ # field](https://console.bluemix.net/docs/services/speech-to-text/language-resource.html#soundsLike).
121+ # * The `display_as` field provides a different way of spelling the word in a
122+ # transcript. Use the parameter when you want the word to appear different from its
123+ # usual representation or from its spelling in corpora training data. For example,
124+ # you might indicate that the word `IBM(trademark)` is to be displayed as
125+ # `IBM™`. For more information, see [Using the display_as
126+ # field](https://console.bluemix.net/docs/services/speech-to-text/language-resource.html#displayAs).
127+ #
128+ #
129+ # If you add a custom word that already exists in the words resource for the custom
130+ # model, the new definition overwrites the existing data for the word. If the
131+ # service encounters an error, it does not add the word to the words resource. Use
132+ # the **List a custom word** method to review the word that you add.
133+ # @param customization_id [String] The customization ID (GUID) of the custom language model. You must make the
134+ # request with service credentials created for the instance of the service that owns
135+ # the custom model.
136+ # @param word_name [String] The custom word for the custom language model. When you add or update a custom
137+ # word with the **Add a custom word** method, do not include spaces in the word. Use
138+ # a `-` (dash) or `_` (underscore) to connect the tokens of compound words.
139+ # @param word [String] For the **Add custom words** method, you must specify the custom word that is to
140+ # be added to or updated in the custom model. Do not include spaces in the word. Use
141+ # a `-` (dash) or `_` (underscore) to connect the tokens of compound words.
142+ #
143+ # Omit this field for the **Add a custom word** method.
144+ # @param sounds_like [Array[String]] An array of sounds-like pronunciations for the custom word. Specify how words that
145+ # are difficult to pronounce, foreign words, acronyms, and so on can be pronounced
146+ # by users. For a word that is not in the service's base vocabulary, omit the
147+ # parameter to have the service automatically generate a sounds-like pronunciation
148+ # for the word. For a word that is in the service's base vocabulary, use the
149+ # parameter to specify additional pronunciations for the word. You cannot override
150+ # the default pronunciation of a word; pronunciations you add augment the
151+ # pronunciation from the base vocabulary. A word can have at most five sounds-like
152+ # pronunciations, and a pronunciation can include at most 40 characters not
153+ # including spaces.
154+ # @param display_as [String] An alternative spelling for the custom word when it appears in a transcript. Use
155+ # the parameter when you want the word to have a spelling that is different from its
156+ # usual representation or from its spelling in corpora training data.
157+ # @return [nil]
158+ def add_word ( customization_id :, word_name :, sounds_like : nil , display_as : nil )
159+ raise ArgumentError ( "customization_id must be provided" ) if customization_id . nil?
160+ raise ArgumentError ( "word_name must be provided" ) if word_name . nil?
161+ headers = {
162+ }
163+ data = {
164+ "word" => word_name ,
165+ "sounds_like" => sounds_like ,
166+ "display_as" => display_as
167+ }
168+ method_url = "/v1/customizations/%s/words/%s" % [ ERB ::Util . url_encode ( customization_id ) , ERB ::Util . url_encode ( word_name ) ]
169+ request (
170+ method : "PUT" ,
171+ url : method_url ,
172+ headers : headers ,
173+ json : data ,
174+ accept_json : true
175+ )
176+ nil
177+ end
95178end
0 commit comments