7474
7575require_relative  "./watson_service" 
7676
77+ # Module for the Watson APIs 
7778module  IBMWatson 
7879  ## 
7980  # The Speech to Text V1 service. 
@@ -408,6 +409,7 @@ def recognize(audio:, content_type:, model: nil, customization_id: nil, acoustic
408409      response 
409410    end 
410411
412+     ## 
411413    # @!method recognize_with_websocket(audio: nil,chunk_data: false,content_type: "audio/l16; rate=44100",model: "en-US_BroadbandModel",recognize_callback: nil,customization_id: nil,acoustic_customization_id: nil,customization_weight: nil,version: nil,inactivity_timeout: 30,interim_results: false,keywords: nil,keywords_threshold: nil,max_alternatives: 1,word_alternatives_threshold: nil,word_confidence: false,timestamps: false,profanity_filter: nil,smart_formatting: false,speaker_labels: nil) 
412414    # Sends audio for speech recognition using web sockets. 
413415    # @param audio [IO] Audio to transcribe in the format specified by the `Content-Type` header. 
@@ -455,13 +457,16 @@ def recognize_with_websocket(
455457    ) 
456458      raise  ArgumentError ( "Audio must be provided" )  if  audio . nil?  && !chunk_data 
457459      raise  ArgumentError ( "Recognize callback must be provided" )  if  recognize_callback . nil? 
458-       raise  TypeError ( "Callback is not a derived class of RecognizeCallback" )  unless  recognize_callback . is_a? ( RecognizeCallback ) 
459- 
460+       raise  TypeError ( "Callback is not a derived class of RecognizeCallback" )  unless  recognize_callback . is_a? ( IBMWatson ::RecognizeCallback ) 
460461      require_relative ( "./websocket/speech_to_text_websocket_listener.rb" ) 
461- 
462462      headers  =  { } 
463463      headers  =  @watson_service . conn . default_options . headers . to_hash  unless  @watson_service . conn . default_options . headers . to_hash . empty? 
464-       headers [ "Authorization" ]  =  "Basic "  + Base64 . strict_encode64 ( "#{ @watson_service . username } #{ @watson_service . password }  ) 
464+       if  !@watson_service . token_manager . nil? 
465+         access_token  =  @watson_service . token_manager . _token 
466+         headers [ "Authorization" ]  =  "Bearer #{ access_token }  
467+       elsif  !@watson_service . username . nil?  && !@watson_service . password . nil? 
468+         headers [ "Authorization" ]  =  "Basic "  + Base64 . strict_encode64 ( "#{ @watson_service . username } #{ @watson_service . password }  ) 
469+       end 
465470      url  =  @watson_service . url . gsub ( "https:" ,  "wss:" ) 
466471      params  =  { 
467472        "model"  =>  model , 
@@ -472,7 +477,6 @@ def recognize_with_websocket(
472477      } 
473478      params . delete_if  {  |_ ,  v | v . nil?  } 
474479      url  += "/v1/recognize?"  + HTTP ::URI . form_encode ( params ) 
475- 
476480      options  =  { 
477481        "content_type"  =>  content_type , 
478482        "inactivity_timeout"  =>  inactivity_timeout , 
@@ -490,7 +494,6 @@ def recognize_with_websocket(
490494      options . delete_if  {  |_ ,  v | v . nil?  } 
491495      WebSocketClient . new ( audio : audio ,  chunk_data : chunk_data ,  options : options ,  recognize_callback : recognize_callback ,  url : url ,  headers : headers ) 
492496    end 
493- 
494497    ######################### 
495498    # Asynchronous 
496499    ######################### 
@@ -1467,7 +1470,7 @@ def add_words(customization_id:, words:)
14671470    end 
14681471
14691472    ## 
1470-     # @!method add_word(customization_id:, word_name:, word: nil,  sounds_like: nil, display_as: nil) 
1473+     # @!method add_word(customization_id:, word_name:, sounds_like: nil, display_as: nil) 
14711474    # Add a custom word. 
14721475    # Adds a custom word to a custom language model. The service populates the words 
14731476    #   resource for a custom model with out-of-vocabulary (OOV) words found in each 
@@ -1509,11 +1512,6 @@ def add_words(customization_id:, words:)
15091512    # @param word_name [String] The custom word for the custom language model. When you add or update a custom 
15101513    #   word with the **Add a custom word** method, do not include spaces in the word. Use 
15111514    #   a `-` (dash) or `_` (underscore) to connect the tokens of compound words. 
1512-     # @param word [String] For the **Add custom words** method, you must specify the custom word that is to 
1513-     #   be added to or updated in the custom model. Do not include spaces in the word. Use 
1514-     #   a `-` (dash) or `_` (underscore) to connect the tokens of compound words. 
1515-     # 
1516-     #   Omit this field for the **Add a custom word** method. 
15171515    # @param sounds_like [Array[String]] An array of sounds-like pronunciations for the custom word. Specify how words that 
15181516    #   are difficult to pronounce, foreign words, acronyms, and so on can be pronounced 
15191517    #   by users. For a word that is not in the service's base vocabulary, omit the 
@@ -1528,13 +1526,13 @@ def add_words(customization_id:, words:)
15281526    #   the parameter when you want the word to have a spelling that is different from its 
15291527    #   usual representation or from its spelling in corpora training data. 
15301528    # @return [nil] 
1531-     def  add_word ( customization_id :,  word_name :,  word :  nil ,   sounds_like : nil ,  display_as : nil ) 
1529+     def  add_word ( customization_id :,  word_name :,  sounds_like : nil ,  display_as : nil ) 
15321530      raise  ArgumentError ( "customization_id must be provided" )  if  customization_id . nil? 
15331531      raise  ArgumentError ( "word_name must be provided" )  if  word_name . nil? 
15341532      headers  =  { 
15351533      } 
15361534      data  =  { 
1537-         "word"  =>  word , 
1535+         "word"  =>  word_name , 
15381536        "sounds_like"  =>  sounds_like , 
15391537        "display_as"  =>  display_as 
15401538      } 
0 commit comments