We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug Speech to text is not working with websockets. Works fine with synchronous recognize.
To Reproduce Here is the code:
#!/usr/bin/env ruby require "ibm_watson/speech_to_text_v1" require "ibm_watson/websocket/recognize_callback" require "ibm_watson/authenticators" require "json" authenticator = IBMWatson::Authenticators::IamAuthenticator.new( apikey: ENV['API_KEY'] ) speech_to_text = IBMWatson::SpeechToTextV1.new( authenticator: authenticator ) speech_to_text.service_url = ENV['API_URL'] File.open(Dir.getwd + "/resources/speech.wav") do |audio_file| recognition = speech_to_text.recognize( audio: audio_file, content_type: "audio/wav", timestamps: true, word_confidence: true ).result puts JSON.pretty_generate(recognition) end # Example using websockets class MyRecognizeCallback < IBMWatson::RecognizeCallback def initialize super end def on_transcription(transcript:) puts JSON.pretty_generate(transcript) end def on_connected puts "Connection was successful" end def on_error(error:) puts "Error received: #{error}" puts "Error message: #{error.message}" end def on_inactivity_timeout(error:) puts "Inactivity timeout: #{error}" end def on_listening puts "Service is listening" end def on_transcription_complete puts "Transcription completed" end def on_hypothesis(hypothesis:) puts hypothesis.to_s end def on_data(data:) puts data.to_s end end mycallback = MyRecognizeCallback.new File.open(Dir.getwd + "/resources/speech.wav") do |audio_file| speech_to_text.recognize_using_websocket( audio: audio_file, recognize_callback: mycallback, content_type: "audio/wav" ).start end
Expected behavior I am expecting to see a successful connected message from the recognize callback.
Actual behavior
Error received: #<Faye::WebSocket::API::ErrorEvent:0x00000000029eaa28> Error message: Error during WebSocket handshake: Unexpected response code: 401
Desktop (please complete the following information):
Additional context By adding the authentication step before sending websocket request I was able to make it work:
diff --git a/lib/ibm_watson/speech_to_text_v1.rb b/lib/ibm_watson/speech_to_text_v1.rb index 7451924..ba3c20a 100644 --- a/lib/ibm_watson/speech_to_text_v1.rb +++ b/lib/ibm_watson/speech_to_text_v1.rb @@ -567,6 +567,7 @@ module IBMWatson require_relative("./websocket/speech_to_text_websocket_listener.rb") headers = {} + @authenticator.authenticate(headers) headers = conn.default_options.headers.to_hash unless conn.default_options.headers.to_hash.empty? service_url = @service_url.gsub("https:", "wss:") params = {
Thanks!
The text was updated successfully, but these errors were encountered:
Hi @pandrews11, thanks a lot for opening the issue, we will have the fix out soon.
Sorry, something went wrong.
Fixed in #94
Mikemosca
No branches or pull requests
Describe the bug
Speech to text is not working with websockets. Works fine with synchronous recognize.
To Reproduce
Here is the code:
Expected behavior
I am expecting to see a successful connected message from the recognize callback.
Actual behavior
Error received: #<Faye::WebSocket::API::ErrorEvent:0x00000000029eaa28> Error message: Error during WebSocket handshake: Unexpected response code: 401
Desktop (please complete the following information):
Additional context
By adding the authentication step before sending websocket request I was able to make it work:
Thanks!
The text was updated successfully, but these errors were encountered: