Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSML Tags Fix #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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}