hume 0.13.4 → 0.13.6

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.
Files changed (50) hide show
  1. package/.mock/definition/empathic-voice/__package__.yml +8 -3
  2. package/.mock/definition/tts/__package__.yml +4 -0
  3. package/.mock/definition/tts/streamInput.yml +30 -2
  4. package/.mock/fern.config.json +1 -1
  5. package/Client.js +10 -3
  6. package/api/resources/empathicVoice/types/ReturnConfig.d.ts +2 -2
  7. package/api/resources/empathicVoice/types/SessionSettings.d.ts +2 -0
  8. package/api/resources/index.d.ts +1 -1
  9. package/api/resources/index.js +2 -2
  10. package/api/resources/tts/types/SnippetAudioChunk.d.ts +5 -0
  11. package/dist/Client.js +10 -3
  12. package/dist/api/resources/empathicVoice/types/ReturnConfig.d.ts +2 -2
  13. package/dist/api/resources/empathicVoice/types/SessionSettings.d.ts +2 -0
  14. package/dist/api/resources/index.d.ts +1 -1
  15. package/dist/api/resources/index.js +2 -2
  16. package/dist/api/resources/tts/types/SnippetAudioChunk.d.ts +5 -0
  17. package/dist/serialization/resources/empathicVoice/types/ReturnConfig.d.ts +1 -1
  18. package/dist/serialization/resources/empathicVoice/types/ReturnConfig.js +1 -1
  19. package/dist/serialization/resources/empathicVoice/types/SessionSettings.d.ts +1 -0
  20. package/dist/serialization/resources/empathicVoice/types/SessionSettings.js +1 -0
  21. package/dist/serialization/resources/index.d.ts +1 -1
  22. package/dist/serialization/resources/index.js +2 -2
  23. package/dist/serialization/resources/tts/types/SnippetAudioChunk.d.ts +1 -0
  24. package/dist/serialization/resources/tts/types/SnippetAudioChunk.js +1 -0
  25. package/dist/version.d.ts +1 -1
  26. package/dist/version.js +1 -1
  27. package/dist/wrapper/SilenceFiller.d.ts +85 -0
  28. package/dist/wrapper/SilenceFiller.js +203 -0
  29. package/dist/wrapper/collate.d.ts +36 -0
  30. package/dist/wrapper/collate.js +126 -0
  31. package/dist/wrapper/index.d.ts +2 -0
  32. package/dist/wrapper/index.js +5 -1
  33. package/package.json +1 -1
  34. package/reference.md +702 -702
  35. package/serialization/resources/empathicVoice/types/ReturnConfig.d.ts +1 -1
  36. package/serialization/resources/empathicVoice/types/ReturnConfig.js +1 -1
  37. package/serialization/resources/empathicVoice/types/SessionSettings.d.ts +1 -0
  38. package/serialization/resources/empathicVoice/types/SessionSettings.js +1 -0
  39. package/serialization/resources/index.d.ts +1 -1
  40. package/serialization/resources/index.js +2 -2
  41. package/serialization/resources/tts/types/SnippetAudioChunk.d.ts +1 -0
  42. package/serialization/resources/tts/types/SnippetAudioChunk.js +1 -0
  43. package/version.d.ts +1 -1
  44. package/version.js +1 -1
  45. package/wrapper/SilenceFiller.d.ts +85 -0
  46. package/wrapper/SilenceFiller.js +203 -0
  47. package/wrapper/collate.d.ts +36 -0
  48. package/wrapper/collate.js +126 -0
  49. package/wrapper/index.d.ts +2 -0
  50. package/wrapper/index.js +5 -1
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Takes an async iterator that yields interleaved items from different groups
3
+ * and produces an iterator that yields items in group order.
4
+ *
5
+ * Example:
6
+ * Input: A1, B1, A2, A3 (final), C1, C2, C3 (final), B2 (final)
7
+ * Output: A1, A2, A3, B1, B2, C1, C2, C3
8
+ *
9
+ * This is useful when using synthesizeJsonStreaming with num_generations > 1
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ *
14
+ * import { collate } from 'hume';
15
+ *
16
+ * const stream = hume.synthesizeJsonStreaming({
17
+ * ...
18
+ * })
19
+ *
20
+ * const contiguous = collate(
21
+ * stream
22
+ * (chunk) => chunk.generationId,
23
+ * (chunk) => chunk.isLastChunk
24
+ * );
25
+ *
26
+ * for await (const item of contiguous) {
27
+ * audioPlayer.write(item.audio)
28
+ * }
29
+ * ```
30
+ *
31
+ * @param source - Async iterable that yields interleaved items.
32
+ * @param groupBy - Function to determine a "key" that determines the group identity for each item.
33
+ * @param isFinal - Function to determine if an item is the final item in its group.
34
+ * @returns An async iterable that yields items in group order.
35
+ */
36
+ export declare function collate<TItem, TKey>(source: AsyncIterable<TItem>, groupBy: (x: TItem) => TKey, isFinal: (x: TItem) => boolean): AsyncIterable<TItem>;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var m = o[Symbol.asyncIterator], i;
5
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
6
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
7
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
+ };
9
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
10
+ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
11
+ var i, p;
12
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
13
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
14
+ };
15
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
16
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
18
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
19
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
20
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
21
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
22
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
23
+ function fulfill(value) { resume("next", value); }
24
+ function reject(value) { resume("throw", value); }
25
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.collate = collate;
29
+ /**
30
+ * Takes an async iterator that yields interleaved items from different groups
31
+ * and produces an iterator that yields items in group order.
32
+ *
33
+ * Example:
34
+ * Input: A1, B1, A2, A3 (final), C1, C2, C3 (final), B2 (final)
35
+ * Output: A1, A2, A3, B1, B2, C1, C2, C3
36
+ *
37
+ * This is useful when using synthesizeJsonStreaming with num_generations > 1
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ *
42
+ * import { collate } from 'hume';
43
+ *
44
+ * const stream = hume.synthesizeJsonStreaming({
45
+ * ...
46
+ * })
47
+ *
48
+ * const contiguous = collate(
49
+ * stream
50
+ * (chunk) => chunk.generationId,
51
+ * (chunk) => chunk.isLastChunk
52
+ * );
53
+ *
54
+ * for await (const item of contiguous) {
55
+ * audioPlayer.write(item.audio)
56
+ * }
57
+ * ```
58
+ *
59
+ * @param source - Async iterable that yields interleaved items.
60
+ * @param groupBy - Function to determine a "key" that determines the group identity for each item.
61
+ * @param isFinal - Function to determine if an item is the final item in its group.
62
+ * @returns An async iterable that yields items in group order.
63
+ */
64
+ function collate(source, groupBy, isFinal) {
65
+ return __asyncGenerator(this, arguments, function* collate_1() {
66
+ var _a, e_1, _b, _c;
67
+ const buffers = new Map();
68
+ const order = [];
69
+ let current;
70
+ const ensure = (k) => {
71
+ if (!buffers.has(k)) {
72
+ buffers.set(k, []);
73
+ order.push(k);
74
+ }
75
+ };
76
+ const flushGroup = function* (k) {
77
+ const buf = buffers.get(k);
78
+ if (!buf)
79
+ return;
80
+ for (const item of buf)
81
+ yield item;
82
+ buffers.delete(k);
83
+ };
84
+ const nextGroup = () => {
85
+ // pop the next group in first-seen order that still has a buffer
86
+ while (order.length && !buffers.has(order[0]))
87
+ order.shift();
88
+ return order.shift();
89
+ };
90
+ try {
91
+ for (var _d = true, source_1 = __asyncValues(source), source_1_1; source_1_1 = yield __await(source_1.next()), _a = source_1_1.done, !_a; _d = true) {
92
+ _c = source_1_1.value;
93
+ _d = false;
94
+ const item = _c;
95
+ const k = groupBy(item);
96
+ if (current === undefined)
97
+ current = k;
98
+ ensure(k);
99
+ buffers.get(k).push(item);
100
+ // if we just saw the final item for the current group, flush it and advance
101
+ if (k === current && isFinal(item)) {
102
+ yield __await(yield* __asyncDelegator(__asyncValues(flushGroup(current))));
103
+ current = nextGroup();
104
+ }
105
+ }
106
+ }
107
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
108
+ finally {
109
+ try {
110
+ if (!_d && !_a && (_b = source_1.return)) yield __await(_b.call(source_1));
111
+ }
112
+ finally { if (e_1) throw e_1.error; }
113
+ }
114
+ // stream ended; flush remaining groups in first-seen order
115
+ if (current !== undefined) {
116
+ if (buffers.has(current))
117
+ yield __await(yield* __asyncDelegator(__asyncValues(flushGroup(current))));
118
+ while (true) {
119
+ const k = nextGroup();
120
+ if (k === undefined)
121
+ break;
122
+ yield __await(yield* __asyncDelegator(__asyncValues(flushGroup(k))));
123
+ }
124
+ }
125
+ });
126
+ }
@@ -9,3 +9,5 @@ export { getAudioStream } from "./getAudioStream";
9
9
  export { MimeType, getBrowserSupportedMimeType } from "./getBrowserSupportedMimeType";
10
10
  export { HumeClient } from "./HumeClient";
11
11
  export { EVIWebAudioPlayer, EVIWebAudioPlayerFFTOptions, EVIWebAudioPlayerOptions } from "./EVIWebAudioPlayer";
12
+ export { collate } from "./collate";
13
+ export { SilenceFiller } from "./SilenceFiller";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EVIWebAudioPlayer = exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.fetchAccessToken = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
3
+ exports.SilenceFiller = exports.collate = exports.EVIWebAudioPlayer = exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.fetchAccessToken = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
4
4
  var base64Decode_1 = require("./base64Decode");
5
5
  Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64Decode_1.base64Decode; } });
6
6
  var base64Encode_1 = require("./base64Encode");
@@ -24,3 +24,7 @@ var HumeClient_1 = require("./HumeClient");
24
24
  Object.defineProperty(exports, "HumeClient", { enumerable: true, get: function () { return HumeClient_1.HumeClient; } });
25
25
  var EVIWebAudioPlayer_1 = require("./EVIWebAudioPlayer");
26
26
  Object.defineProperty(exports, "EVIWebAudioPlayer", { enumerable: true, get: function () { return EVIWebAudioPlayer_1.EVIWebAudioPlayer; } });
27
+ var collate_1 = require("./collate");
28
+ Object.defineProperty(exports, "collate", { enumerable: true, get: function () { return collate_1.collate; } });
29
+ var SilenceFiller_1 = require("./SilenceFiller");
30
+ Object.defineProperty(exports, "SilenceFiller", { enumerable: true, get: function () { return SilenceFiller_1.SilenceFiller; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hume",
3
- "version": "0.13.4",
3
+ "version": "0.13.6",
4
4
  "private": false,
5
5
  "repository": "https://github.com/HumeAI/hume-typescript-sdk",
6
6
  "main": "./index.js",