flask-ask
flask-ask copied to clipboard
Fix for using <amazon:effect> SSML
Encountered an issue where if I tried to submit a template with the amazon:effect tag, the parser would raise an error. This would result in the SSML being submitted as plain text.
I've moved from using xml.etree to lxml, which seems to solve the problem, but does add another dependency.
👍 on having this merged... I've been using dirty monkey patching to avoid new dependencies
def _output_speech(speech):
try:
xmldoc = ElementTree.fromstring(speech.replace('amazon:effect', 'aaa'))
if xmldoc.tag == 'speak':
return {'type': 'SSML', 'ssml': speech}
except (UnicodeEncodeError, ElementTree.ParseError) as e:
pass
return {'type': 'PlainText', 'text': speech}
flask_ask.models._output_speech = _output_speech