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 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 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

Download speechmarkdown-swift-package.zip from the latest release, unzip it, and add it as a local package in Xcode:

  1. Xcode: File > Add Packages > Add Local > select the unzipped directory
  2. 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

#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.1.14.tar.gz (491.7 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.1.14-cp313-cp313-win_amd64.whl (252.0 kB view details)

Uploaded CPython 3.13Windows x86-64

speechmarkdown_rust-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (397.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

speechmarkdown_rust-0.1.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (386.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

speechmarkdown_rust-0.1.14-cp313-cp313-macosx_11_0_arm64.whl (348.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

speechmarkdown_rust-0.1.14-cp313-cp313-macosx_10_12_x86_64.whl (355.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: speechmarkdown_rust-0.1.14.tar.gz
  • Upload date:
  • Size: 491.7 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.1.14.tar.gz
Algorithm Hash digest
SHA256 dd2d19cadee9c8971d537e4c010cecee70a50b46b580ed07c384502ef0fddd85
MD5 bd902a9c03c0837bda1433e3142481b2
BLAKE2b-256 9cf6767bca6e24fa81e66fa75d187cb8416bab21f180d296a860ebb222aa8f52

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.1.14.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.1.14-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.1.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cfc400fb2a0f560322678e9ee8aa7b8e4e66b8c2b9ce798a74be4cf9f1e76d7c
MD5 97decc41b05fda56175b3833eed9eceb
BLAKE2b-256 e78b6f946a52925a6597751e862efd44c2c91d1ba029f53ea5d5b63e198a5282

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.1.14-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.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0632931a8350b6b46018489cccd1a97cc8e921c47cd01093b405b29b2b070706
MD5 2f2fc6e1ff6cd42affa3fb12355ad3cc
BLAKE2b-256 5a98cb40f7b94d1a11fd6c07ed1d43d7201e827ed2fca43db3484ea56039a6d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.1.14-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.1.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.1.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a3452cb086668d91f91ea51166349d4d150ad39f7b0242d53d796bafa83d2c49
MD5 efbf6a79fe7bcf2f514607716a6ec7b7
BLAKE2b-256 c86552b34436fe8db2ccb57174bd59195c9c6df36347767aaa8347e68ad9298f

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.1.14-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.1.14-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.1.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fcadc9cb2cd833ed65d5bf195f99d8970bb598942bb265cd2bb1b7a63804c37
MD5 d29a22fe6736cad726fe927c0a3dbfaa
BLAKE2b-256 94ddb81054db2eca4241e5ef2ef05d3e43f0e2c11eaab1a051812d8bce8ebc19

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.1.14-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.1.14-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for speechmarkdown_rust-0.1.14-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 59389e49d1c28999969fac65825be4910d08ff3491b2acabc758678d0e4e307a
MD5 e69ac382881c19bbb266e725bb5fdf09
BLAKE2b-256 c9c792e8d249228f2bc5463cc78b183b9564c637bbaafbf50e5824434eae515e

See more details on using hashes here.

Provenance

The following attestation bundles were made for speechmarkdown_rust-0.1.14-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