]> Repos - mime-chat/commitdiff
ws loop
authorAndrew Gundersen <gundersena@xavier.edu>
Mon, 1 Feb 2021 21:42:54 +0000 (15:42 -0600)
committerAndrew Gundersen <gundersena@xavier.edu>
Mon, 1 Feb 2021 21:42:54 +0000 (15:42 -0600)
ws.py

diff --git a/ws.py b/ws.py
index 57751f332b85abd29d2b71068fe17f508cd00e38..7dd80279535356016fe3e90d19bde4291e10f987 100644 (file)
--- a/ws.py
+++ b/ws.py
@@ -19,7 +19,9 @@ config = speech.RecognitionConfig(
 )
 
 streaming_config = speech.StreamingRecognitionConfig(config=config)
-def test(stream):
+
+def transcribe(stream):
+
     requests = (
         speech.StreamingRecognizeRequest(audio_content=chunk) for chunk in stream
     )
@@ -44,14 +46,22 @@ def test(stream):
                     print(u"Transcript: {}".format(alternative.transcript))
 
 
-stream = []
-async def hello(websocket, path):
-    chunk = await websocket.recv()
-    print(chunk)
 
+async def session(websocket, path):
+    buf = []
+
+    while True:
+        chunk = await websocket.recv()
+
+        if chunk == "stop":
+            break
+
+        buf.append(chunk)
+
+    transcribe(buf)
 
-start_server = websockets.serve(hello, "localhost", 8080)
 
+start_server = websockets.serve(session, "localhost", 8080)
 asyncio.get_event_loop().run_until_complete(start_server)
 asyncio.get_event_loop().run_forever()