def test_setAttrDifferentAttrs(self): """Tests multiple SetAttrCommands with different attributes of the same tag. """ xml = self.balancer.generateXml([ speechXml.SetAttrCommand("prosody", "pitch", 50), speechXml.SetAttrCommand("prosody", "volume", 60), "text" ]) self.assertEqual(xml, '<prosody pitch="50" volume="60">text</prosody>')
def test_setAttrDifferentTags(self): """Tests multiple SetAttrCommands with different tags. """ xml = self.balancer.generateXml([ speechXml.SetAttrCommand("pitch", "val", 50), speechXml.SetAttrCommand("volume", "val", 60), "text" ]) self.assertEqual( xml, '<pitch val="50"><volume val="60">text</volume></pitch>')
def test_setAttrInterspersedText(self): """Tests multiple SetAttrCommands interspersed with text. """ xml = self.balancer.generateXml([ speechXml.SetAttrCommand("pitch", "val", 50), "t1", speechXml.SetAttrCommand("volume", "val", 60), "t2" ]) self.assertEqual( xml, '<pitch val="50">t1</pitch><pitch val="50"><volume val="60">t2</volume></pitch>' )
def test_delSingleAttrOfMultipleAttrs(self): """Tests DelAttrCommand removing a single attribute from a tag which has multiple attributes. """ xml = self.balancer.generateXml([ speechXml.SetAttrCommand("prosody", "pitch", 50), speechXml.SetAttrCommand("prosody", "volume", 60), "t1", speechXml.DelAttrCommand("prosody", "pitch"), "t2" ]) self.assertEqual( xml, '<prosody pitch="50" volume="60">t1</prosody><prosody volume="60">t2</prosody>' )
def test_delAttrUnbalanced(self): """Tests DelAttrCommand removing an outer tag before an inner tag. """ xml = self.balancer.generateXml([ speechXml.SetAttrCommand("pitch", "val", 50), speechXml.SetAttrCommand("volume", "val", 60), "t1", speechXml.DelAttrCommand("pitch", "val"), "t2" ]) self.assertEqual( xml, '<pitch val="50"><volume val="60">t1</volume></pitch><volume val="60">t2</volume>' )
def _convertProsody(self, command, attr, default, base): if command.multiplier == 1 and base == default: # Returning to synth default. return speechXml.DelAttrCommand("prosody", attr) else: # Multiplication isn't supported, only addition/subtraction. # The final value must therefore be relative to the synthesizer's default. val = base * command.multiplier - default return speechXml.SetAttrCommand("prosody", attr, "%d%%" % val)
def test_setAttrThenDelAttr(self): xml = self.balancer.generateXml([ speechXml.SetAttrCommand("pitch", "val", 50), "t1", speechXml.DelAttrCommand("pitch", "val"), "t2" ]) self.assertEqual(xml, '<pitch val="50">t1</pitch>t2')
def test_setAttr(self): xml = self.balancer.generateXml( [speechXml.SetAttrCommand("pitch", "val", 50), "text"]) self.assertEqual(xml, '<pitch val="50">text</pitch>')