watson_developer_cloud.websocket.recognize_listener module

class RecognizeListener(audio_source, options, callback, url, headers, http_proxy_host=None, http_proxy_port=None)[source]

Bases: object

classmethod build_start_message(options)[source]
classmethod build_closing_message()[source]
classmethod extract_transcripts(alternatives)[source]
send(data, opcode=1)[source]

Send message to server.

data: message to send. If you set opcode to OPCODE_TEXT,
data must be utf-8 string or unicode.

opcode: operation code of data. default is OPCODE_TEXT.

send_audio(ws)[source]

Stream audio to server

Parameters:ws – Websocket client
on_open(ws)[source]

Callback executed when a connection is opened to the server. Handles streaming of audio to the server.

Parameters:ws – Websocket client
on_data(ws, message, message_type, fin)[source]

Callback executed when message is received from the server.

Parameters:
  • ws – Websocket client
  • message – utf-8 string which we get from the server.
  • message_type – Message type which is either ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY
  • fin – continue flag. If 0, the data continues.
on_error(ws, error)[source]

Callback executed when an error is received

Parameters:
  • ws – Websocket client
  • error – Exception object
on_close(ws)[source]

Callback executed when websocket connection is closed

Parameters:ws – Websocket client