@mumble-speech/web 0.0.0-stage → 0.1.1-rc.1

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.
@@ -0,0 +1,451 @@
1
+ /* @ts-self-types="./mumble.d.ts" */
2
+
3
+ export class RenderResult {
4
+ static __wrap(ptr) {
5
+ const obj = Object.create(RenderResult.prototype);
6
+ obj.__wbg_ptr = ptr;
7
+ RenderResultFinalization.register(obj, obj.__wbg_ptr, obj);
8
+ return obj;
9
+ }
10
+ __destroy_into_raw() {
11
+ const ptr = this.__wbg_ptr;
12
+ this.__wbg_ptr = 0;
13
+ RenderResultFinalization.unregister(this);
14
+ return ptr;
15
+ }
16
+ free() {
17
+ const ptr = this.__destroy_into_raw();
18
+ wasm.__wbg_renderresult_free(ptr, 0);
19
+ }
20
+ /**
21
+ * @returns {number}
22
+ */
23
+ get duration() {
24
+ const ret = wasm.renderresult_duration(this.__wbg_ptr);
25
+ return ret;
26
+ }
27
+ /**
28
+ * @returns {Float64Array}
29
+ */
30
+ takeEvents() {
31
+ const ret = wasm.renderresult_takeEvents(this.__wbg_ptr);
32
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
33
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
34
+ return v1;
35
+ }
36
+ /**
37
+ * Moves the samples out; call once.
38
+ * @returns {Float32Array}
39
+ */
40
+ takeSamples() {
41
+ const ret = wasm.renderresult_takeSamples(this.__wbg_ptr);
42
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
43
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
44
+ return v1;
45
+ }
46
+ }
47
+ if (Symbol.dispose) RenderResult.prototype[Symbol.dispose] = RenderResult.prototype.free;
48
+
49
+ export class Speaker {
50
+ __destroy_into_raw() {
51
+ const ptr = this.__wbg_ptr;
52
+ this.__wbg_ptr = 0;
53
+ SpeakerFinalization.unregister(this);
54
+ return ptr;
55
+ }
56
+ free() {
57
+ const ptr = this.__destroy_into_raw();
58
+ wasm.__wbg_speaker_free(ptr, 0);
59
+ }
60
+ /**
61
+ * @param {number} style
62
+ * @param {number} pitch
63
+ * @param {number} speed
64
+ * @param {number} variation
65
+ * @param {number} seed
66
+ * @param {number} sample_rate
67
+ */
68
+ constructor(style, pitch, speed, variation, seed, sample_rate) {
69
+ const ret = wasm.speaker_new(style, pitch, speed, variation, seed, sample_rate);
70
+ if (ret[2]) {
71
+ throw takeFromExternrefTable0(ret[1]);
72
+ }
73
+ this.__wbg_ptr = ret[0];
74
+ SpeakerFinalization.register(this, this.__wbg_ptr, this);
75
+ return this;
76
+ }
77
+ /**
78
+ * @param {string} text
79
+ * @returns {Utterance}
80
+ */
81
+ next(text) {
82
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ret = wasm.speaker_next(this.__wbg_ptr, ptr0, len0);
85
+ return Utterance.__wrap(ret);
86
+ }
87
+ reset() {
88
+ wasm.speaker_reset(this.__wbg_ptr);
89
+ }
90
+ }
91
+ if (Symbol.dispose) Speaker.prototype[Symbol.dispose] = Speaker.prototype.free;
92
+
93
+ export class Utterance {
94
+ static __wrap(ptr) {
95
+ const obj = Object.create(Utterance.prototype);
96
+ obj.__wbg_ptr = ptr;
97
+ UtteranceFinalization.register(obj, obj.__wbg_ptr, obj);
98
+ return obj;
99
+ }
100
+ __destroy_into_raw() {
101
+ const ptr = this.__wbg_ptr;
102
+ this.__wbg_ptr = 0;
103
+ UtteranceFinalization.unregister(this);
104
+ return ptr;
105
+ }
106
+ free() {
107
+ const ptr = this.__destroy_into_raw();
108
+ wasm.__wbg_utterance_free(ptr, 0);
109
+ }
110
+ /**
111
+ * @returns {number}
112
+ */
113
+ get advance() {
114
+ const ret = wasm.utterance_advance(this.__wbg_ptr);
115
+ return ret;
116
+ }
117
+ /**
118
+ * Style index of the sound (0 beep, 1 grunt, 2 alphabet), or −1 when nothing sounded.
119
+ * @returns {number}
120
+ */
121
+ get soundStyle() {
122
+ const ret = wasm.utterance_soundStyle(this.__wbg_ptr);
123
+ return ret;
124
+ }
125
+ /**
126
+ * @returns {number}
127
+ */
128
+ get soundVariant() {
129
+ const ret = wasm.utterance_soundVariant(this.__wbg_ptr);
130
+ return ret;
131
+ }
132
+ /**
133
+ * @returns {Float32Array}
134
+ */
135
+ takeSamples() {
136
+ const ret = wasm.utterance_takeSamples(this.__wbg_ptr);
137
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
138
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
139
+ return v1;
140
+ }
141
+ }
142
+ if (Symbol.dispose) Utterance.prototype[Symbol.dispose] = Utterance.prototype.free;
143
+
144
+ /**
145
+ * @param {Float32Array} samples
146
+ * @param {number} sample_rate
147
+ * @returns {Uint8Array}
148
+ */
149
+ export function encodeWav(samples, sample_rate) {
150
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
151
+ const len0 = WASM_VECTOR_LEN;
152
+ const ret = wasm.encodeWav(ptr0, len0, sample_rate);
153
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
154
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
155
+ return v2;
156
+ }
157
+
158
+ /**
159
+ * @param {string} text
160
+ * @param {number} style
161
+ * @param {number} pitch
162
+ * @param {number} speed
163
+ * @param {number} variation
164
+ * @param {number} seed
165
+ * @param {number} sample_rate
166
+ * @returns {RenderResult}
167
+ */
168
+ export function render(text, style, pitch, speed, variation, seed, sample_rate) {
169
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
+ const len0 = WASM_VECTOR_LEN;
171
+ const ret = wasm.render(ptr0, len0, style, pitch, speed, variation, seed, sample_rate);
172
+ if (ret[2]) {
173
+ throw takeFromExternrefTable0(ret[1]);
174
+ }
175
+ return RenderResult.__wrap(ret[0]);
176
+ }
177
+
178
+ /**
179
+ * @param {string} text
180
+ * @param {number} style
181
+ * @param {number} pitch
182
+ * @param {number} speed
183
+ * @param {number} variation
184
+ * @param {number} seed
185
+ * @returns {RenderResult}
186
+ */
187
+ export function timeline(text, style, pitch, speed, variation, seed) {
188
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
189
+ const len0 = WASM_VECTOR_LEN;
190
+ const ret = wasm.timeline(ptr0, len0, style, pitch, speed, variation, seed);
191
+ if (ret[2]) {
192
+ throw takeFromExternrefTable0(ret[1]);
193
+ }
194
+ return RenderResult.__wrap(ret[0]);
195
+ }
196
+ function __wbg_get_imports() {
197
+ const import0 = {
198
+ __proto__: null,
199
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
200
+ const ret = Error(getStringFromWasm0(arg0, arg1));
201
+ return ret;
202
+ },
203
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
204
+ throw new Error(getStringFromWasm0(arg0, arg1));
205
+ },
206
+ __wbindgen_init_externref_table: function() {
207
+ const table = wasm.__wbindgen_externrefs;
208
+ const offset = table.grow(4);
209
+ table.set(0, undefined);
210
+ table.set(offset + 0, undefined);
211
+ table.set(offset + 1, null);
212
+ table.set(offset + 2, true);
213
+ table.set(offset + 3, false);
214
+ },
215
+ };
216
+ return {
217
+ __proto__: null,
218
+ "./mumble_bg.js": import0,
219
+ };
220
+ }
221
+
222
+ const RenderResultFinalization = (typeof FinalizationRegistry === 'undefined')
223
+ ? { register: () => {}, unregister: () => {} }
224
+ : new FinalizationRegistry(ptr => wasm.__wbg_renderresult_free(ptr, 1));
225
+ const SpeakerFinalization = (typeof FinalizationRegistry === 'undefined')
226
+ ? { register: () => {}, unregister: () => {} }
227
+ : new FinalizationRegistry(ptr => wasm.__wbg_speaker_free(ptr, 1));
228
+ const UtteranceFinalization = (typeof FinalizationRegistry === 'undefined')
229
+ ? { register: () => {}, unregister: () => {} }
230
+ : new FinalizationRegistry(ptr => wasm.__wbg_utterance_free(ptr, 1));
231
+
232
+ function getArrayF32FromWasm0(ptr, len) {
233
+ ptr = ptr >>> 0;
234
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
235
+ }
236
+
237
+ function getArrayF64FromWasm0(ptr, len) {
238
+ ptr = ptr >>> 0;
239
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
240
+ }
241
+
242
+ function getArrayU8FromWasm0(ptr, len) {
243
+ ptr = ptr >>> 0;
244
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
245
+ }
246
+
247
+ let cachedFloat32ArrayMemory0 = null;
248
+ function getFloat32ArrayMemory0() {
249
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
250
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
251
+ }
252
+ return cachedFloat32ArrayMemory0;
253
+ }
254
+
255
+ let cachedFloat64ArrayMemory0 = null;
256
+ function getFloat64ArrayMemory0() {
257
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
258
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
259
+ }
260
+ return cachedFloat64ArrayMemory0;
261
+ }
262
+
263
+ function getStringFromWasm0(ptr, len) {
264
+ return decodeText(ptr >>> 0, len);
265
+ }
266
+
267
+ let cachedUint8ArrayMemory0 = null;
268
+ function getUint8ArrayMemory0() {
269
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
270
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
271
+ }
272
+ return cachedUint8ArrayMemory0;
273
+ }
274
+
275
+ function passArrayF32ToWasm0(arg, malloc) {
276
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
277
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
278
+ WASM_VECTOR_LEN = arg.length;
279
+ return ptr;
280
+ }
281
+
282
+ function passStringToWasm0(arg, malloc, realloc) {
283
+ if (realloc === undefined) {
284
+ const buf = cachedTextEncoder.encode(arg);
285
+ const ptr = malloc(buf.length, 1) >>> 0;
286
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
287
+ WASM_VECTOR_LEN = buf.length;
288
+ return ptr;
289
+ }
290
+
291
+ let len = arg.length;
292
+ let ptr = malloc(len, 1) >>> 0;
293
+
294
+ const mem = getUint8ArrayMemory0();
295
+
296
+ let offset = 0;
297
+
298
+ for (; offset < len; offset++) {
299
+ const code = arg.charCodeAt(offset);
300
+ if (code > 0x7F) break;
301
+ mem[ptr + offset] = code;
302
+ }
303
+ if (offset !== len) {
304
+ if (offset !== 0) {
305
+ arg = arg.slice(offset);
306
+ }
307
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
308
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
309
+ const ret = cachedTextEncoder.encodeInto(arg, view);
310
+
311
+ offset += ret.written;
312
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
313
+ }
314
+
315
+ WASM_VECTOR_LEN = offset;
316
+ return ptr;
317
+ }
318
+
319
+ function takeFromExternrefTable0(idx) {
320
+ const value = wasm.__wbindgen_externrefs.get(idx);
321
+ wasm.__externref_table_dealloc(idx);
322
+ return value;
323
+ }
324
+
325
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
326
+ cachedTextDecoder.decode();
327
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
328
+ let numBytesDecoded = 0;
329
+ function decodeText(ptr, len) {
330
+ numBytesDecoded += len;
331
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
332
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
333
+ cachedTextDecoder.decode();
334
+ numBytesDecoded = len;
335
+ }
336
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
337
+ }
338
+
339
+ const cachedTextEncoder = new TextEncoder();
340
+
341
+ if (!('encodeInto' in cachedTextEncoder)) {
342
+ cachedTextEncoder.encodeInto = function (arg, view) {
343
+ const buf = cachedTextEncoder.encode(arg);
344
+ view.set(buf);
345
+ return {
346
+ read: arg.length,
347
+ written: buf.length
348
+ };
349
+ };
350
+ }
351
+
352
+ let WASM_VECTOR_LEN = 0;
353
+
354
+ let wasmModule, wasmInstance, wasm;
355
+ function __wbg_finalize_init(instance, module) {
356
+ wasmInstance = instance;
357
+ wasm = instance.exports;
358
+ wasmModule = module;
359
+ cachedFloat32ArrayMemory0 = null;
360
+ cachedFloat64ArrayMemory0 = null;
361
+ cachedUint8ArrayMemory0 = null;
362
+ wasm.__wbindgen_start();
363
+ return wasm;
364
+ }
365
+
366
+ async function __wbg_load(module, imports) {
367
+ if (typeof Response === 'function' && module instanceof Response) {
368
+ if (!module.ok) {
369
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
370
+ }
371
+
372
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
373
+ try {
374
+ return await WebAssembly.instantiateStreaming(module, imports);
375
+ } catch (e) {
376
+ const validResponse = expectedResponseType(module.type);
377
+
378
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
379
+ 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);
380
+
381
+ } else { throw e; }
382
+ }
383
+ }
384
+
385
+ const bytes = await module.arrayBuffer();
386
+ return await WebAssembly.instantiate(bytes, imports);
387
+ } else {
388
+ const instance = await WebAssembly.instantiate(module, imports);
389
+
390
+ if (instance instanceof WebAssembly.Instance) {
391
+ return { instance, module };
392
+ } else {
393
+ return instance;
394
+ }
395
+ }
396
+
397
+ function expectedResponseType(type) {
398
+ switch (type) {
399
+ case 'basic': case 'cors': case 'default': return true;
400
+ }
401
+ return false;
402
+ }
403
+ }
404
+
405
+ function initSync(module) {
406
+ if (wasm !== undefined) return wasm;
407
+
408
+
409
+ if (module !== undefined) {
410
+ if (Object.getPrototypeOf(module) === Object.prototype) {
411
+ ({module} = module)
412
+ } else {
413
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
414
+ }
415
+ }
416
+
417
+ const imports = __wbg_get_imports();
418
+ if (!(module instanceof WebAssembly.Module)) {
419
+ module = new WebAssembly.Module(module);
420
+ }
421
+ const instance = new WebAssembly.Instance(module, imports);
422
+ return __wbg_finalize_init(instance, module);
423
+ }
424
+
425
+ async function __wbg_init(module_or_path) {
426
+ if (wasm !== undefined) return wasm;
427
+
428
+
429
+ if (module_or_path !== undefined) {
430
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
431
+ ({module_or_path} = module_or_path)
432
+ } else {
433
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
434
+ }
435
+ }
436
+
437
+ if (module_or_path === undefined) {
438
+ module_or_path = new URL('mumble_bg.wasm', import.meta.url);
439
+ }
440
+ const imports = __wbg_get_imports();
441
+
442
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
443
+ module_or_path = fetch(module_or_path);
444
+ }
445
+
446
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
447
+
448
+ return __wbg_finalize_init(instance, module);
449
+ }
450
+
451
+ export { initSync, __wbg_init as default };
@@ -0,0 +1 @@
1
+ export declare const WASM_BASE64: string;