Example #1
0
    def test_convertComplex(self):
        """Test converting a complex speech sequence to SSML.
		XML generation is already tested by TestXmlBalancer.
		However, SSML is what callers expect at the end of the day,
		so test converting a complex speech sequence to SSML.
		Depends on behavior tested by TestXmlBalancer.
		"""
        converter = speechXml.SsmlConverter("en_US")
        xml = converter.convertToXml([
            "t1",
            PitchCommand(multiplier=2),
            VolumeCommand(multiplier=2), "t2",
            PitchCommand(),
            LangChangeCommand("de_DE"),
            CharacterModeCommand(True),
            IndexCommand(1), "c",
            CharacterModeCommand(False),
            PhonemeCommand("phIpa", text="phText")
        ])
        self.assertEqual(
            xml,
            '<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">'
            't1'
            '<prosody pitch="200%" volume="200%">t2</prosody>'
            '<prosody volume="200%"><voice xml:lang="de-DE">'
            '<mark name="1"/><say-as interpret-as="characters">c</say-as>'
            '<phoneme alphabet="ipa" ph="phIpa">phText</phoneme>'
            '</voice></prosody></speak>')
Example #2
0
def _processMpSpeech(text, language):
    # MathPlayer's default rate is 180 wpm.
    # Assume that 0% is 80 wpm and 100% is 450 wpm and scale accordingly.
    synth = getSynth()
    wpm = synth._percentToParam(synth.rate, 80, 450)
    breakMulti = 180.0 / wpm
    out = []
    if language:
        out.append(LangChangeCommand(language))
    resetProsody = set()
    for m in RE_MP_SPEECH.finditer(text):
        if m.lastgroup == "break":
            out.append(BreakCommand(time=int(m.group("break")) * breakMulti))
        elif m.lastgroup == "char":
            out.extend((CharacterModeCommand(True), m.group("char"),
                        CharacterModeCommand(False)))
        elif m.lastgroup == "comma":
            out.append(BreakCommand(time=100))
        elif m.lastgroup in PROSODY_COMMANDS:
            command = PROSODY_COMMANDS[m.lastgroup]
            out.append(command(multiplier=int(m.group(m.lastgroup)) / 100.0))
            resetProsody.add(command)
        elif m.lastgroup == "prosodyReset":
            for command in resetProsody:
                out.append(command(multiplier=1))
            resetProsody.clear()
        elif m.lastgroup == "phonemeText":
            out.append(
                PhonemeCommand(m.group("ipa"), text=m.group("phonemeText")))
        elif m.lastgroup == "content":
            out.append(m.group(0))
    if language:
        out.append(LangChangeCommand(None))
    return out
Example #3
0
    def test_redundantSequenceAfterEndUtterance(self):
        """
		Tests that redundant param change and index commands are not emitted as an extra utterance
		when the preceeding utterance contained param change commands and an EndUtterance command.
		See PR #11651
		E.g. speaking a character.
		"""
        smi = SpeechManagerInteractions(self)
        seq = [
            CharacterModeCommand(True),
            "a",
            smi.create_ExpectedIndex(1),
            EndUtteranceCommand(),
        ]
        with smi.expectation():
            smi.speak(seq)
            # synth should receive the characterMode, the letter 'a' and an index command.
            smi.expect_synthSpeak(sequence=seq[:-1])
        with smi.expectation():
            # Previously, this would result in synth.speak receiving
            # a call with sequence:
            # [CharacterModeCommand(True), IndexCommand(2)]
            # This is a problem because it includes an index command but no speech.
            # This is inefficient, and also some SAPI5 synths such as Ivona will not
            # notify of this bookmark.
            smi.indexReached(1)
            smi.doneSpeaking()
            smi.pumpAll()
Example #4
0
 def test_manySymbolNamesInARow(self):
     # Spelling a...b
     seq = (c for c in [
         'a',
         EndUtteranceCommand(), 'dot',
         EndUtteranceCommand(), 'dot',
         EndUtteranceCommand(), 'dot',
         EndUtteranceCommand(), 'b',
         EndUtteranceCommand()
     ])
     expected = repr([
         CharacterModeCommand(True), 'a',
         EndUtteranceCommand(),
         CharacterModeCommand(False), 'dot',
         EndUtteranceCommand(), 'dot',
         EndUtteranceCommand(), 'dot',
         EndUtteranceCommand(),
         CharacterModeCommand(True), 'b',
         EndUtteranceCommand()
     ])
     output = _getSpellingSpeechAddCharMode(seq)
     self.assertEqual(repr(list(output)), expected)
Example #5
0
 def test_symbolNamesAtStartAndEnd(self):
     # Spelling ¡hola!
     seq = (c for c in [
         'inverted exclamation point',
         EndUtteranceCommand(), 'h',
         EndUtteranceCommand(), 'o',
         EndUtteranceCommand(), 'l',
         EndUtteranceCommand(), 'a',
         EndUtteranceCommand(), 'bang',
         EndUtteranceCommand()
     ])
     expected = repr([
         'inverted exclamation point',
         EndUtteranceCommand(),
         CharacterModeCommand(True), 'h',
         EndUtteranceCommand(), 'o',
         EndUtteranceCommand(), 'l',
         EndUtteranceCommand(), 'a',
         EndUtteranceCommand(),
         CharacterModeCommand(False), 'bang',
         EndUtteranceCommand()
     ])
     output = _getSpellingSpeechAddCharMode(seq)
     self.assertEqual(repr(list(output)), expected)
Example #6
0
    def test_nonSpokenCharacter(self):
        """Test for fix to GH#11752 - NVDA Freeze with unicode value U+000B
		Actually, the speech manager receives an empty string for the character U+000B. NVDA
		does not have a mapping for this character.
		It is questionable whether we should send anything to the synth when there is no content, however
		what constitutes 'content' is currently not easy to define.
		"""
        smi = SpeechManagerInteractions(self)

        speechSequence = [
            CharacterModeCommand(True), '',
            smi.create_EndUtteranceCommand(expectedToBecomeIndex=1)
        ]
        with smi.expectation():
            seqIndexes = smi.speak(speechSequence)
            smi.expect_synthSpeak(seqIndexes)