Created
November 21, 2021 16:41
-
-
Save gmyrianthous/1c2e73104c7f479773034ff892a329b5 to your computer and use it in GitHub Desktop.
Real-time Speech-To-Text Tutorial - Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import base64 | |
import asyncio | |
async def send_data(): | |
""" | |
Asynchronous function used for sending data | |
""" | |
while True: | |
try: | |
data = audio_stream.read(FRAMES_PER_BUFFER) | |
data = base64.b64encode(data).decode('utf-8') | |
await ws_connection.send(json.dumps({'audio_data': str(data)})) | |
except Exception as e: | |
print(f'Something went wrong. Error code was {e.code}') | |
break | |
await asyncio.sleep(0.5) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment