Skip to main content

SpeechMarkdown parser - convert SpeechMarkdown to SSML

Project description

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 See Swift section below

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
supported_ssml(platform) string (JSON) Get supported SSML elements for a platform

Usage

Rust

use speechmarkdown_rust::{SpeechMarkdownParser, Platform};

// Convert to SSML
let ssml = SpeechMarkdownParser::to_ssml(
    "Hello (world)[emphasis:\"strong\"]",
    Platform::AmazonAlexa,
)?;

// Convert to plain text
let text = SpeechMarkdownParser::to_text("Hello (world)[emphasis:\"strong\"]")?;

// Parse to AST (JSON string)
let ast = SpeechMarkdownParser::parse("Hello world")?;

// Check if input contains SpeechMarkdown syntax
if SpeechMarkdownParser::is_speech_markdown(&input) {
    // ...
}

// Validate input
SpeechMarkdownParser::validate(&input)?;

// Convert SSML back to SpeechMarkdown (best-effort)
let smd = SpeechMarkdownParser::to_smd(r#"<speak><emphasis level="strong">word</emphasis></speak>"#)?;
// Returns: ++word++

Python

from speechmarkdown_rust import to_ssml, to_text, parse, is_speech_markdown, validate

ssml = to_ssml('Hello (world)[emphasis:"strong"]', 'amazon-alexa')
text = to_text('Hello (world)[emphasis:"strong"]')
ast = parse('Hello world')

is_smd = is_speech_markdown('Hello (world)[emphasis:"strong"]')  # True
is_smd = is_speech_markdown('Hello world')                       # False

validate('Hello (world)[emphasis:"strong"]')  # raises ValueError if invalid

# Convert SSML to SpeechMarkdown (best-effort)
smd = to_smd('<speak><emphasis level="strong">word</emphasis></speak>')
# Returns: ++word++

Node.js

const { to_ssml, to_text, parse, is_speech_markdown, validate } = require('speechmarkdown')

const ssml = to_ssml('Hello (world)[emphasis:"strong"]', 'amazon-alexa')
const text = to_text('Hello (world)[emphasis:"strong"]')
const ast = parse('Hello world')

is_speech_markdown('Hello (world)[emphasis:"strong"]')  // true
is_speech_markdown('Hello world')                       // false

validate('Hello (world)[emphasis:"strong"]')  // throws if invalid

// Convert SSML to SpeechMarkdown (best-effort)
const smd = to_smd('<speak><emphasis level="strong">word</emphasis></speak>')
// 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

The repo root contains a Package.swift with a binary target pointing to a pre-built XCFramework. This enables both local development and Swift Package Index integration.

Option 1 — SPM (recommended):

// In your Package.swift:
.package(url: "https://github.com/AACTools/speechmarkdown-rust", branch: "spm")

Option 2 — Local package: Download speechmarkdown-swift-package.zip from the latest release, unzip, and add as a local package in Xcode (File > Add Packages > Add Local).

Includes macOS (arm64 + x86_64), iOS device (arm64), and iOS simulator (arm64) slices.

To build from source: ./build-swift-package.sh

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

#include "speechmarkdown.h"

// Convert to SSML
const char* ssml = speechmarkdown_to_ssml("Hello (world)[emphasis:\"strong\"]", "amazon-alexa");
speechmarkdown_free((char*)ssml);

// Convert to plain text
const char* text = speechmarkdown_to_text("Hello (world)[emphasis:\"strong\"]");
speechmarkdown_free((char*)text);

// Parse to JSON
const char* json = speechmarkdown_parse("Hello world");
speechmarkdown_free((char*)json);

// Check for SpeechMarkdown syntax
bool is_smd = speechmarkdown_is_speech_markdown("Hello (world)[emphasis:\"strong\"]");

// Validate
bool valid = speechmarkdown_validate("Hello (world)[emphasis:\"strong\"]");

// Convert SSML to SpeechMarkdown (best-effort)
const char* smd = speechmarkdown_to_smd("<speak><emphasis level=\"strong\">word</emphasis></speak>");
speechmarkdown_free((char*)smd);

// Get last error (thread-local)
const char* err = speechmarkdown_get_error();

Building from Source

cargo build --release

This produces:

  • Windows: target/release/speechmarkdown_rust.dll
  • macOS: target/release/libspeechmarkdown_rust.dylib
  • Linux: target/release/libspeechmarkdown_rust.so

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

speechmarkdown_rust-0.2.6.tar.gz (452.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

speechmarkdown_rust-0.2.6-cp313-cp313-win_amd64.whl (265.9 kB view details)

Uploaded CPython 3.13Windows x86-64

speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (409.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (398.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

speechmarkdown_rust-0.2.6-cp313-cp313-macosx_11_0_arm64.whl (356.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

speechmarkdown_rust-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl (365.9 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file speechmarkdown_rust-0.2.6.tar.gz.

File metadata

  • Download URL: speechmarkdown_rust-0.2.6.tar.gz
  • Upload date:
  • Size: 452.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for speechmarkdown_rust-0.2.6.tar.gz
Algorithm Hash digest
SHA256 44f4fde386cacc3491b74f10184d16f3771472a9a4cfbab94aeb4a6e89ee5aae
MD5 cd2680b8bb9f37cd799abec2fc9c7d39
BLAKE2b-256 6f2c0680cf6f7272dd6dbc0ffbdc0492732c21e9836024a86d79d5faa4ef9450

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.2.6.tar.gz:

Publisher: publish.yml on AACTools/speechmarkdown-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file speechmarkdown_rust-0.2.6-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.2.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 19e62d03b0cf0a7aaf085fee1bd5af1f117a44e8783d9aff0275634038e81e55
MD5 7380ab299b374e22483916924ea75d3a
BLAKE2b-256 454ea888fb80f0ec185ef8e256ecec24eac584966d92f2f6d5a7c02c090028bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.2.6-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on AACTools/speechmarkdown-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 874d81eb5b17316e2722e1c08dcaeb543f43e9152380088e7e175e16d0d69f7d
MD5 e5f8522639d5a1b2aca193d55a3e8293
BLAKE2b-256 308187c0f7b207b2e19af5f1bf11e5a180649b8c4c4bb9e2e1a3578eb27ce0dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on AACTools/speechmarkdown-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ded2ca1a45a44ac747c0e7cf65e21e5b8737625d95f9febeeab2c67ff09cba23
MD5 d37254f65bada6edad9b8b02eb90798d
BLAKE2b-256 ec2ce084a9623beff33502c0f5f8a9a578add83e0e795b7c9e93202946b76e5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on AACTools/speechmarkdown-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file speechmarkdown_rust-0.2.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.2.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d3cd470bb4e643a166f60ab40834e52a1920b6060307525a860a7004f0f82c6
MD5 73781068f23b8948ba8cb9071503dc54
BLAKE2b-256 3ef844895796f6fa93d0040b4390dc2fbf1e0112b59532832f01cd5ea5041f57

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.2.6-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on AACTools/speechmarkdown-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file speechmarkdown_rust-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 47b47134fc4e32ec2141ab35e534370557c5510c6b60b926a0d3ba7f9797730b
MD5 aec6b8b7251f176b06e7a5789f150f31
BLAKE2b-256 197f9f092046ba413bde0edd9e86163aa7aca456c8c09a255afd47742437f6c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: publish.yml on AACTools/speechmarkdown-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page