Skip to content

Commit 37a688a

Browse files
committed
chore(doc): Update readme and other chores
1 parent 4fae7d4 commit 37a688a

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Build Status](https://travis-ci.org/watson-developer-cloud/python-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/python-sdk)
44
[![Slack](https://wdc-slack-inviter.mybluemix.net/badge.svg)](https://wdc-slack-inviter.mybluemix.net)
5-
[![codecov.io](https://codecov.io/github/watson-developer-cloud/python-sdk/coverage.svg?branch=master)](https://codecov.io/github/watson-developer-cloud/python-sdk?branch=master)
65
[![Latest Stable Version](https://img.shields.io/pypi/v/watson-developer-cloud.svg)](https://pypi.python.org/pypi/watson-developer-cloud)
76
[![CLA assistant](https://cla-assistant.io/readme/badge/watson-developer-cloud/python-sdk)](https://cla-assistant.io/watson-developer-cloud/python-sdk)
87

@@ -251,6 +250,30 @@ This would give an output of `DetailedResponse` having the structure:
251250
```
252251
You can use the `get_result()`, `get_headers()` and get_status_code() to return the result, headers and status code respectively.
253252

253+
## Using Websockets
254+
The Text to Speech service supports synthesizing text to spoken audio using web sockets with the `synthesize_using_websocket`. The Speech to Text service supports recognizing speech to text using web sockets with the `recognize_using_websocket`. These methods need a custom callback class to listen to events. Below is an example of `synthesize_using_websocket`.
255+
256+
```py
257+
from watson_developer_cloud.websocket import SynthesizeCallback
258+
259+
class MySynthesizeCallback(SynthesizeCallback):
260+
def __init__(self):
261+
SynthesizeCallback.__init__(self)
262+
263+
def on_audio_stream(self, audio_stream):
264+
return audio_stream
265+
266+
def on_data(self, data):
267+
return data
268+
269+
my_callback = MySynthesizeCallback()
270+
service.synthesize_using_websocket("I like to pet dogs",
271+
my_callback,
272+
accept='audio/wav',
273+
voice="en-US_AllisonVoice"
274+
)
275+
```
276+
254277
## Dependencies
255278

256279
* [requests]

examples/speaker_text_to_speech.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# You need to install pyaudio to run this example
22
# pip install pyaudio
33

4-
# In this example, the a websocket connection is opened with a text
4+
# In this example, the websocket connection is opened with a text
55
# passed in the request. When the service responds with the synthesized
66
# audio, the pyaudio would play it in a blocking mode
77

@@ -82,7 +82,7 @@ def on_close(self):
8282
print 'Completed synthesizing'
8383
self.play.complete_playing()
8484

85-
testCallback = MySynthesizeCallback()
85+
test_callback = MySynthesizeCallback()
8686

8787
# An example SSML text
8888
SSML_sorry_text = """<speak version=\"1.0\">
@@ -108,7 +108,7 @@ def on_close(self):
108108
</speak>"""
109109

110110
service.synthesize_using_websocket(SSML_text,
111-
testCallback,
111+
test_callback,
112112
accept='audio/wav',
113113
voice="en-US_AllisonVoice"
114114
)

examples/text_to_speech_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def on_close(self):
9191
self.fd.close()
9292
print("Done synthesizing. Closing the connection")
9393

94-
myCallback = MySynthesizeCallback()
94+
my_callback = MySynthesizeCallback()
9595
service.synthesize_using_websocket("I like to pet dogs",
96-
myCallback,
96+
my_callback,
9797
accept='audio/wav',
9898
voice="en-US_AllisonVoice"
9999
)

test/integration/test_speech_to_text_v1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ def on_error(self, error):
9797
def on_transcription(self, transcript):
9898
self.transcript = transcript
9999

100-
testCallback = MyRecognizeCallback()
100+
test_callback = MyRecognizeCallback()
101101
with open(os.path.join(os.path.dirname(__file__), '../../resources/speech.wav'), 'rb') as audio_file:
102102
audio_source = AudioSource(audio_file, False)
103-
t = threading.Thread(target=self.speech_to_text.recognize_using_websocket, args=(audio_source, "audio/l16; rate=44100", testCallback))
103+
t = threading.Thread(target=self.speech_to_text.recognize_using_websocket, args=(audio_source, "audio/l16; rate=44100", test_callback))
104104
t.start()
105105
t.join()
106-
assert testCallback.error is None
107-
assert testCallback.transcript is not None
108-
assert testCallback.transcript[0]['transcript'] == 'thunderstorms could produce large hail isolated tornadoes and heavy rain '
106+
assert test_callback.error is None
107+
assert test_callback.transcript is not None
108+
assert test_callback.transcript[0]['transcript'] == 'thunderstorms could produce large hail isolated tornadoes and heavy rain '

test/integration/test_text_to_speech_v1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ def on_audio_stream(self, audio_stream):
8989
def on_close(self):
9090
self.fd.close()
9191

92-
testCallback = MySynthesizeCallback()
92+
test_callback = MySynthesizeCallback()
9393
self.text_to_speech.synthesize_using_websocket("She sells seashells by the seashore",
94-
testCallback,
94+
test_callback,
9595
accept='audio/wav',
9696
voice="en-GB_KateVoice"
9797
)
98-
assert testCallback.error is None
99-
assert testCallback.fd is not None
98+
assert test_callback.error is None
99+
assert test_callback.fd is not None
100100
assert os.stat(file).st_size > 0
101101
os.remove(file)

0 commit comments

Comments
 (0)