SpeechMarkdown Rust
High-performance SpeechMarkdown parser written in Rust. Converts SpeechMarkdown syntax to platform-specific SSML for Amazon Alexa, Google Assistant, Microsoft Azure, and more.
Install
| Language | Package | Install |
|---|---|---|
| Rust | speechmarkdown-rust | cargo add speechmarkdown-rust |
| Python | speechmarkdown-rust | pip install speechmarkdown-rust |
| Node.js | speechmarkdown | npm install speechmarkdown |
| .NET | SpeechMarkdown | dotnet add package SpeechMarkdown |
| Swift | Release asset | Download speechmarkdown-swift-package.zip |
Supported Platforms
| Platform | String ID |
|---|---|
| Amazon Alexa | "amazon-alexa" or "alexa" |
| Google Assistant | "google-assistant" or "google" |
| Microsoft Azure | "microsoft-azure" or "azure" |
| Apple | "apple" |
| W3C | "w3c" |
| Samsung Bixby | "samsung-bixby" or "bixby" |
| ElevenLabs | "elevenlabs" |
| IBM Watson | "ibm-watson" or "watson" |
API
All bindings expose the same core methods:
| Method | Returns | Description |
|---|---|---|
to_ssml(input, platform) |
string |
Convert SpeechMarkdown to SSML for the given platform |
to_text(input) |
string |
Convert SpeechMarkdown to plain text (strips all markup) |
to_smd(ssml) |
string |
Convert SSML to SpeechMarkdown (best-effort, lossy for unsupported elements) |
parse(input) |
string (JSON) |
Parse SpeechMarkdown and return the AST as JSON |
is_speech_markdown(input) |
bool |
Check if a string contains SpeechMarkdown syntax |
validate(input) |
bool |
Validate that SpeechMarkdown parses without errors |
Usage
Rust
use ;
// Convert to SSML
let ssml = to_ssml?;
// Convert to plain text
let text = to_text?;
// Parse to AST (JSON string)
let ast = parse?;
// Check if input contains SpeechMarkdown syntax
if is_speech_markdown
// Validate input
validate?;
// Convert SSML back to SpeechMarkdown (best-effort)
let smd = to_smd?;
// Returns: ++word++
Python
=
=
=
= # True
= # False
# raises ValueError if invalid
# Convert SSML to SpeechMarkdown (best-effort)
=
# Returns: ++word++
Node.js
const = require
const ssml =
const text =
const ast =
// true
// false
// throws if invalid
// Convert SSML to SpeechMarkdown (best-effort)
const smd =
// Returns: ++word++
.NET (C#)
using SpeechMarkdown;
var parser = new SpeechMarkdownParser();
string ssml = parser.ToSsml("Hello (world)[emphasis:\"strong\"]", Platform.AmazonAlexa);
string text = parser.ToText("Hello (world)[emphasis:\"strong\"]");
string json = parser.ParseToJson("Hello world");
bool isSmd = parser.IsSpeechMarkdown("Hello (world)[emphasis:\"strong\"]"); // true
parser.Validate("Hello (world)[emphasis:\"strong\"]"); // throws on invalid
// Convert SSML to SpeechMarkdown (best-effort)
string smd = parser.ToSmd("<speak><emphasis level=\"strong\">word</emphasis></speak>");
// Returns: ++word++
Swift
Download speechmarkdown-swift-package.zip from the latest release, unzip it, and add it as a local package in Xcode:
- Xcode: File > Add Packages > Add Local > select the unzipped directory
- Or in Package.swift:
.package(path: "./path/to/speechmarkdown-swift-package")
To build from source instead: ./build-swift-package.sh (requires Rust toolchain with aarch64-apple-darwin and x86_64-apple-darwin targets)
import SpeechMarkdown
let parser = SpeechMarkdownParser()
let ssml = try parser.toSsml(input: "Hello (world)[emphasis:\"strong\"]", platform: "amazon-alexa")
let text = try parser.toText(input: "Hello (world)[emphasis:\"strong\"]")
let json = try parser.parseToJson(input: "Hello world")
let isSmd = parser.isSpeechMarkdown(input: "Hello (world)[emphasis:\"strong\"]") // true
try parser.validate(input: "Hello (world)[emphasis:\"strong\"]") // throws on invalid
// Convert SSML to SpeechMarkdown (best-effort)
let smd = try parser.toSmd(ssml: "<speak><emphasis level=\"strong\">word</emphasis></speak>")
// Returns: ++word++
C API
// Convert to SSML
const char* ssml = ;
;
// Convert to plain text
const char* text = ;
;
// Parse to JSON
const char* json = ;
;
// Check for SpeechMarkdown syntax
bool is_smd = ;
// Validate
bool valid = ;
// Convert SSML to SpeechMarkdown (best-effort)
const char* smd = ;
;
// Get last error (thread-local)
const char* err = ;
Building from Source
This produces:
- Windows:
target/release/speechmarkdown_rust.dll - macOS:
target/release/libspeechmarkdown_rust.dylib - Linux:
target/release/libspeechmarkdown_rust.so
License
MIT