Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions flask_ask/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import inspect
from flask import json
from xml.etree import ElementTree
import aniso8601
from .core import session, context, current_stream, stream_cache, dbgdump
from .cache import push_stream
import uuid
import re

SPEAK_TAG_REGEX = re.compile("^<speak>.*<\/speak>")

class _Field(dict):
"""Container to represent Alexa Request Data.
Expand Down Expand Up @@ -451,10 +452,7 @@ def _copyattr(src, dest, attr, convert=None):


def _output_speech(speech):
try:
xmldoc = ElementTree.fromstring(speech)
if xmldoc.tag == 'speak':
return {'type': 'SSML', 'ssml': speech}
except (UnicodeEncodeError, ElementTree.ParseError) as e:
pass
return {'type': 'PlainText', 'text': speech}
if SPEAK_TAG_REGEX.match(speech):
return {"type": "SSML", "ssml": speech}

return {"type": "PlainText", "text": speech}