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.
Usage
Rust
use ;
// Convert to SSML
let ssml = to_ssml?;
// => <speak>Hello <emphasis level="strong">world</emphasis></speak>
// Convert to plain text
let text = to_text?;
// => Hello world
// Parse to AST (JSON)
let ast = parse?;
Supported Platforms
| Platform | Enum Value | String ID |
|---|---|---|
| Amazon Alexa | Platform::AmazonAlexa |
"amazon-alexa" or "alexa" |
| Google Assistant | Platform::GoogleAssistant |
"google-assistant" or "google" |
| Microsoft Azure | Platform::MicrosoftAzure |
"microsoft-azure" or "azure" |
| Apple | Platform::Apple |
"apple" |
| W3C | Platform::W3c |
"w3c" |
| Samsung Bixby | Platform::SamsungBixby |
"samsung-bixby" or "bixby" |
| ElevenLabs | Platform::ElevenLabs |
"elevenlabs" |
| IBM Watson | Platform::IbmWatson |
"ibm-watson" or "watson" |
Language Bindings
The library exposes a C ABI (cdylib/staticlib) so it can be used from any language. Pre-built bindings are provided for .NET, Swift, and Node.js.
Build the native library
This produces:
- Windows:
target/release/speechmarkdown_rust.dll - macOS:
target/release/libspeechmarkdown_rust.dylib - Linux:
target/release/libspeechmarkdown_rust.so
C API
// Convert SpeechMarkdown to SSML
const char* ssml = ;
;
;
// Convert to plain text
const char* text = ;
;
;
// Get last error (thread-local)
const char* err = ;
.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");
Copy bindings/dotnet/SpeechMarkdown.cs into your project and place the native library in your output directory alongside the assembly.
Swift
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")
Include bindings/swift/SpeechMarkdown.swift, bindings/swift/module.modulemap, and bindings/speechmarkdown.h in your Xcode project. Link against the compiled .dylib.
Node.js
const = require;
const parser = ;
const ssml = parser.;
const text = parser.;
const json = parser.;
Install ffi-napi and ref-napi as dependencies. Build the native library first with cargo build --release.
Python
=
=
= # returns dict
Available on PyPI as speechmarkdown-rust.