speechmarkdown 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  High-performance SpeechMarkdown parser written in Rust. Converts [SpeechMarkdown](https://speechmarkdown.com/) syntax to platform-specific SSML for Amazon Alexa, Google Assistant, Microsoft Azure, and more.
4
4
 
5
+ ## Install
6
+
7
+ | Language | Package | Install |
8
+ |----------|---------|---------|
9
+ | Rust | [speechmarkdown-rust](https://crates.io/crates/speechmarkdown-rust) | `cargo add speechmarkdown-rust` |
10
+ | Python | [speechmarkdown-rust](https://pypi.org/project/speechmarkdown-rust/) | `pip install speechmarkdown-rust` |
11
+ | Node.js | [speechmarkdown](https://www.npmjs.com/package/speechmarkdown) | `npm install speechmarkdown` |
12
+ | .NET | [SpeechMarkdown](https://www.nuget.org/packages/SpeechMarkdown) | `dotnet add package SpeechMarkdown` |
13
+ | Swift | [Release asset](https://github.com/AACTools/speechmarkdown-rust/releases) | Download `speechmarkdown-swift-package.zip` |
14
+
15
+ ## Supported Platforms
16
+
17
+ | Platform | String ID |
18
+ |----------|-----------|
19
+ | Amazon Alexa | `"amazon-alexa"` or `"alexa"` |
20
+ | Google Assistant | `"google-assistant"` or `"google"` |
21
+ | Microsoft Azure | `"microsoft-azure"` or `"azure"` |
22
+ | Apple | `"apple"` |
23
+ | W3C | `"w3c"` |
24
+ | Samsung Bixby | `"samsung-bixby"` or `"bixby"` |
25
+ | ElevenLabs | `"elevenlabs"` |
26
+ | IBM Watson | `"ibm-watson"` or `"watson"` |
27
+
28
+ ## API
29
+
30
+ All bindings expose the same core methods:
31
+
32
+ | Method | Returns | Description |
33
+ |--------|---------|-------------|
34
+ | `to_ssml(input, platform)` | `string` | Convert SpeechMarkdown to SSML for the given platform |
35
+ | `to_text(input)` | `string` | Convert SpeechMarkdown to plain text (strips all markup) |
36
+ | `to_smd(ssml)` | `string` | Convert SSML to SpeechMarkdown (best-effort, lossy for unsupported elements) |
37
+ | `parse(input)` | `string` (JSON) | Parse SpeechMarkdown and return the AST as JSON |
38
+ | `is_speech_markdown(input)` | `bool` | Check if a string contains SpeechMarkdown syntax |
39
+ | `validate(input)` | `bool` | Validate that SpeechMarkdown parses without errors |
40
+
5
41
  ## Usage
6
42
 
7
43
  ### Rust
@@ -14,61 +50,62 @@ let ssml = SpeechMarkdownParser::to_ssml(
14
50
  "Hello (world)[emphasis:\"strong\"]",
15
51
  Platform::AmazonAlexa,
16
52
  )?;
17
- // => <speak>Hello <emphasis level="strong">world</emphasis></speak>
18
53
 
19
54
  // Convert to plain text
20
55
  let text = SpeechMarkdownParser::to_text("Hello (world)[emphasis:\"strong\"]")?;
21
- // => Hello world
22
56
 
23
- // Parse to AST (JSON)
57
+ // Parse to AST (JSON string)
24
58
  let ast = SpeechMarkdownParser::parse("Hello world")?;
59
+
60
+ // Check if input contains SpeechMarkdown syntax
61
+ if SpeechMarkdownParser::is_speech_markdown(&input) {
62
+ // ...
63
+ }
64
+
65
+ // Validate input
66
+ SpeechMarkdownParser::validate(&input)?;
67
+
68
+ // Convert SSML back to SpeechMarkdown (best-effort)
69
+ let smd = SpeechMarkdownParser::to_smd(r#"<speak><emphasis level="strong">word</emphasis></speak>"#)?;
70
+ // Returns: ++word++
25
71
  ```
26
72
 
27
- ### Supported Platforms
73
+ ### Python
28
74
 
29
- | Platform | Enum Value | String ID |
30
- |----------|-----------|-----------|
31
- | Amazon Alexa | `Platform::AmazonAlexa` | `"amazon-alexa"` or `"alexa"` |
32
- | Google Assistant | `Platform::GoogleAssistant` | `"google-assistant"` or `"google"` |
33
- | Microsoft Azure | `Platform::MicrosoftAzure` | `"microsoft-azure"` or `"azure"` |
34
- | Apple | `Platform::Apple` | `"apple"` |
35
- | W3C | `Platform::W3c` | `"w3c"` |
36
- | Samsung Bixby | `Platform::SamsungBixby` | `"samsung-bixby"` or `"bixby"` |
37
- | ElevenLabs | `Platform::ElevenLabs` | `"elevenlabs"` |
38
- | IBM Watson | `Platform::IbmWatson` | `"ibm-watson"` or `"watson"` |
75
+ ```python
76
+ from speechmarkdown_rust import to_ssml, to_text, parse, is_speech_markdown, validate
39
77
 
40
- ## Language Bindings
78
+ ssml = to_ssml('Hello (world)[emphasis:"strong"]', 'amazon-alexa')
79
+ text = to_text('Hello (world)[emphasis:"strong"]')
80
+ ast = parse('Hello world')
41
81
 
42
- 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.
82
+ is_smd = is_speech_markdown('Hello (world)[emphasis:"strong"]') # True
83
+ is_smd = is_speech_markdown('Hello world') # False
43
84
 
44
- ### Build the native library
85
+ validate('Hello (world)[emphasis:"strong"]') # raises ValueError if invalid
45
86
 
46
- ```bash
47
- cargo build --release
87
+ # Convert SSML to SpeechMarkdown (best-effort)
88
+ smd = to_smd('<speak><emphasis level="strong">word</emphasis></speak>')
89
+ # Returns: ++word++
48
90
  ```
49
91
 
50
- This produces:
51
- - **Windows**: `target/release/speechmarkdown_rust.dll`
52
- - **macOS**: `target/release/libspeechmarkdown_rust.dylib`
53
- - **Linux**: `target/release/libspeechmarkdown_rust.so`
92
+ ### Node.js
54
93
 
55
- ### C API
94
+ ```js
95
+ const { to_ssml, to_text, parse, is_speech_markdown, validate } = require('speechmarkdown')
56
96
 
57
- ```c
58
- #include "bindings/speechmarkdown.h"
97
+ const ssml = to_ssml('Hello (world)[emphasis:"strong"]', 'amazon-alexa')
98
+ const text = to_text('Hello (world)[emphasis:"strong"]')
99
+ const ast = parse('Hello world')
59
100
 
60
- // Convert SpeechMarkdown to SSML
61
- const char* ssml = speechmarkdown_to_ssml("Hello (world)[emphasis:\"strong\"]", "amazon-alexa");
62
- printf("%s\n", ssml);
63
- speechmarkdown_free((char*)ssml);
101
+ is_speech_markdown('Hello (world)[emphasis:"strong"]') // true
102
+ is_speech_markdown('Hello world') // false
64
103
 
65
- // Convert to plain text
66
- const char* text = speechmarkdown_to_text("Hello (world)[emphasis:\"strong\"]");
67
- printf("%s\n", text);
68
- speechmarkdown_free((char*)text);
104
+ validate('Hello (world)[emphasis:"strong"]') // throws if invalid
69
105
 
70
- // Get last error (thread-local)
71
- const char* err = speechmarkdown_get_error();
106
+ // Convert SSML to SpeechMarkdown (best-effort)
107
+ const smd = to_smd('<speak><emphasis level="strong">word</emphasis></speak>')
108
+ // Returns: ++word++
72
109
  ```
73
110
 
74
111
  ### .NET (C#)
@@ -81,12 +118,24 @@ var parser = new SpeechMarkdownParser();
81
118
  string ssml = parser.ToSsml("Hello (world)[emphasis:\"strong\"]", Platform.AmazonAlexa);
82
119
  string text = parser.ToText("Hello (world)[emphasis:\"strong\"]");
83
120
  string json = parser.ParseToJson("Hello world");
84
- ```
85
121
 
86
- Copy `bindings/dotnet/SpeechMarkdown.cs` into your project and place the native library in your output directory alongside the assembly.
122
+ bool isSmd = parser.IsSpeechMarkdown("Hello (world)[emphasis:\"strong\"]"); // true
123
+ parser.Validate("Hello (world)[emphasis:\"strong\"]"); // throws on invalid
124
+
125
+ // Convert SSML to SpeechMarkdown (best-effort)
126
+ string smd = parser.ToSmd("<speak><emphasis level=\"strong\">word</emphasis></speak>");
127
+ // Returns: ++word++
128
+ ```
87
129
 
88
130
  ### Swift
89
131
 
132
+ Download `speechmarkdown-swift-package.zip` from the [latest release](https://github.com/AACTools/speechmarkdown-rust/releases), unzip it, and add it as a local package in Xcode:
133
+
134
+ 1. **Xcode**: File > Add Packages > Add Local > select the unzipped directory
135
+ 2. **Or in Package.swift**: `.package(path: "./path/to/speechmarkdown-swift-package")`
136
+
137
+ To build from source instead: `./build-swift-package.sh` (requires Rust toolchain with `aarch64-apple-darwin` and `x86_64-apple-darwin` targets)
138
+
90
139
  ```swift
91
140
  import SpeechMarkdown
92
141
 
@@ -95,32 +144,57 @@ let parser = SpeechMarkdownParser()
95
144
  let ssml = try parser.toSsml(input: "Hello (world)[emphasis:\"strong\"]", platform: "amazon-alexa")
96
145
  let text = try parser.toText(input: "Hello (world)[emphasis:\"strong\"]")
97
146
  let json = try parser.parseToJson(input: "Hello world")
147
+
148
+ let isSmd = parser.isSpeechMarkdown(input: "Hello (world)[emphasis:\"strong\"]") // true
149
+ try parser.validate(input: "Hello (world)[emphasis:\"strong\"]") // throws on invalid
150
+
151
+ // Convert SSML to SpeechMarkdown (best-effort)
152
+ let smd = try parser.toSmd(ssml: "<speak><emphasis level=\"strong\">word</emphasis></speak>")
153
+ // Returns: ++word++
98
154
  ```
99
155
 
100
- Include `bindings/swift/SpeechMarkdown.swift`, `bindings/swift/module.modulemap`, and `bindings/speechmarkdown.h` in your Xcode project. Link against the compiled `.dylib`.
156
+ ### C API
101
157
 
102
- ### Node.js
158
+ ```c
159
+ #include "speechmarkdown.h"
103
160
 
104
- ```js
105
- const { SpeechMarkdownParser } = require('./bindings/nodejs');
161
+ // Convert to SSML
162
+ const char* ssml = speechmarkdown_to_ssml("Hello (world)[emphasis:\"strong\"]", "amazon-alexa");
163
+ speechmarkdown_free((char*)ssml);
106
164
 
107
- const parser = new SpeechMarkdownParser();
165
+ // Convert to plain text
166
+ const char* text = speechmarkdown_to_text("Hello (world)[emphasis:\"strong\"]");
167
+ speechmarkdown_free((char*)text);
108
168
 
109
- const ssml = parser.toSsml('Hello (world)[emphasis:"strong"]', 'amazon-alexa');
110
- const text = parser.toText('Hello (world)[emphasis:"strong"]');
111
- const json = parser.parseToJson('Hello world');
112
- ```
169
+ // Parse to JSON
170
+ const char* json = speechmarkdown_parse("Hello world");
171
+ speechmarkdown_free((char*)json);
113
172
 
114
- Install `ffi-napi` and `ref-napi` as dependencies. Build the native library first with `cargo build --release`.
173
+ // Check for SpeechMarkdown syntax
174
+ bool is_smd = speechmarkdown_is_speech_markdown("Hello (world)[emphasis:\"strong\"]");
115
175
 
116
- ### Python
176
+ // Validate
177
+ bool valid = speechmarkdown_validate("Hello (world)[emphasis:\"strong\"]");
117
178
 
118
- ```python
119
- from speechmarkdown import to_ssml, to_text, parse
179
+ // Convert SSML to SpeechMarkdown (best-effort)
180
+ const char* smd = speechmarkdown_to_smd("<speak><emphasis level=\"strong\">word</emphasis></speak>");
181
+ speechmarkdown_free((char*)smd);
120
182
 
121
- ssml = to_ssml('Hello (world)[emphasis:"strong"]', 'amazon-alexa')
122
- text = to_text('Hello (world)[emphasis:"strong"]')
123
- ast = parse('Hello world') # returns dict
183
+ // Get last error (thread-local)
184
+ const char* err = speechmarkdown_get_error();
124
185
  ```
125
186
 
126
- Available on [PyPI](https://pypi.org/project/speechmarkdown-rust/) as `speechmarkdown-rust`.
187
+ ## Building from Source
188
+
189
+ ```bash
190
+ cargo build --release
191
+ ```
192
+
193
+ This produces:
194
+ - **Windows**: `target/release/speechmarkdown_rust.dll`
195
+ - **macOS**: `target/release/libspeechmarkdown_rust.dylib`
196
+ - **Linux**: `target/release/libspeechmarkdown_rust.so`
197
+
198
+ ## License
199
+
200
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speechmarkdown",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "SpeechMarkdown parser - convert SpeechMarkdown to SSML",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "build:debug": "napi build --platform",
11
11
  "prepublishOnly": "napi prepublish -t npm",
12
12
  "test": "node test.js",
13
- "version": "0.1.12"
13
+ "version": "0.1.14"
14
14
  },
15
15
  "keywords": [
16
16
  "speech",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file