Skip to content

Commit e151e82

Browse files
fix(tts): remove origin header from websocket request
1 parent b9b7d8a commit e151e82

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

ibm_watson/websocket/synthesize_listener.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self,
5757

5858
self.ws_client.run_forever(http_proxy_host=self.http_proxy_host,
5959
http_proxy_port=self.http_proxy_port,
60+
suppress_origin=True,
6061
sslopt={'cert_reqs': ssl.CERT_NONE}
6162
if self.verify is not None else None)
6263

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Sphinx==3.5.2
1717
bumpversion==0.6.0
1818

1919
# Web sockets
20-
websocket-client==0.48.0
20+
websocket-client==1.1.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
requests>=2.0,<3.0
22
python_dateutil>=2.5.3
3-
websocket-client==0.48.0
3+
websocket-client==1.1.0
44
ibm_cloud_sdk_core>=3.3.6, == 3.*

test/integration/test_text_to_speech_v1.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,38 @@ def on_close(self):
133133
assert test_callback.fd is not None
134134
assert os.stat(file).st_size > 0
135135
os.remove(file)
136+
137+
# This is test will only be meaningful so long as en-AU_CraigVoice is a Neural type voice model
138+
# Check this url for all Neutral type voice models: https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices#languageVoices
139+
def test_synthesize_using_websocket_neural(self):
140+
file = 'tongue_twister.wav'
141+
142+
class MySynthesizeCallback(SynthesizeCallback):
143+
144+
def __init__(self):
145+
SynthesizeCallback.__init__(self)
146+
self.fd = None
147+
self.error = None
148+
149+
def on_connected(self):
150+
self.fd = open(file, 'ab')
151+
152+
def on_error(self, error):
153+
self.error = error
154+
155+
def on_audio_stream(self, audio_stream):
156+
self.fd.write(audio_stream)
157+
158+
def on_close(self):
159+
self.fd.close()
160+
161+
test_callback = MySynthesizeCallback()
162+
self.text_to_speech.synthesize_using_websocket(
163+
'She sells seashells by the seashore',
164+
test_callback,
165+
accept='audio/wav',
166+
voice='en-AU_CraigVoice')
167+
assert test_callback.error is None
168+
assert test_callback.fd is not None
169+
assert os.stat(file).st_size > 0
170+
os.remove(file)

0 commit comments

Comments
 (0)