samiam-rs 0.0.0-stage → 0.1.3

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
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # samiam
2
+
3
+ **You have selected Microsoft Sam as the computer's default voice.**
4
+
5
+ Samuel Andrew Microsoft was born in '85 and has been reading errors ever since.
6
+
7
+ [▶ Listen](https://cdn.jsdelivr.net/gh/06chaynes/samiam@main/assets/samiam.wav) or make him say something else [here](https://06chaynes.github.io/samiam/).
8
+
9
+ ## npm
10
+
11
+ `npm add samiam-rs` puts Sam in a browser, types included. TypeScript needs 5.2+ and `esnext.disposable` in `lib`.
12
+
13
+ ```js
14
+ import init, { Voice, phonemes } from "samiam-rs";
15
+ await init();
16
+ phonemes("Hello!"); // "HH EH1 L OW !"
17
+ new Voice().wav("I am Sam, Sam I am."); // Uint8Array, a complete WAV
18
+ ```
2
19
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "samiam-rs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.3",
4
+ "description": "Retro text-to-speech from letter-to-sound rules and a formant synthesizer",
5
+ "license": "MIT OR Apache-2.0",
6
+ "type": "module",
7
+ "keywords": [
8
+ "wasm",
9
+ "tts",
10
+ "speech",
11
+ "retro",
12
+ "rust"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/06chaynes/samiam.git"
17
+ },
18
+ "main": "./samiam.js",
19
+ "types": "./samiam.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./samiam.d.ts",
23
+ "default": "./samiam.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "samiam.js",
28
+ "samiam_bg.wasm",
29
+ "samiam.d.ts"
30
+ ]
31
+ }
package/samiam.d.ts ADDED
@@ -0,0 +1,59 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class Voice {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ constructor();
8
+ speak(text: string): Float32Array;
9
+ wav(text: string): Uint8Array;
10
+ pitch: number;
11
+ sample_rate: number;
12
+ speed: number;
13
+ }
14
+
15
+ export function phonemes(text: string): string;
16
+
17
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
18
+
19
+ export interface InitOutput {
20
+ readonly memory: WebAssembly.Memory;
21
+ readonly __wbg_get_voice_pitch: (a: number) => number;
22
+ readonly __wbg_get_voice_sample_rate: (a: number) => number;
23
+ readonly __wbg_get_voice_speed: (a: number) => number;
24
+ readonly __wbg_set_voice_pitch: (a: number, b: number) => void;
25
+ readonly __wbg_set_voice_sample_rate: (a: number, b: number) => void;
26
+ readonly __wbg_set_voice_speed: (a: number, b: number) => void;
27
+ readonly __wbg_voice_free: (a: number, b: number) => void;
28
+ readonly phonemes: (a: number, b: number) => [number, number];
29
+ readonly voice_new: () => number;
30
+ readonly voice_speak: (a: number, b: number, c: number) => [number, number];
31
+ readonly voice_wav: (a: number, b: number, c: number) => [number, number];
32
+ readonly __wbindgen_externrefs: WebAssembly.Table;
33
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
34
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
35
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
36
+ readonly __wbindgen_start: () => void;
37
+ }
38
+
39
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
40
+
41
+ /**
42
+ * Instantiates the given `module`, which can either be bytes or
43
+ * a precompiled `WebAssembly.Module`.
44
+ *
45
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
46
+ *
47
+ * @returns {InitOutput}
48
+ */
49
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
50
+
51
+ /**
52
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
53
+ * for everything else, calls `WebAssembly.instantiate` directly.
54
+ *
55
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
56
+ *
57
+ * @returns {Promise<InitOutput>}
58
+ */
59
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/samiam.js ADDED
@@ -0,0 +1,322 @@
1
+ /* @ts-self-types="./samiam.d.ts" */
2
+
3
+ export class Voice {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ VoiceFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_voice_free(ptr, 0);
13
+ }
14
+ /**
15
+ * @returns {number}
16
+ */
17
+ get pitch() {
18
+ const ret = wasm.__wbg_get_voice_pitch(this.__wbg_ptr);
19
+ return ret;
20
+ }
21
+ /**
22
+ * @returns {number}
23
+ */
24
+ get sample_rate() {
25
+ const ret = wasm.__wbg_get_voice_sample_rate(this.__wbg_ptr);
26
+ return ret >>> 0;
27
+ }
28
+ /**
29
+ * @returns {number}
30
+ */
31
+ get speed() {
32
+ const ret = wasm.__wbg_get_voice_speed(this.__wbg_ptr);
33
+ return ret;
34
+ }
35
+ /**
36
+ * @param {number} arg0
37
+ */
38
+ set pitch(arg0) {
39
+ wasm.__wbg_set_voice_pitch(this.__wbg_ptr, arg0);
40
+ }
41
+ /**
42
+ * @param {number} arg0
43
+ */
44
+ set sample_rate(arg0) {
45
+ wasm.__wbg_set_voice_sample_rate(this.__wbg_ptr, arg0);
46
+ }
47
+ /**
48
+ * @param {number} arg0
49
+ */
50
+ set speed(arg0) {
51
+ wasm.__wbg_set_voice_speed(this.__wbg_ptr, arg0);
52
+ }
53
+ constructor() {
54
+ const ret = wasm.voice_new();
55
+ this.__wbg_ptr = ret;
56
+ VoiceFinalization.register(this, this.__wbg_ptr, this);
57
+ return this;
58
+ }
59
+ /**
60
+ * @param {string} text
61
+ * @returns {Float32Array}
62
+ */
63
+ speak(text) {
64
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ const ret = wasm.voice_speak(this.__wbg_ptr, ptr0, len0);
67
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
68
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
69
+ return v2;
70
+ }
71
+ /**
72
+ * @param {string} text
73
+ * @returns {Uint8Array}
74
+ */
75
+ wav(text) {
76
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
77
+ const len0 = WASM_VECTOR_LEN;
78
+ const ret = wasm.voice_wav(this.__wbg_ptr, ptr0, len0);
79
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
80
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
81
+ return v2;
82
+ }
83
+ }
84
+ if (Symbol.dispose) Voice.prototype[Symbol.dispose] = Voice.prototype.free;
85
+
86
+ /**
87
+ * @param {string} text
88
+ * @returns {string}
89
+ */
90
+ export function phonemes(text) {
91
+ let deferred2_0;
92
+ let deferred2_1;
93
+ try {
94
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ const ret = wasm.phonemes(ptr0, len0);
97
+ deferred2_0 = ret[0];
98
+ deferred2_1 = ret[1];
99
+ return getStringFromWasm0(ret[0], ret[1]);
100
+ } finally {
101
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
102
+ }
103
+ }
104
+ function __wbg_get_imports() {
105
+ const import0 = {
106
+ __proto__: null,
107
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
108
+ throw new Error(getStringFromWasm0(arg0, arg1));
109
+ },
110
+ __wbindgen_init_externref_table: function() {
111
+ const table = wasm.__wbindgen_externrefs;
112
+ const offset = table.grow(4);
113
+ table.set(0, undefined);
114
+ table.set(offset + 0, undefined);
115
+ table.set(offset + 1, null);
116
+ table.set(offset + 2, true);
117
+ table.set(offset + 3, false);
118
+ },
119
+ };
120
+ return {
121
+ __proto__: null,
122
+ "./samiam_bg.js": import0,
123
+ };
124
+ }
125
+
126
+ const VoiceFinalization = (typeof FinalizationRegistry === 'undefined')
127
+ ? { register: () => {}, unregister: () => {} }
128
+ : new FinalizationRegistry(ptr => wasm.__wbg_voice_free(ptr, 1));
129
+
130
+ function getArrayF32FromWasm0(ptr, len) {
131
+ ptr = ptr >>> 0;
132
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
133
+ }
134
+
135
+ function getArrayU8FromWasm0(ptr, len) {
136
+ ptr = ptr >>> 0;
137
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
138
+ }
139
+
140
+ let cachedFloat32ArrayMemory0 = null;
141
+ function getFloat32ArrayMemory0() {
142
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
143
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
144
+ }
145
+ return cachedFloat32ArrayMemory0;
146
+ }
147
+
148
+ function getStringFromWasm0(ptr, len) {
149
+ return decodeText(ptr >>> 0, len);
150
+ }
151
+
152
+ let cachedUint8ArrayMemory0 = null;
153
+ function getUint8ArrayMemory0() {
154
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
155
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
156
+ }
157
+ return cachedUint8ArrayMemory0;
158
+ }
159
+
160
+ function passStringToWasm0(arg, malloc, realloc) {
161
+ if (realloc === undefined) {
162
+ const buf = cachedTextEncoder.encode(arg);
163
+ const ptr = malloc(buf.length, 1) >>> 0;
164
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
165
+ WASM_VECTOR_LEN = buf.length;
166
+ return ptr;
167
+ }
168
+
169
+ let len = arg.length;
170
+ let ptr = malloc(len, 1) >>> 0;
171
+
172
+ const mem = getUint8ArrayMemory0();
173
+
174
+ let offset = 0;
175
+
176
+ for (; offset < len; offset++) {
177
+ const code = arg.charCodeAt(offset);
178
+ if (code > 0x7F) break;
179
+ mem[ptr + offset] = code;
180
+ }
181
+ if (offset !== len) {
182
+ if (offset !== 0) {
183
+ arg = arg.slice(offset);
184
+ }
185
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
186
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
187
+ const ret = cachedTextEncoder.encodeInto(arg, view);
188
+
189
+ offset += ret.written;
190
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
191
+ }
192
+
193
+ WASM_VECTOR_LEN = offset;
194
+ return ptr;
195
+ }
196
+
197
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
198
+ cachedTextDecoder.decode();
199
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
200
+ let numBytesDecoded = 0;
201
+ function decodeText(ptr, len) {
202
+ numBytesDecoded += len;
203
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
204
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
205
+ cachedTextDecoder.decode();
206
+ numBytesDecoded = len;
207
+ }
208
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
209
+ }
210
+
211
+ const cachedTextEncoder = new TextEncoder();
212
+
213
+ if (!('encodeInto' in cachedTextEncoder)) {
214
+ cachedTextEncoder.encodeInto = function (arg, view) {
215
+ const buf = cachedTextEncoder.encode(arg);
216
+ view.set(buf);
217
+ return {
218
+ read: arg.length,
219
+ written: buf.length
220
+ };
221
+ };
222
+ }
223
+
224
+ let WASM_VECTOR_LEN = 0;
225
+
226
+ let wasmModule, wasmInstance, wasm;
227
+ function __wbg_finalize_init(instance, module) {
228
+ wasmInstance = instance;
229
+ wasm = instance.exports;
230
+ wasmModule = module;
231
+ cachedFloat32ArrayMemory0 = null;
232
+ cachedUint8ArrayMemory0 = null;
233
+ wasm.__wbindgen_start();
234
+ return wasm;
235
+ }
236
+
237
+ async function __wbg_load(module, imports) {
238
+ if (typeof Response === 'function' && module instanceof Response) {
239
+ if (!module.ok) {
240
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
241
+ }
242
+
243
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
244
+ try {
245
+ return await WebAssembly.instantiateStreaming(module, imports);
246
+ } catch (e) {
247
+ const validResponse = expectedResponseType(module.type);
248
+
249
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
250
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
251
+
252
+ } else { throw e; }
253
+ }
254
+ }
255
+
256
+ const bytes = await module.arrayBuffer();
257
+ return await WebAssembly.instantiate(bytes, imports);
258
+ } else {
259
+ const instance = await WebAssembly.instantiate(module, imports);
260
+
261
+ if (instance instanceof WebAssembly.Instance) {
262
+ return { instance, module };
263
+ } else {
264
+ return instance;
265
+ }
266
+ }
267
+
268
+ function expectedResponseType(type) {
269
+ switch (type) {
270
+ case 'basic': case 'cors': case 'default': return true;
271
+ }
272
+ return false;
273
+ }
274
+ }
275
+
276
+ function initSync(module) {
277
+ if (wasm !== undefined) return wasm;
278
+
279
+
280
+ if (module !== undefined) {
281
+ if (Object.getPrototypeOf(module) === Object.prototype) {
282
+ ({module} = module)
283
+ } else {
284
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
285
+ }
286
+ }
287
+
288
+ const imports = __wbg_get_imports();
289
+ if (!(module instanceof WebAssembly.Module)) {
290
+ module = new WebAssembly.Module(module);
291
+ }
292
+ const instance = new WebAssembly.Instance(module, imports);
293
+ return __wbg_finalize_init(instance, module);
294
+ }
295
+
296
+ async function __wbg_init(module_or_path) {
297
+ if (wasm !== undefined) return wasm;
298
+
299
+
300
+ if (module_or_path !== undefined) {
301
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
302
+ ({module_or_path} = module_or_path)
303
+ } else {
304
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
305
+ }
306
+ }
307
+
308
+ if (module_or_path === undefined) {
309
+ module_or_path = new URL('samiam_bg.wasm', import.meta.url);
310
+ }
311
+ const imports = __wbg_get_imports();
312
+
313
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
314
+ module_or_path = fetch(module_or_path);
315
+ }
316
+
317
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
318
+
319
+ return __wbg_finalize_init(instance, module);
320
+ }
321
+
322
+ export { initSync, __wbg_init as default };
package/samiam_bg.wasm ADDED
Binary file