{"action":"created","comment":{"url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/comments/171452838","pull_request_review_id":100302296,"id":171452838,"diff_hunk":"@@ -0,0 +1,174 @@\n+# coding: utf-8\n+\n+# Copyright 2018 IBM All Rights Reserved.\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#      http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+import sys\n+import os\n+import json\n+\n+# WebSockets\n+from autobahn.twisted.websocket import WebSocketClientProtocol, WebSocketClientFactory, connectWS\n+from twisted.python import log\n+from twisted.internet import ssl, reactor\n+\n+\n+class RecognizeListener:\n+    def __init__(self, audio, options, recognize_callback, url, headers):\n+        self.audio = audio\n+        self.options = options\n+        self.callback = recognize_callback\n+        self.url = url\n+        self.headers = headers\n+\n+        factory = self.WebSocketClientFactory(self.audio, self.options,\n+                                          self.callback, self.url, self.headers)\n+        factory.protocol = self.WebSocketClient\n+\n+        if factory.isSecure:\n+            contextFactory = ssl.ClientContextFactory()\n+        else:\n+            contextFactory = None\n+        connectWS(factory, contextFactory)\n+\n+        reactor.run()\n+\n+    class WebSocketClient(WebSocketClientProtocol):\n+        def __init__(self, factory, audio, options, callback):\n+            self.factory = factory\n+            self.audio = audio\n+            self.options = options\n+            self.callback = callback\n+            self.isListening = False\n+            self.bytes_sent = 0\n+            self.ONE_KB = 1000  # in bytes","path":"watson_developer_cloud/websocket/speech_to_text_websocket_listener.py","position":55,"original_position":55,"commit_id":"cc2e7f92d84f70a67eff1e4f762cd4baacd441e7","original_commit_id":"cc2e7f92d84f70a67eff1e4f762cd4baacd441e7","user":{"login":"germanattanasio","id":313157,"avatar_url":"https://avatars3.githubusercontent.com/u/313157?v=4","gravatar_id":"","url":"https://api.github.com/users/germanattanasio","html_url":"https://github.com/germanattanasio","followers_url":"https://api.github.com/users/germanattanasio/followers","following_url":"https://api.github.com/users/germanattanasio/following{/other_user}","gists_url":"https://api.github.com/users/germanattanasio/gists{/gist_id}","starred_url":"https://api.github.com/users/germanattanasio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/germanattanasio/subscriptions","organizations_url":"https://api.github.com/users/germanattanasio/orgs","repos_url":"https://api.github.com/users/germanattanasio/repos","events_url":"https://api.github.com/users/germanattanasio/events{/privacy}","received_events_url":"https://api.github.com/users/germanattanasio/received_events","type":"User","site_admin":false},"body":"Use constants not class variables.","created_at":"2018-03-01T03:06:13Z","updated_at":"2018-03-01T03:12:25Z","html_url":"https://github.com/watson-developer-cloud/python-sdk/pull/376#discussion_r171452838","pull_request_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/comments/171452838"},"html":{"href":"https://github.com/watson-developer-cloud/python-sdk/pull/376#discussion_r171452838"},"pull_request":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376"}}},"pull_request":{"url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376","id":170931544,"html_url":"https://github.com/watson-developer-cloud/python-sdk/pull/376","diff_url":"https://github.com/watson-developer-cloud/python-sdk/pull/376.diff","patch_url":"https://github.com/watson-developer-cloud/python-sdk/pull/376.patch","issue_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/376","number":376,"state":"open","locked":false,"title":"Speech to Text using web sockets ","user":{"login":"ehdsouza","id":13935994,"avatar_url":"https://avatars2.githubusercontent.com/u/13935994?v=4","gravatar_id":"","url":"https://api.github.com/users/ehdsouza","html_url":"https://github.com/ehdsouza","followers_url":"https://api.github.com/users/ehdsouza/followers","following_url":"https://api.github.com/users/ehdsouza/following{/other_user}","gists_url":"https://api.github.com/users/ehdsouza/gists{/gist_id}","starred_url":"https://api.github.com/users/ehdsouza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ehdsouza/subscriptions","organizations_url":"https://api.github.com/users/ehdsouza/orgs","repos_url":"https://api.github.com/users/ehdsouza/repos","events_url":"https://api.github.com/users/ehdsouza/events{/privacy}","received_events_url":"https://api.github.com/users/ehdsouza/received_events","type":"User","site_admin":false},"body":"It takes in an audio file and outputs interim results, hypothesis based on what the listener is interested in.\r\n\r\nFollowing is the implementation details:\r\n* Pass in a callback instance of type `RecognizeAbstractCallback` \r\n* In onOpen, it passed it the open action and options\r\n* In onMessage, the appropriate callbacks are called.\r\n* When the end of the audio is reached, a close action is sent and the reactor is closed which terminates the session\r\n\r\nTested on python 2.7 and 3.6.4\r\nWritten an example which works successfully\r\n```\r\nclass MyRecognizeCallback(RecognizeAbstractCallback):\r\n    def __init__(self):\r\n        pass\r\n\r\n    def on_transcription(self, transcript):\r\n        print(transcript)\r\n\r\n    def on_connected(self):\r\n        print('Connection was successful')\r\n\r\n    def on_error(self):\r\n        print('Error received: {}'.format(error))\r\n\r\n    def on_inactivity_timeout(self):\r\n        print('Timeout!')\r\n\r\n    def on_listening(self):\r\n        print('Service is listening')\r\n\r\n    def on_transcription_complete(self):\r\n        print('Transcription completed')\r\n\r\n    def on_hypothesis(self, hypothesis):\r\n        print(hypothesis)\r\n\r\nmycallback = MyRecognizeCallback()\r\nwith open(join(dirname(__file__), '../resources/speech.wav'),\r\n          'rb') as audio_file:\r\n    speech_to_text.recognize_with_websocket(\r\n        audio=audio_file, recognize_callback=mycallback)\r\n```","created_at":"2018-02-23T04:41:41Z","updated_at":"2018-03-01T03:12:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6f19cf1d23966fb9312b587be7049092742c357","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":270568019,"url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/labels/Ready%20for%20review","name":"Ready for review","color":"cc317c","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376/commits","review_comments_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376/comments","review_comment_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/376/comments","statuses_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/statuses/cc2e7f92d84f70a67eff1e4f762cd4baacd441e7","head":{"label":"watson-developer-cloud:stt-web-sockets","ref":"stt-web-sockets","sha":"cc2e7f92d84f70a67eff1e4f762cd4baacd441e7","user":{"login":"watson-developer-cloud","id":10017763,"avatar_url":"https://avatars2.githubusercontent.com/u/10017763?v=4","gravatar_id":"","url":"https://api.github.com/users/watson-developer-cloud","html_url":"https://github.com/watson-developer-cloud","followers_url":"https://api.github.com/users/watson-developer-cloud/followers","following_url":"https://api.github.com/users/watson-developer-cloud/following{/other_user}","gists_url":"https://api.github.com/users/watson-developer-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/watson-developer-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watson-developer-cloud/subscriptions","organizations_url":"https://api.github.com/users/watson-developer-cloud/orgs","repos_url":"https://api.github.com/users/watson-developer-cloud/repos","events_url":"https://api.github.com/users/watson-developer-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/watson-developer-cloud/received_events","type":"Organization","site_admin":false},"repo":{"id":42750248,"name":"python-sdk","full_name":"watson-developer-cloud/python-sdk","owner":{"login":"watson-developer-cloud","id":10017763,"avatar_url":"https://avatars2.githubusercontent.com/u/10017763?v=4","gravatar_id":"","url":"https://api.github.com/users/watson-developer-cloud","html_url":"https://github.com/watson-developer-cloud","followers_url":"https://api.github.com/users/watson-developer-cloud/followers","following_url":"https://api.github.com/users/watson-developer-cloud/following{/other_user}","gists_url":"https://api.github.com/users/watson-developer-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/watson-developer-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watson-developer-cloud/subscriptions","organizations_url":"https://api.github.com/users/watson-developer-cloud/orgs","repos_url":"https://api.github.com/users/watson-developer-cloud/repos","events_url":"https://api.github.com/users/watson-developer-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/watson-developer-cloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/watson-developer-cloud/python-sdk","description":":snake: Client library to use the IBM Watson services in Python and available in pip as watson-developer-cloud","fork":false,"url":"https://api.github.com/repos/watson-developer-cloud/python-sdk","forks_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/forks","keys_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/teams","hooks_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/hooks","issue_events_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/events","assignees_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/tags","blobs_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/languages","stargazers_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/stargazers","contributors_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/contributors","subscribers_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/subscribers","subscription_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/subscription","commits_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/merges","archive_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/downloads","issues_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/labels{/name}","releases_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/deployments","created_at":"2015-09-18T22:39:00Z","updated_at":"2018-02-28T12:38:02Z","pushed_at":"2018-02-27T20:11:18Z","git_url":"git://github.com/watson-developer-cloud/python-sdk.git","ssh_url":"git@github.com:watson-developer-cloud/python-sdk.git","clone_url":"https://github.com/watson-developer-cloud/python-sdk.git","svn_url":"https://github.com/watson-developer-cloud/python-sdk","homepage":"https://pypi.python.org/pypi/watson-developer-cloud","size":8145,"stargazers_count":803,"watchers_count":803,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":480,"mirror_url":null,"archived":false,"open_issues_count":10,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":480,"open_issues":10,"watchers":803,"default_branch":"develop"}},"base":{"label":"watson-developer-cloud:next","ref":"next","sha":"8dfc0f9492a23f3c69698e16fe4df18daa93a20d","user":{"login":"watson-developer-cloud","id":10017763,"avatar_url":"https://avatars2.githubusercontent.com/u/10017763?v=4","gravatar_id":"","url":"https://api.github.com/users/watson-developer-cloud","html_url":"https://github.com/watson-developer-cloud","followers_url":"https://api.github.com/users/watson-developer-cloud/followers","following_url":"https://api.github.com/users/watson-developer-cloud/following{/other_user}","gists_url":"https://api.github.com/users/watson-developer-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/watson-developer-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watson-developer-cloud/subscriptions","organizations_url":"https://api.github.com/users/watson-developer-cloud/orgs","repos_url":"https://api.github.com/users/watson-developer-cloud/repos","events_url":"https://api.github.com/users/watson-developer-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/watson-developer-cloud/received_events","type":"Organization","site_admin":false},"repo":{"id":42750248,"name":"python-sdk","full_name":"watson-developer-cloud/python-sdk","owner":{"login":"watson-developer-cloud","id":10017763,"avatar_url":"https://avatars2.githubusercontent.com/u/10017763?v=4","gravatar_id":"","url":"https://api.github.com/users/watson-developer-cloud","html_url":"https://github.com/watson-developer-cloud","followers_url":"https://api.github.com/users/watson-developer-cloud/followers","following_url":"https://api.github.com/users/watson-developer-cloud/following{/other_user}","gists_url":"https://api.github.com/users/watson-developer-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/watson-developer-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watson-developer-cloud/subscriptions","organizations_url":"https://api.github.com/users/watson-developer-cloud/orgs","repos_url":"https://api.github.com/users/watson-developer-cloud/repos","events_url":"https://api.github.com/users/watson-developer-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/watson-developer-cloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/watson-developer-cloud/python-sdk","description":":snake: Client library to use the IBM Watson services in Python and available in pip as watson-developer-cloud","fork":false,"url":"https://api.github.com/repos/watson-developer-cloud/python-sdk","forks_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/forks","keys_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/teams","hooks_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/hooks","issue_events_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/events","assignees_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/tags","blobs_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/languages","stargazers_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/stargazers","contributors_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/contributors","subscribers_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/subscribers","subscription_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/subscription","commits_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/merges","archive_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/downloads","issues_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/labels{/name}","releases_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/watson-developer-cloud/python-sdk/deployments","created_at":"2015-09-18T22:39:00Z","updated_at":"2018-02-28T12:38:02Z","pushed_at":"2018-02-27T20:11:18Z","git_url":"git://github.com/watson-developer-cloud/python-sdk.git","ssh_url":"git@github.com:watson-developer-cloud/python-sdk.git","clone_url":"https://github.com/watson-developer-cloud/python-sdk.git","svn_url":"https://github.com/watson-developer-cloud/python-sdk","homepage":"https://pypi.python.org/pypi/watson-developer-cloud","size":8145,"stargazers_count":803,"watchers_count":803,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":480,"mirror_url":null,"archived":false,"open_issues_count":10,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":480,"open_issues":10,"watchers":803,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376"},"html":{"href":"https://github.com/watson-developer-cloud/python-sdk/pull/376"},"issue":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/376"},"comments":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/issues/376/comments"},"review_comments":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376/comments"},"review_comment":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/pulls/376/commits"},"statuses":{"href":"https://api.github.com/repos/watson-developer-cloud/python-sdk/statuses/cc2e7f92d84f70a67eff1e4f762cd4baacd441e7"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"germanattanasio"}}