ws loop
This commit is contained in:
parent
ead59fc9f2
commit
e2dc3bad20
1 changed files with 16 additions and 6 deletions
24
ws.py
24
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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue