'''
ssmd_text = ssmd.from_ssml(ssml)
# Output:
# *Hello* world
#
# This is [important]{volume="loud"}
#
# ...500ms
#
# Goodbye
Whitespace Handling
-------------------
SSMD normalizes whitespace during conversion:
.. code-block:: python
# Extra whitespace is normalized
ssml = '''
Hello
world
'''
ssmd_text = ssmd.from_ssml(ssml)
# → *Hello* world (whitespace normalized)
Error Handling
--------------
Invalid SSML
~~~~~~~~~~~~
.. code-block:: python
import ssmd
try:
ssmd.from_ssml('text')
except ValueError as e:
print(f"Error: {e}")
# Invalid/unknown tags are treated as plain text
Malformed XML
~~~~~~~~~~~~~
.. code-block:: python
try:
ssmd.from_ssml('unclosed')
except ValueError as e:
print(f"XML Parse Error: {e}")
Configuration Options
---------------------
.. code-block:: python
from ssmd import Document
parser = Document(capabilities='espeak')
# SSML features not supported by eSpeak will be simplified
ssml = 'Hello'
doc = Document.from_ssml(ssml, capabilities='espeak')
ssmd_text = doc.to_ssmd()
# eSpeak doesn't support emphasis, so output is just: Hello
Use Cases
---------
Migration from Raw SSML
~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from ssmd import Document
# You have existing SSML files
with open('old_ssml.xml') as f:
ssml = f.read()
# Convert to SSMD for easier editing
doc = Document.from_ssml(ssml)
ssmd_text = doc.to_ssmd()
with open('new_ssmd.txt', 'w') as f:
f.write(ssmd_text)
SSML Editor Backend
~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from ssmd import Document
# Load SSML for editing
def load_document(ssml_file):
with open(ssml_file) as f:
ssml = f.read()
return Document.from_ssml(ssml)
# Save as SSML
def save_document(doc, ssml_file):
ssml = doc.to_ssml()
with open(ssml_file, 'w') as f:
f.write(ssml)
Testing and Validation
~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from ssmd import Document
# Validate SSML by round-trip conversion
def validate_ssml(ssml_text):
try:
doc = Document.from_ssml(ssml_text)
restored_ssml = doc.to_ssml()
return True
except Exception as e:
print(f"Validation failed: {e}")
return False
Limitations
-----------
1. **Syntax differences**: Round-trip conversion is semantically equivalent but may
normalize attribute order or quoting in annotations
2. **Comments lost**: XML comments are not preserved
3. **Unknown elements**: Custom SSML elements are converted to plain text
4. **Attribute order**: Attribute order may change but semantics are preserved
5. **Whitespace**: Whitespace is normalized for readability