ibm_watson 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ibm_watson/speech_to_text_v1.rb +1 -1
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +8 -2
- data/test/integration/test_speech_to_text_v1.rb +4 -2
- data/test/unit/test_configure_http_client.rb +1 -1
- data/test/unit/test_speech_to_text_v1.rb +31 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cc1b9f91b2361fcc08435b17ed79e5f7b969e31471fefa78150253b4f1bac00
|
4
|
+
data.tar.gz: 5f56854edbe1136ba2211bb921efeb640646a38d56f751461c45ae75cd09b7a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb694116948f8db7a8419428f4b81e2d5ed9244214f6ce336e447fdf0ffe1bfd699cc29e81d1b611aae217961abca06373b53ec133441ad995edbb98522d6097
|
7
|
+
data.tar.gz: 9100b72cb2b7c7f64948e4a99b0a36f9f8c7e44671a1ee5915121274af995eb97eafcb54abaa845db1dbd94756bfb33f3611fae369e3c3b3e0cfa86000ce4144
|
@@ -533,7 +533,7 @@ module IBMWatson
|
|
533
533
|
"redaction" => redaction
|
534
534
|
}
|
535
535
|
options.delete_if { |_, v| v.nil? }
|
536
|
-
WebSocketClient.new(audio: audio, chunk_data: chunk_data, options: options, recognize_callback: recognize_callback, url: url, headers: headers)
|
536
|
+
WebSocketClient.new(audio: audio, chunk_data: chunk_data, options: options, recognize_callback: recognize_callback, url: url, headers: headers, disable_ssl_verification: @disable_ssl_verification)
|
537
537
|
end
|
538
538
|
|
539
539
|
# :nocov:
|
data/lib/ibm_watson/version.rb
CHANGED
@@ -11,7 +11,7 @@ TEN_MILLISECONDS = 0.01
|
|
11
11
|
|
12
12
|
# Class for interacting with the WebSocket API
|
13
13
|
class WebSocketClient
|
14
|
-
def initialize(audio: nil, chunk_data:, options:, recognize_callback:, url:, headers:)
|
14
|
+
def initialize(audio: nil, chunk_data:, options:, recognize_callback:, url:, headers:, disable_ssl_verification: false)
|
15
15
|
@audio = audio
|
16
16
|
@options = options
|
17
17
|
@callback = recognize_callback
|
@@ -24,6 +24,7 @@ class WebSocketClient
|
|
24
24
|
@mic_running = false
|
25
25
|
@data_size = audio.nil? ? 0 : @audio.size
|
26
26
|
@queue = Queue.new
|
27
|
+
@disable_ssl_verification = disable_ssl_verification
|
27
28
|
end
|
28
29
|
|
29
30
|
def start
|
@@ -77,7 +78,12 @@ class WebSocketClient
|
|
77
78
|
|
78
79
|
EM&.reactor_thread&.join
|
79
80
|
EM.run do
|
80
|
-
|
81
|
+
if @disable_ssl_verification
|
82
|
+
@url = @url.sub("wss:", "ws:")
|
83
|
+
@client = Faye::WebSocket::Client.new(@url, nil, tls: { verify_peer: false, fail_if_no_peer_cert: false }, headers: @headers)
|
84
|
+
else
|
85
|
+
@client = Faye::WebSocket::Client.new(@url, nil, headers: @headers)
|
86
|
+
end
|
81
87
|
@client.onclose = on_close
|
82
88
|
@client.onerror = on_error
|
83
89
|
@client.onmessage = on_message
|
@@ -162,7 +162,8 @@ if !ENV["SPEECH_TO_TEXT_APIKEY"].nil? && !ENV["SPEECH_TO_TEXT_URL"].nil?
|
|
162
162
|
|
163
163
|
def test_recognize_websocket_as_chunks
|
164
164
|
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
165
|
-
|
165
|
+
atomic_boolean = Concurrent::AtomicBoolean.new
|
166
|
+
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
|
166
167
|
speech = @service.recognize_using_websocket(
|
167
168
|
chunk_data: true,
|
168
169
|
recognize_callback: mycallback,
|
@@ -186,7 +187,8 @@ if !ENV["SPEECH_TO_TEXT_APIKEY"].nil? && !ENV["SPEECH_TO_TEXT_URL"].nil?
|
|
186
187
|
|
187
188
|
def test_recognize_websocket
|
188
189
|
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
189
|
-
|
190
|
+
atomic_boolean = Concurrent::AtomicBoolean.new
|
191
|
+
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
|
190
192
|
speech = @service.recognize_using_websocket(
|
191
193
|
audio: audio_file,
|
192
194
|
recognize_callback: mycallback,
|
@@ -140,7 +140,7 @@ class HTTPConfigTest < Minitest::Test
|
|
140
140
|
assert_equal(expected_timeouts, timeout)
|
141
141
|
end
|
142
142
|
|
143
|
-
def
|
143
|
+
def test_disable_ssl_verification
|
144
144
|
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
145
145
|
version: "2018-03-16",
|
146
146
|
username: "username",
|
@@ -89,6 +89,37 @@ class SpeechToTextV1Test < Minitest::Test
|
|
89
89
|
refute_nil(service_response)
|
90
90
|
end
|
91
91
|
|
92
|
+
def test_recognize_using_websocket_disable_ssl_verification
|
93
|
+
service = IBMWatson::SpeechToTextV1.new(
|
94
|
+
username: "username",
|
95
|
+
password: "password"
|
96
|
+
)
|
97
|
+
|
98
|
+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
|
99
|
+
stub_request(:post, "ws://stream.watsonplatform.net/speech-to-text/api/v1/recognize")
|
100
|
+
.with(
|
101
|
+
headers: {
|
102
|
+
"Accept" => "application/json",
|
103
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
104
|
+
"Content-Type" => "audio/l16; rate=44100",
|
105
|
+
"Host" => "stream.watsonplatform.net"
|
106
|
+
}
|
107
|
+
).to_return(status: 200, body: "", headers: { "Content-Type" => "application/json" })
|
108
|
+
|
109
|
+
atomic_boolean = Concurrent::AtomicBoolean.new
|
110
|
+
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
|
111
|
+
service.configure_http_client(disable_ssl_verification: true)
|
112
|
+
speech = service.recognize_using_websocket(
|
113
|
+
audio: audio_file,
|
114
|
+
recognize_callback: mycallback,
|
115
|
+
inactivity_timeout: 1,
|
116
|
+
content_type: "audio/l16; rate=44100"
|
117
|
+
)
|
118
|
+
thr = Thread.new { speech.start }
|
119
|
+
thr.join
|
120
|
+
assert(atomic_boolean.true?)
|
121
|
+
end
|
122
|
+
|
92
123
|
def test_get_model
|
93
124
|
service = IBMWatson::SpeechToTextV1.new(
|
94
125
|
username: "username",
|