samiam-rs 0.1.3 → 0.3.0

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
@@ -13,7 +13,8 @@ Samuel Andrew Microsoft was born in '85 and has been reading errors ever since.
13
13
  ```js
14
14
  import init, { Voice, phonemes } from "samiam-rs";
15
15
  await init();
16
- phonemes("Hello!"); // "HH EH1 L OW !"
16
+ phonemes("Hello!"); // "HH AX L OW1 !"
17
17
  new Voice().wav("I am Sam, Sam I am."); // Uint8Array, a complete WAV
18
+ new Voice().cues("Hello!"); // Float32Array, each phoneme's start time in seconds
18
19
  ```
19
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samiam-rs",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Retro text-to-speech from letter-to-sound rules and a formant synthesizer",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
package/samiam.d.ts CHANGED
@@ -4,12 +4,22 @@
4
4
  export class Voice {
5
5
  free(): void;
6
6
  [Symbol.dispose](): void;
7
+ /**
8
+ * Start time in seconds of each token of `phonemes(text)`, `/` between words included and a
9
+ * `,` added when the text ends without a pause, then the total length.
10
+ */
11
+ cues(text: string): Float32Array;
7
12
  constructor();
8
13
  speak(text: string): Float32Array;
9
14
  wav(text: string): Uint8Array;
15
+ cutoff: number;
10
16
  pitch: number;
11
17
  sample_rate: number;
18
+ get source(): Float32Array;
19
+ set source(value: Float32Array | number[]);
12
20
  speed: number;
21
+ tract: number;
22
+ width: number;
13
23
  }
14
24
 
15
25
  export function phonemes(text: string): string;
@@ -18,21 +28,30 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
18
28
 
19
29
  export interface InitOutput {
20
30
  readonly memory: WebAssembly.Memory;
31
+ readonly __wbg_get_voice_cutoff: (a: number) => number;
21
32
  readonly __wbg_get_voice_pitch: (a: number) => number;
22
33
  readonly __wbg_get_voice_sample_rate: (a: number) => number;
34
+ readonly __wbg_get_voice_source: (a: number) => [number, number];
23
35
  readonly __wbg_get_voice_speed: (a: number) => number;
36
+ readonly __wbg_get_voice_tract: (a: number) => number;
37
+ readonly __wbg_get_voice_width: (a: number) => number;
38
+ readonly __wbg_set_voice_cutoff: (a: number, b: number) => void;
24
39
  readonly __wbg_set_voice_pitch: (a: number, b: number) => void;
25
40
  readonly __wbg_set_voice_sample_rate: (a: number, b: number) => void;
41
+ readonly __wbg_set_voice_source: (a: number, b: number, c: number) => void;
26
42
  readonly __wbg_set_voice_speed: (a: number, b: number) => void;
43
+ readonly __wbg_set_voice_tract: (a: number, b: number) => void;
44
+ readonly __wbg_set_voice_width: (a: number, b: number) => void;
27
45
  readonly __wbg_voice_free: (a: number, b: number) => void;
28
46
  readonly phonemes: (a: number, b: number) => [number, number];
47
+ readonly voice_cues: (a: number, b: number, c: number) => [number, number];
29
48
  readonly voice_new: () => number;
30
49
  readonly voice_speak: (a: number, b: number, c: number) => [number, number];
31
50
  readonly voice_wav: (a: number, b: number, c: number) => [number, number];
32
51
  readonly __wbindgen_externrefs: WebAssembly.Table;
52
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
33
53
  readonly __wbindgen_malloc: (a: number, b: number) => number;
34
54
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
35
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
36
55
  readonly __wbindgen_start: () => void;
37
56
  }
38
57
 
package/samiam.js CHANGED
@@ -11,6 +11,13 @@ export class Voice {
11
11
  const ptr = this.__destroy_into_raw();
12
12
  wasm.__wbg_voice_free(ptr, 0);
13
13
  }
14
+ /**
15
+ * @returns {number}
16
+ */
17
+ get cutoff() {
18
+ const ret = wasm.__wbg_get_voice_cutoff(this.__wbg_ptr);
19
+ return ret;
20
+ }
14
21
  /**
15
22
  * @returns {number}
16
23
  */
@@ -25,6 +32,15 @@ export class Voice {
25
32
  const ret = wasm.__wbg_get_voice_sample_rate(this.__wbg_ptr);
26
33
  return ret >>> 0;
27
34
  }
35
+ /**
36
+ * @returns {Float32Array}
37
+ */
38
+ get source() {
39
+ const ret = wasm.__wbg_get_voice_source(this.__wbg_ptr);
40
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
41
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
42
+ return v1;
43
+ }
28
44
  /**
29
45
  * @returns {number}
30
46
  */
@@ -32,6 +48,26 @@ export class Voice {
32
48
  const ret = wasm.__wbg_get_voice_speed(this.__wbg_ptr);
33
49
  return ret;
34
50
  }
51
+ /**
52
+ * @returns {number}
53
+ */
54
+ get tract() {
55
+ const ret = wasm.__wbg_get_voice_tract(this.__wbg_ptr);
56
+ return ret;
57
+ }
58
+ /**
59
+ * @returns {number}
60
+ */
61
+ get width() {
62
+ const ret = wasm.__wbg_get_voice_width(this.__wbg_ptr);
63
+ return ret;
64
+ }
65
+ /**
66
+ * @param {number} arg0
67
+ */
68
+ set cutoff(arg0) {
69
+ wasm.__wbg_set_voice_cutoff(this.__wbg_ptr, arg0);
70
+ }
35
71
  /**
36
72
  * @param {number} arg0
37
73
  */
@@ -44,12 +80,46 @@ export class Voice {
44
80
  set sample_rate(arg0) {
45
81
  wasm.__wbg_set_voice_sample_rate(this.__wbg_ptr, arg0);
46
82
  }
83
+ /**
84
+ * @param {Float32Array | number[]} arg0
85
+ */
86
+ set source(arg0) {
87
+ const ptr0 = passArrayF32ToWasm0(arg0, wasm.__wbindgen_malloc);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ wasm.__wbg_set_voice_source(this.__wbg_ptr, ptr0, len0);
90
+ }
47
91
  /**
48
92
  * @param {number} arg0
49
93
  */
50
94
  set speed(arg0) {
51
95
  wasm.__wbg_set_voice_speed(this.__wbg_ptr, arg0);
52
96
  }
97
+ /**
98
+ * @param {number} arg0
99
+ */
100
+ set tract(arg0) {
101
+ wasm.__wbg_set_voice_tract(this.__wbg_ptr, arg0);
102
+ }
103
+ /**
104
+ * @param {number} arg0
105
+ */
106
+ set width(arg0) {
107
+ wasm.__wbg_set_voice_width(this.__wbg_ptr, arg0);
108
+ }
109
+ /**
110
+ * Start time in seconds of each token of `phonemes(text)`, `/` between words included and a
111
+ * `,` added when the text ends without a pause, then the total length.
112
+ * @param {string} text
113
+ * @returns {Float32Array}
114
+ */
115
+ cues(text) {
116
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
117
+ const len0 = WASM_VECTOR_LEN;
118
+ const ret = wasm.voice_cues(this.__wbg_ptr, ptr0, len0);
119
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
120
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
121
+ return v2;
122
+ }
53
123
  constructor() {
54
124
  const ret = wasm.voice_new();
55
125
  this.__wbg_ptr = ret;
@@ -104,17 +174,16 @@ export function phonemes(text) {
104
174
  function __wbg_get_imports() {
105
175
  const import0 = {
106
176
  __proto__: null,
107
- __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
177
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
108
178
  throw new Error(getStringFromWasm0(arg0, arg1));
109
179
  },
110
180
  __wbindgen_init_externref_table: function() {
111
181
  const table = wasm.__wbindgen_externrefs;
112
- const offset = table.grow(4);
113
182
  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);
183
+ table.set(1024, undefined);
184
+ table.set(1025, null);
185
+ table.set(1026, true);
186
+ table.set(1027, false);
118
187
  },
119
188
  };
120
189
  return {
@@ -146,7 +215,8 @@ function getFloat32ArrayMemory0() {
146
215
  }
147
216
 
148
217
  function getStringFromWasm0(ptr, len) {
149
- return decodeText(ptr >>> 0, len);
218
+ ptr = ptr >>> 0;
219
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
150
220
  }
151
221
 
152
222
  let cachedUint8ArrayMemory0 = null;
@@ -157,6 +227,13 @@ function getUint8ArrayMemory0() {
157
227
  return cachedUint8ArrayMemory0;
158
228
  }
159
229
 
230
+ function passArrayF32ToWasm0(arg, malloc) {
231
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
232
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
233
+ WASM_VECTOR_LEN = arg.length;
234
+ return ptr;
235
+ }
236
+
160
237
  function passStringToWasm0(arg, malloc, realloc) {
161
238
  if (realloc === undefined) {
162
239
  const buf = cachedTextEncoder.encode(arg);
@@ -194,18 +271,18 @@ function passStringToWasm0(arg, malloc, realloc) {
194
271
  return ptr;
195
272
  }
196
273
 
197
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
274
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
198
275
  cachedTextDecoder.decode();
199
276
  const MAX_SAFARI_DECODE_BYTES = 2146435072;
200
277
  let numBytesDecoded = 0;
201
- function decodeText(ptr, len) {
202
- numBytesDecoded += len;
278
+ function decodeText(bytes) {
279
+ numBytesDecoded += bytes.length;
203
280
  if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
204
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
281
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
205
282
  cachedTextDecoder.decode();
206
- numBytesDecoded = len;
283
+ numBytesDecoded = bytes.length;
207
284
  }
208
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
285
+ return cachedTextDecoder.decode(bytes);
209
286
  }
210
287
 
211
288
  const cachedTextEncoder = new TextEncoder();
@@ -293,9 +370,17 @@ function initSync(module) {
293
370
  return __wbg_finalize_init(instance, module);
294
371
  }
295
372
 
373
+ let __wbg_init_promise;
296
374
  async function __wbg_init(module_or_path) {
297
375
  if (wasm !== undefined) return wasm;
376
+ if (__wbg_init_promise === undefined) {
377
+ __wbg_init_promise = __wbg_init_once(module_or_path);
378
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
379
+ }
380
+ return __wbg_init_promise;
381
+ }
298
382
 
383
+ async function __wbg_init_once(module_or_path) {
299
384
 
300
385
  if (module_or_path !== undefined) {
301
386
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
package/samiam_bg.wasm CHANGED
Binary file