Package: alexautils
AlexaUtilsAlexaUtils is a PyPI with utility classes and functions to supplement the Python AWS SDK for Alexa skill development.InstallationPython 3.6 +ask-sdk-core == 1.11.0To install Alexa Utils, use pip:pip install alexautilsImportsBy default, the following classes and functions are imported:ClassesSlotUtilsPauserFunctionslogger, log_func_names, log_alllinear_nlgThe smml_tags module is not imported by default.
Per convention, this module should be imported separately as ssml:>>>importalexautils.ssml_tagsasssml>>>ssml.MW_EXCITED.format("Hi!")ContentsSlotUtilsUtility class with methods to retrieve slots from user utterance.get_slot_val_by_name(handler_input, slot_name: str) -> str:Returns slot value for slot_name nameget_all_slot_values(handler_input) -> list:Returns all slot.values from user utteranceget_first_slot_value(handler_input) -> str:Returns first slot value from captured values.get_resolved_value(handler_input, slot_name: str) -> str:Returns resolved value for the slot.PauserUtility class to create pauses in speech response.get_pause(pause_length: float = 1) -> str:Returns pause speech for passed length.get_p_for_msg_len(message: str) -> str:Returns pause with duration based on message length.get_p_level(level: float) -> str:Returns pause length dependent on the level passed.Random variation included for more fluid UX.Standard levelsPause length (seconds)10.3520.7031.0541.4051.75make_ms_pause_level_list(*args) -> list:Returns list of the arguments to be added to speech_list.Transforms all int/float args into p_levels then adds to the list.linear_nlglinear_nlg(tuple_message_clause: tuple, str_joiner: str = ' ') -> strReturns message constructed from tuple message clause.Constructs the message with different methods per data type.Data typeMethodTuple/listrandom.choice()strappendintPauser.get_p_level()linear_nlg is a naive natural language generation (NLG) to interact with the user.
The method transforms linearly connected sentence chunks (e.g., clauses, parts of speech, etc.) into speech responses.Consider the following arbitrary noun phrase:"The red dog"This phrase can be parsed into 3 separate chunks:"The": determiner
"red": colour adjective
"dog": animal noun
In this example, the determiner, adjective, and noun have no effect on the meaning of the response.
We can use naive NLG to create an arbitrary noun phrase. This skill's NLG method would sample from the following three message tuples (MT).
A single item is sampled from each message tuple to create the noun phrase (DET, JJ, NN).MT_DET=("The","A",)MT_COLOUR_JJ=("red","blue","yellow",)MT_ANIMAL_NN=("dog","cat",)This NLG method requires careful consideration of sentence structure and semantics to avoid unnatural responses.
However, successful implementation increases response variety multiplicatively.
The speech construction for the above noun phrase yields 12 response permutations.>>>test=[MT_DET,MT_COLOUR_JJ,MT_ANIMAL_NN]>>>naive_nlg(test)"The red dog">>>naive_nlg(test)"A yellow cat"Logsloggerlog_level set by Lambda environment variablelog_leveldef log_func_name(func, *args, **kwargs):Decorator to log.debug the function name.log_all(*args, log_level: int = 10) -> None:Logs all arguments at log_level keyword.ssml_tagsAlexa's voice user interface uses Speech Synthesis Markup Language to control the speech output. SSML reference availablehereSSML are implemented as individual text wrappers so that wrappers can be applied to separate phrases, e.g.:MW_EXCITED_MED.format("Oh No!")+"Don't throw that away, please."NOTE:
May like to implement a class with dictionary structure to access SSML levels.
Referencepyssmlv0.0.1 - initial commit