pyzenbo.modules.dialog_system module

class pyzenbo.modules.dialog_system.RobotFace

Bases: object

Face expression ID.

HIDEFACE = 'HIDEFACE'
INTERESTED = 'INTERESTED'
DOUBTING = 'DOUBTING'
PROUD = 'PROUD'
DEFAULT = 'DEFAULT'
HAPPY = 'HAPPY'
EXPECTING = 'EXPECTING'
SHOCKED = 'SHOCKED'
QUESTIONING = 'QUESTIONING'
IMPATIENT = 'IMPATIENT'
CONFIDENT = 'CONFIDENT'
ACTIVE = 'ACTIVE'
PLEASED = 'PLEASED'
HELPLESS = 'HELPLESS'
SERIOUS = 'SERIOUS'
WORRIED = 'WORRIED'
PRETENDING = 'PRETENDING'
LAZY = 'LAZY'
AWARE_RIGHT = 'AWARE_RIGHT'
TIRED = 'TIRED'
SHY = 'SHY'
INNOCENT = 'INNOCENT'
SINGING = 'SINGING'
AWARE_LEFT = 'AWARE_LEFT'
DEFAULT_STILL = 'DEFAULT_STILL'
PREVIOUS = 'PREVIOUS'
EXPECTING_ADV = 'EXPECTING_ADV'
IMPATIENT_ADV = 'IMPATIENT_ADV'
PLEASED_ADV = 'PLEASED_ADV'
SHOCKED_ADV = 'SHOCKED_ADV'
TIRED_ADV = 'TIRED_ADV'
DEFAULT_ADV = 'DEFAULT_ADV'
WORRIED_ADV = 'WORRIED_ADV'
QUESTIONING_ADV = 'QUESTIONING_ADV'
PRETENDING_ADV = 'PRETENDING_ADV'
INTERESTED_ADV = 'INTERESTED_ADV'
SHY_ADV = 'SHY_ADV'
CONFIDENT_ADV = 'CONFIDENT_ADV'
HAPPY_ADV = 'HAPPY_ADV'
LAZY_ADV = 'LAZY_ADV'
ACTIVE_ADV = 'ACTIVE_ADV'
SINGING_ADV = 'SINGING_ADV'
DOUBTING_ADV = 'DOUBTING_ADV'
AWARE_RIGHT_ADV = 'AWARE_RIGHT_ADV'
AWARE_LEFT_ADV = 'AWARE_LEFT_ADV'
HELPLESS_ADV = 'HELPLESS_ADV'
SERIOUS_ADV = 'SERIOUS_ADV'
INNOCENT_ADV = 'INNOCENT_ADV'
PROUD_ADV = 'PROUD_ADV'
class pyzenbo.modules.dialog_system.DynamicEditAction

Bases: object

ADD_NEW_INSTANCE = 'addNewInstance'
UPDATE_NEW_INSTANCE = 'updateNewInstance'
DELETE_INSTANCE = 'deleteInstance'
class pyzenbo.modules.dialog_system.LanguageType

Bases: object

ZH_TW = 1
EN_US = 2
ZH_CN = 3
JP = 4
HK = 7
DE = 8
FR = 9
ES = 10
PT = 11
NL = 12
class pyzenbo.modules.dialog_system.DialogSystem(inter_comm)

Bases: object

contain of pyzenbo.robot attribute

register_listen_callback(domain, listen, sync=True, timeout=None)

Register the listen callback functions for Dialog System.

Usage
def listen_callback(args):
    utterance = args.get('event_user_utterance', None)
    vad = args.get('event_vad_status', None)
    slu = args.get('event_slu_query', None)
    msg = 'listen uu:{}, vad:{}, slu:{}'
    print(msg.format(utterance, vad, slu))
    if not utterance and not vad and not slu:
        print('listen raw:{}'.format(args))
    result = parser_listen_result(slu)
    if result is not None:
        print('slu_result:{}'.format(result))

sdk = pyzenbo.connect(host_ip)
sdk.robot.register_listen_callback(domain, listen_callback)
Parameters
  • domain – domain UUID

  • listen – listen callback function

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

unregister_listen_callback(sync=True, timeout=None)

Unregister listen callback.

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.unregister_listen_callback()
Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

speak(sentence, config=None, sync=True, timeout=None)

Start speaking.

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.speak("hello world")
Parameters
  • sentence – sentence of text to speech

  • config – configuration for speak engine

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

stop_speak(sync=True, timeout=None)

Stop speaking.

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.stop_speak()
Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

set_expression(facial, sentence=None, config=None, sync=True, timeout=None)

Make robot expression and speak.

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.set_expression(RobotFace.PROUD, 'Hello World')
Parameters
  • facial – robot face expression ID: HIDEFACE, INTERESTED, DOUBTING, PROUD, DEFAULT, HAPPY, EXPECTING, SHOCKED, QUESTIONING, IMPATIENT, CONFIDENT, ACTIVE, PLEASED, HELPLESS, SERIOUS, WORRIED, PRETENDING, LAZY, AWARE_RIGHT, TIRED, SHY, INNOCENT, SINGING, AWARE_LEFT, DEFAULT_STILL, PREVIOUS

  • sentence – sentence of text to speech

  • config – configuration for expression engine

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

query_expression_status(sync=True, timeout=None)

Query expression status, return result in onResult callback, result will have an JSON string, key is “RESULT”. JSON object have two element, FaceID and FaceExit. FaceID is current face value, and FaceExit is an boolean True is currently have display expression.

Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

clear_app_context(domain, sync=True, timeout=None)

Clear specific domain UUID in current dialog system stack. pyzenbo.robot.clear_app_context

Parameters
  • domain – domain UUID

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

clear_background_context(domain, sync=True, timeout=None)

Clear background context.

Parameters
  • domain – domain UUID

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

dynamic_edit_instance(domain, action, entity, instances, sync=True, timeout=None)

Add/Delete/Update user defined instances of an specific Entity.

Parameters
  • domain – domain UUID

  • action – types of action

  • entity – the existed entity added on the Concept page of DS Editor

  • instances – the instances to be modified

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

jump_to_plan(domain, plan, cross_intent=None, sync=True, timeout=None)

Let dialog state switch to specific plan, and set output context of this plan on top of the context stack.

Parameters
  • domain – domain UUID

  • plan – plan ID to be switched to

  • cross_intent – set True to enable cross intent

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

set_background_context(domain, plan, sync=True, timeout=None)

Set background context.

Parameters
  • domain – domain UUID

  • plan – plan ID

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

set_voice_trigger(enable, sync=True, timeout=None)

Set dialog system voice trigger.

Parameters
  • enable – flag to enable/disable dialog system voice trigger

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

reset_voice_trigger(enable, sync=True, timeout=None)

Reset dialog system voice trigger counter and force voice trigger enable or disable.

Parameters
  • enable – flag to enable/disable dialog system voice trigger

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

reset_voice_trigger_to_default(sync=True, timeout=None)

Reset dialog system voice trigger to default setting.

Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

set_listen_context(domain, context, sync=True, timeout=None)

Force Dialog System to listen specific context in the DS Editor

Parameters
  • domain – domain UUID

  • context – context to listen to

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

speak_and_listen(sentence, config=None, sync=True, timeout=None)

Start speaking and listening. If sentence is an empty string (“”), Zenbo will listen directly.

Parameters
  • sentence – sentence sentence of text to speech

  • config – configuration for speak engine

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

stop_speak_and_listen(sync=True, timeout=None)

Stop speak and listen.

Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

update_dialog_corpus_by_server(domain, package_name, version, sync=True, timeout=None)

Automatic compare corpus data version while call the API and will trigger command set update process if needed.

Parameters
  • domain – domain UUID string

  • package_name – package name on DDE

  • version – version string

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

query_word_similarity(input_sentence, target_sentence, sync=True, timeout=None)

Query word similarity between input and target sentences and get data from onResult callback, result bundle will have an JSON string, key is “RESULT”. JSON object have three element, input_sentence, target_sentence and similarity.

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.query_word_similarity(input_sentence='who are you',
                        target_sentence=['who are you', 'where are you'])

RESULT: ‘{“input_sentence”:”who are you”,”target_sentence”:[“who are you”,”where are you”], “similarity”:[{“who are you”:1.01},{“where are you”:0.57}]}’}

Parameters
  • input_sentence – input sentence

  • target_sentence – array for target sentence

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

zh_to_number(input_sentence, sync=True, timeout=None)

Transform ZH to number for inputSentence and get data from onResult callback, result bundle will have an JSON string, key is “RESULT”. Example: {“input_sentence”:”轉換數字一二三四”,”result”:”1234”}

Parameters
  • input_sentence – input sentence

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

en_to_number(input_sentence, sync=True, timeout=None)

Transform EN to number for inputSentence and get data from onResult callback, result bundle will have an JSON string, key is “RESULT”. Example: {“input_sentence”:”transform one thousand four hundred and fifty”,”result”:”1450”}

Parameters
  • input_sentence – input sentence

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

config_next_csr(language_type, disable_slu, sync=True, timeout=None)

Config next CSR setting. Include HeyZenbo trigger and speakAndListen API.

Parameters
  • language_type – LanguageType.ZH_TW, LanguageType.EN_US or LanguageType.ZH_CN, etc..

  • disable_slu – Disable SLU report and skip questioning expression

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

wait_for_listen(sentence, config=None, timeout=10)

Wait for speak and listen execute completed and return SLU result.

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.set_expression(RobotFace.HAPPY, timeout=5)
 sdk.robot.jump_to_plan('E7AABB554ACB414C9AB9BF45E7FA8AD9',
    'lanuchHelloWolrd_Plan')
 slu_result = sdk.robot.wait_for_listen('Which city do you like? You can say Hello Block City, or Hello White City')
Parameters
  • sentence – sentence sentence of text to speech

  • config – configuration for speak engine

  • timeout – maximum blocking time in second, None means infinity

Returns

SLU result, if timeout will return None

wait_for_doa(sentence, config=None, timeout=10)

Wait for speak and listen execute completed and return DOA (direction of arrival).

Usage
 sdk = pyzenbo.connect(host_ip)
 sdk.robot.set_expression(RobotFace.HAPPY, timeout=5)
 sdk.robot.jump_to_plan('E7AABB554ACB414C9AB9BF45E7FA8AD9',
    'lanuchHelloWolrd_Plan')
 doa = sdk.robot.wait_for_doa('Which city do you like? You can say Hello Block City, or Hello White City')
Parameters
  • sentence – sentence sentence of text to speech

  • config – configuration for speak engine

  • timeout – maximum blocking time in second, None means waiting speak and listen completed.

Returns

DOA result, if timeout or the error code of the listen result is not success will return None