def main():
# Connect to websocket interfaces
headers = {}
userpass = ":".join(get_auth())
headers["Authorization"] = "Basic " + base64.b64encode(
userpass.encode()).decode()
url = ("wss://stream.watsonplatform.net//speech-to-text/api/v1/recognize"
"?model=en-US_BroadbandModel")
# If you really want to see everything going across the wire,
# uncomment this. However realize the trace is going to also do
# things like dump the binary sound packets in text in the
# console.
#
# websocket.enableTrace(True)
ws = websocket.WebSocketApp(url,
header=headers,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.on_open = on_open
ws.args = parse_args()
# This gives control over the WebSocketApp. This is a blocking
# call, so it won't return until the ws.close() gets called (after
# 6 seconds in the dedicated thread).
ws.run_forever()
评论列表
文章目录