From 04582a2bd06f7d64a0b8e7e29519a79a7df28849 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 28 Apr 2020 21:16:55 +1200 Subject: [PATCH] Catch more cases of consecutive breaks. --- src/SSML.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/SSML.hs b/src/SSML.hs index 4e2eb50..778341b 100644 --- a/src/SSML.hs +++ b/src/SSML.hs @@ -15,7 +15,8 @@ import Data.List (elemIndex) import SpeechStyle styleToSSML :: StyleTree SpeechStyle -> Element -styleToSSML = Element "{http://www.w3.org/2001/10/synthesis}speak" M.empty . collapseBreaks' . styleToNodes +styleToSSML = Element "{http://www.w3.org/2001/10/synthesis}speak" M.empty . + collapseBreaks' . floatBreaks' . styleToNodes styleToNodes :: StyleTree SpeechStyle -> [Node] styleToNodes = Prelude.map style . postorder styleToSSML' @@ -91,6 +92,17 @@ pitch2txt (Absolute (Unit' unit n)) = Txt.pack (show n) `Txt.append` unit pitch2txt (Relative n) = unit2txt n -- collapse +floatBreaks :: Element -> [Node] +floatBreaks el@(Element _ _ childs) + | break@(NodeElement (Element "break" _ _)):nodes <- floatBreaks' childs = + break : floatBreaks el{elementNodes = nodes} + | break@(NodeElement (Element "break" _ _)):nodes <- reverse $ floatBreaks' childs = + floatBreaks el{elementNodes = reverse nodes} ++ [break] + | otherwise = [NodeElement el] +floatBreaks' (NodeElement el:nodes) = floatBreaks el ++ floatBreaks' nodes +floatBreaks' (node:nodes) = node : floatBreaks' nodes +floatBreaks' [] = [] + collapseBreaks :: Element -> Element collapseBreaks (Element name attrs elChildren) = Element name attrs $ collapseBreaks' elChildren -- 2.30.2