Parser API

The SSMD Parser provides an alternative to SSML generation by extracting structured data from SSMD text. This is useful when you need programmatic control over SSMD features or want to build custom TTS pipelines.

When to Use the Parser

Use the parser API when you need to:

  • Process SSMD features programmatically - Extract and handle features individually

  • Build custom TTS pipelines - Implement your own text-to-speech workflow

  • Handle text transformations - Process say-as, substitution, and phoneme conversions

  • Create multi-voice dialogue systems - Build voice-specific processing pipelines

  • Analyze SSMD content - Extract metadata and features without generating SSML

Overview

The parser extracts SSMD markup into structured segments, allowing you to process each feature individually instead of generating a complete SSML document.

 from ssmd import parse_paragraphs

 script = """
 <div voice="sarah">
 Hello! Call [+1-555-0123]{as="telephone"} for info.
 </div>

 <div voice="michael">
 Thanks *Sarah*!
 </div>
 """

 # Parse into structured paragraphs
for paragraph in parse_paragraphs(script):
    for sentence in paragraph.sentences:
        # Get voice configuration
        voice_name = sentence.voice.name if sentence.voice else "default"

        # Build complete text from segments
        full_text = ""
        for seg in sentence.segments:
            # Handle text transformations
            if seg.say_as:
                text = convert_say_as(seg.text, seg.say_as.interpret_as)
            elif seg.substitution:
                text = seg.substitution
            elif seg.phoneme:
                text = seg.text  # TTS engine handles phoneme
            else:
                text = seg.text
            full_text += text

        # Speak with TTS engine
        tts.speak(full_text, voice=voice_name)

Parser Functions

parse_paragraphs

Parse SSMD text into structured paragraphs with sentences and segments.