Skip to content

Instantly share code, notes, and snippets.

@gmyrianthous
Created November 21, 2021 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmyrianthous/1c2e73104c7f479773034ff892a329b5 to your computer and use it in GitHub Desktop.
Save gmyrianthous/1c2e73104c7f479773034ff892a329b5 to your computer and use it in GitHub Desktop.
Real-time Speech-To-Text Tutorial - Part 2
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