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 +129 -55
- package/package.json +2 -2
- package/speechmarkdown.darwin-arm64.node +0 -0
- package/speechmarkdown.darwin-x64.node +0 -0
- package/speechmarkdown.linux-arm64-gnu.node +0 -0
- package/speechmarkdown.linux-x64-gnu.node +0 -0
- package/speechmarkdown.linux-x64-musl.node +0 -0
- package/speechmarkdown.win32-arm64-msvc.node +0 -0
- package/speechmarkdown.win32-x64-msvc.node +0 -0
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
|
-
###
|
|
73
|
+
### Python
|
|
28
74
|
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
+
is_smd = is_speech_markdown('Hello (world)[emphasis:"strong"]') # True
|
|
83
|
+
is_smd = is_speech_markdown('Hello world') # False
|
|
43
84
|
|
|
44
|
-
|
|
85
|
+
validate('Hello (world)[emphasis:"strong"]') # raises ValueError if invalid
|
|
45
86
|
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
94
|
+
```js
|
|
95
|
+
const { to_ssml, to_text, parse, is_speech_markdown, validate } = require('speechmarkdown')
|
|
56
96
|
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
//
|
|
61
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
71
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
156
|
+
### C API
|
|
101
157
|
|
|
102
|
-
|
|
158
|
+
```c
|
|
159
|
+
#include "speechmarkdown.h"
|
|
103
160
|
|
|
104
|
-
|
|
105
|
-
const
|
|
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
|
-
|
|
165
|
+
// Convert to plain text
|
|
166
|
+
const char* text = speechmarkdown_to_text("Hello (world)[emphasis:\"strong\"]");
|
|
167
|
+
speechmarkdown_free((char*)text);
|
|
108
168
|
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
```
|
|
169
|
+
// Parse to JSON
|
|
170
|
+
const char* json = speechmarkdown_parse("Hello world");
|
|
171
|
+
speechmarkdown_free((char*)json);
|
|
113
172
|
|
|
114
|
-
|
|
173
|
+
// Check for SpeechMarkdown syntax
|
|
174
|
+
bool is_smd = speechmarkdown_is_speech_markdown("Hello (world)[emphasis:\"strong\"]");
|
|
115
175
|
|
|
116
|
-
|
|
176
|
+
// Validate
|
|
177
|
+
bool valid = speechmarkdown_validate("Hello (world)[emphasis:\"strong\"]");
|
|
117
178
|
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
|
Binary file
|