)
streaming_config = speech.StreamingRecognitionConfig(config=config)
-def test(stream):
+
+def transcribe(stream):
+
requests = (
speech.StreamingRecognizeRequest(audio_content=chunk) for chunk in 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()