hume 0.13.3 → 0.13.5

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 (91) hide show
  1. package/api/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +1 -5
  2. package/api/resources/empathicVoice/types/AssistantInput.d.ts +1 -1
  3. package/api/resources/empathicVoice/types/AssistantMessage.d.ts +1 -1
  4. package/api/resources/empathicVoice/types/ChatMetadata.d.ts +2 -2
  5. package/api/resources/empathicVoice/types/PauseAssistantMessage.d.ts +1 -1
  6. package/api/resources/empathicVoice/types/SessionSettings.d.ts +9 -7
  7. package/api/resources/empathicVoice/types/ToolCallMessage.d.ts +1 -1
  8. package/api/resources/empathicVoice/types/ToolErrorMessage.d.ts +2 -2
  9. package/api/resources/empathicVoice/types/ToolResponseMessage.d.ts +3 -3
  10. package/api/resources/empathicVoice/types/UserMessage.d.ts +3 -3
  11. package/api/resources/tts/types/PublishTts.d.ts +23 -0
  12. package/api/resources/tts/types/PublishTts.js +5 -0
  13. package/api/resources/tts/types/SnippetAudioChunk.d.ts +6 -1
  14. package/api/resources/tts/types/index.d.ts +7 -6
  15. package/api/resources/tts/types/index.js +7 -6
  16. package/dist/api/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +1 -5
  17. package/dist/api/resources/empathicVoice/types/AssistantInput.d.ts +1 -1
  18. package/dist/api/resources/empathicVoice/types/AssistantMessage.d.ts +1 -1
  19. package/dist/api/resources/empathicVoice/types/ChatMetadata.d.ts +2 -2
  20. package/dist/api/resources/empathicVoice/types/PauseAssistantMessage.d.ts +1 -1
  21. package/dist/api/resources/empathicVoice/types/SessionSettings.d.ts +9 -7
  22. package/dist/api/resources/empathicVoice/types/ToolCallMessage.d.ts +1 -1
  23. package/dist/api/resources/empathicVoice/types/ToolErrorMessage.d.ts +2 -2
  24. package/dist/api/resources/empathicVoice/types/ToolResponseMessage.d.ts +3 -3
  25. package/dist/api/resources/empathicVoice/types/UserMessage.d.ts +3 -3
  26. package/dist/api/resources/tts/types/PublishTts.d.ts +23 -0
  27. package/dist/api/resources/tts/types/PublishTts.js +5 -0
  28. package/dist/api/resources/tts/types/SnippetAudioChunk.d.ts +6 -1
  29. package/dist/api/resources/tts/types/index.d.ts +7 -6
  30. package/dist/api/resources/tts/types/index.js +7 -6
  31. package/dist/serialization/resources/empathicVoice/types/SessionSettings.d.ts +1 -0
  32. package/dist/serialization/resources/empathicVoice/types/SessionSettings.js +1 -0
  33. package/dist/serialization/resources/tts/types/PublishTts.d.ts +19 -0
  34. package/dist/serialization/resources/tts/types/PublishTts.js +50 -0
  35. package/dist/serialization/resources/tts/types/SnippetAudioChunk.d.ts +2 -1
  36. package/dist/serialization/resources/tts/types/SnippetAudioChunk.js +2 -1
  37. package/dist/serialization/resources/tts/types/index.d.ts +7 -6
  38. package/dist/serialization/resources/tts/types/index.js +7 -6
  39. package/dist/version.d.ts +1 -1
  40. package/dist/version.js +1 -1
  41. package/dist/wrapper/EVIWebAudioPlayer.d.ts +6 -7
  42. package/dist/wrapper/EVIWebAudioPlayer.js +237 -73
  43. package/dist/wrapper/SilenceFiller.d.ts +85 -0
  44. package/dist/wrapper/SilenceFiller.js +203 -0
  45. package/dist/wrapper/collate.d.ts +36 -0
  46. package/dist/wrapper/collate.js +126 -0
  47. package/dist/wrapper/convertFrequencyScale.d.ts +1 -0
  48. package/dist/wrapper/convertFrequencyScale.js +28 -0
  49. package/dist/wrapper/generateEmptyFft.d.ts +1 -0
  50. package/dist/wrapper/generateEmptyFft.js +6 -0
  51. package/dist/wrapper/index.d.ts +2 -0
  52. package/dist/wrapper/index.js +5 -1
  53. package/package.json +2 -1
  54. package/serialization/resources/empathicVoice/types/SessionSettings.d.ts +1 -0
  55. package/serialization/resources/empathicVoice/types/SessionSettings.js +1 -0
  56. package/serialization/resources/tts/types/PublishTts.d.ts +19 -0
  57. package/serialization/resources/tts/types/PublishTts.js +50 -0
  58. package/serialization/resources/tts/types/SnippetAudioChunk.d.ts +2 -1
  59. package/serialization/resources/tts/types/SnippetAudioChunk.js +2 -1
  60. package/serialization/resources/tts/types/index.d.ts +7 -6
  61. package/serialization/resources/tts/types/index.js +7 -6
  62. package/version.d.ts +1 -1
  63. package/version.js +1 -1
  64. package/wrapper/EVIWebAudioPlayer.d.ts +6 -7
  65. package/wrapper/EVIWebAudioPlayer.js +237 -73
  66. package/wrapper/SilenceFiller.d.ts +85 -0
  67. package/wrapper/SilenceFiller.js +203 -0
  68. package/wrapper/collate.d.ts +36 -0
  69. package/wrapper/collate.js +126 -0
  70. package/wrapper/convertFrequencyScale.d.ts +1 -0
  71. package/wrapper/convertFrequencyScale.js +28 -0
  72. package/wrapper/generateEmptyFft.d.ts +1 -0
  73. package/wrapper/generateEmptyFft.js +6 -0
  74. package/wrapper/index.d.ts +2 -0
  75. package/wrapper/index.js +5 -1
  76. package/.mock/definition/api.yml +0 -12
  77. package/.mock/definition/empathic-voice/__package__.yml +0 -2973
  78. package/.mock/definition/empathic-voice/chat.yml +0 -175
  79. package/.mock/definition/empathic-voice/chatGroups.yml +0 -627
  80. package/.mock/definition/empathic-voice/chatWebhooks.yml +0 -30
  81. package/.mock/definition/empathic-voice/chats.yml +0 -506
  82. package/.mock/definition/empathic-voice/configs.yml +0 -852
  83. package/.mock/definition/empathic-voice/prompts.yml +0 -558
  84. package/.mock/definition/empathic-voice/tools.yml +0 -626
  85. package/.mock/definition/expression-measurement/__package__.yml +0 -1
  86. package/.mock/definition/expression-measurement/batch/__package__.yml +0 -1803
  87. package/.mock/definition/expression-measurement/stream/__package__.yml +0 -113
  88. package/.mock/definition/expression-measurement/stream/stream.yml +0 -438
  89. package/.mock/definition/tts/__package__.yml +0 -660
  90. package/.mock/definition/tts/voices.yml +0 -143
  91. package/.mock/fern.config.json +0 -4
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnclockedSilenceFiller = exports.SilenceFiller = void 0;
4
+ const stream_1 = require("stream");
5
+ /**
6
+ * SilenceFiller is a Readable stream that intersperses incoming audio data
7
+ * with bytes of silence. This is important in some cases to keep an audio
8
+ * stream "alive". Audio players, such as ffmpeg, can interpret inactivity as
9
+ * meaning the stream is ended, or disconnected.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { SilenceFiller } from 'hume';
14
+ *
15
+ * const BYTES_PER_SAMPLE = 2; // 16-bit samples
16
+ * const SAMPLE_RATE = 48000;
17
+ * const BUFFER_SIZE = Math.floor(SAMPLE_RATE * 0.1 * BYTES_PER_SAMPLE); // 100ms buffer
18
+ * const silenceFiller = new SilenceFiller(BUFFER_SIZE, SAMPLE_RATE, BYTES_PER_SAMPLE, 10);
19
+ *
20
+ * // Pipe silence filler output to audio player stdin
21
+ * silenceFiller.pipe(audioPlayer.stdin);
22
+ *
23
+ * // Handle pipe errors
24
+ * silenceFiller.on('error', (err) => {
25
+ * console.error("SilenceFiller error:", err);
26
+ * });
27
+ *
28
+ * // Write audio data as it arrives
29
+ * silenceFiller.writeAudio(audioBuffer);
30
+ *
31
+ * // End the stream when done
32
+ * await silenceFiller.endStream();
33
+ * ```
34
+ */
35
+ class SilenceFiller extends stream_1.Readable {
36
+ /**
37
+ * Creates a new SilenceFiller instance.
38
+ *
39
+ * @param pushIntervalMs - The interval in milliseconds for pushing audio data (default: 5ms).
40
+ * @param sampleRate - The sample rate of the audio (e.g., 48000).
41
+ * @param bytesPerSample - The number of bytes per audio sample (e.g., 2 for 16-bit).
42
+ * @param bufferSize - How much to 'prebuffer'. If you set this too low there
43
+ * is a chance that playback will stutter, but if you set it too high
44
+ * playback will take longer to start.
45
+ */
46
+ constructor(pushIntervalMs = 5, sampleRate = 48000, bytesPerSample = 2, bufferSize = 9600) {
47
+ super({ objectMode: false });
48
+ this.isStarted = false;
49
+ this.pushInterval = null;
50
+ this.unclockedSilenceFiller = new UnclockedSilenceFiller(bufferSize, sampleRate, bytesPerSample);
51
+ this.bytesPerSample = bytesPerSample;
52
+ this.pushIntervalMs = pushIntervalMs;
53
+ }
54
+ /**
55
+ * Writes audio data to the silence filler.
56
+ *
57
+ * @param audioBuffer - The audio buffer to write.
58
+ */
59
+ writeAudio(audioBuffer) {
60
+ const now = Date.now();
61
+ try {
62
+ this.unclockedSilenceFiller.writeAudio(audioBuffer, now);
63
+ if (!this.isStarted && this.unclockedSilenceFiller.donePrebuffering) {
64
+ this.isStarted = true;
65
+ this.startPushInterval();
66
+ }
67
+ }
68
+ catch (error) {
69
+ console.error(`[SilenceFiller] Error writing audio:`, error);
70
+ this.emit("error", error);
71
+ }
72
+ }
73
+ startPushInterval() {
74
+ this.pushInterval = setInterval(() => {
75
+ this.pushData();
76
+ }, this.pushIntervalMs);
77
+ }
78
+ pushData() {
79
+ if (!this.isStarted)
80
+ return;
81
+ try {
82
+ const now = Date.now();
83
+ const audioChunk = this.unclockedSilenceFiller.readAudio(now);
84
+ if (audioChunk && audioChunk.length > 0) {
85
+ // Ensure chunk size is aligned to bytesPerSample
86
+ const alignedChunkSize = Math.floor(audioChunk.length / this.bytesPerSample) * this.bytesPerSample;
87
+ if (alignedChunkSize > 0) {
88
+ const chunk = audioChunk.subarray(0, alignedChunkSize);
89
+ this.push(chunk);
90
+ }
91
+ }
92
+ }
93
+ catch (error) {
94
+ console.error(`[SilenceFiller] Error pushing data:`, error);
95
+ this.emit("error", error);
96
+ }
97
+ }
98
+ _read() { }
99
+ _destroy(error, callback) {
100
+ super._destroy(error, callback);
101
+ }
102
+ /**
103
+ * Ends the stream and drains all remaining audio data.
104
+ *
105
+ * @returns A promise that resolves when the stream has ended.
106
+ */
107
+ endStream() {
108
+ return new Promise((resolve) => {
109
+ // Stop pushing data
110
+ if (this.pushInterval) {
111
+ clearInterval(this.pushInterval);
112
+ this.pushInterval = null;
113
+ }
114
+ // Drain all remaining audio from SilenceFiller
115
+ const now = Date.now();
116
+ // Keep reading until no more audio is available
117
+ while (true) {
118
+ const remainingChunk = this.unclockedSilenceFiller.readAudio(now);
119
+ if (!remainingChunk || remainingChunk.length === 0) {
120
+ break;
121
+ }
122
+ const alignedChunkSize = Math.floor(remainingChunk.length / this.bytesPerSample) * this.bytesPerSample;
123
+ if (alignedChunkSize > 0) {
124
+ const chunk = remainingChunk.subarray(0, alignedChunkSize);
125
+ this.push(chunk);
126
+ }
127
+ }
128
+ this.push(null); // Signal end of stream
129
+ this.once("end", () => {
130
+ resolve();
131
+ });
132
+ });
133
+ }
134
+ }
135
+ exports.SilenceFiller = SilenceFiller;
136
+ /**
137
+ * Does the actual calculation of how interspersing audio with silence
138
+ * is "pure" in the sense that it does not rely on the system clock.
139
+ * It's up to the caller to provide timestamps.
140
+ *
141
+ * @internal
142
+ */
143
+ class UnclockedSilenceFiller {
144
+ constructor(bufferSize, sampleRate, bytesPerSample) {
145
+ this.audioQueue = [];
146
+ this.totalBufferedBytes = 0;
147
+ this.startTimestamp = null;
148
+ this.totalBytesSent = 0;
149
+ this.donePrebuffering = false;
150
+ this.bufferSize = bufferSize;
151
+ this.sampleRate = sampleRate;
152
+ this.bytesPerSample = bytesPerSample;
153
+ }
154
+ writeAudio(audioBuffer, timestamp) {
155
+ this.audioQueue.push(audioBuffer);
156
+ this.totalBufferedBytes += audioBuffer.length;
157
+ if (this.startTimestamp === null) {
158
+ this.startTimestamp = timestamp;
159
+ }
160
+ if (!this.donePrebuffering && this.totalBufferedBytes >= this.bufferSize) {
161
+ this.donePrebuffering = true;
162
+ }
163
+ }
164
+ readAudio(timestamp) {
165
+ if (this.startTimestamp === null || !this.donePrebuffering) {
166
+ return null;
167
+ }
168
+ const elapsedMs = timestamp - this.startTimestamp;
169
+ const targetBytesSent = Math.floor(((this.sampleRate * elapsedMs) / 1000) * this.bytesPerSample);
170
+ const bytesNeeded = targetBytesSent - this.totalBytesSent;
171
+ if (bytesNeeded <= 0) {
172
+ return null;
173
+ }
174
+ // Ensure bytesNeeded is a multiple of bytesPerSample
175
+ const alignedBytesNeeded = Math.floor(bytesNeeded / this.bytesPerSample) * this.bytesPerSample;
176
+ if (alignedBytesNeeded <= 0) {
177
+ return null;
178
+ }
179
+ let chunk = Buffer.alloc(0);
180
+ // Drain from queue until we have enough bytes
181
+ while (chunk.length < alignedBytesNeeded && this.audioQueue.length > 0) {
182
+ const nextBuffer = this.audioQueue.shift();
183
+ chunk = Buffer.concat([chunk, nextBuffer]);
184
+ this.totalBufferedBytes -= nextBuffer.length;
185
+ }
186
+ // If we have more than needed, put the excess back
187
+ if (chunk.length > alignedBytesNeeded) {
188
+ const excess = chunk.subarray(alignedBytesNeeded);
189
+ this.audioQueue.unshift(excess);
190
+ this.totalBufferedBytes += excess.length;
191
+ chunk = chunk.subarray(0, alignedBytesNeeded);
192
+ }
193
+ // Fill remaining with silence if needed
194
+ if (chunk.length < alignedBytesNeeded) {
195
+ const silenceNeeded = Buffer.alloc(alignedBytesNeeded - chunk.length, 0);
196
+ chunk = Buffer.concat([chunk, silenceNeeded]);
197
+ }
198
+ // Update total bytes sent
199
+ this.totalBytesSent += chunk.length;
200
+ return chunk;
201
+ }
202
+ }
203
+ exports.UnclockedSilenceFiller = UnclockedSilenceFiller;
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export declare function convertLinearFrequenciesToBark(linearData: Uint8Array, sampleRate: number): number[];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertLinearFrequenciesToBark = convertLinearFrequenciesToBark;
4
+ // This function converts linear-scaled frequency decibels from an AnalyserNode's frequncy data to Bark scale [https://en.wikipedia.org/wiki/Bark_scale]
5
+ // This implementation uses a simple approach of mapping indices in the linear-scaled array to the closest
6
+ // Bark scale center frequency and is not intended to be an accurate representation, but rather "close-enough" for visualization purposes
7
+ const barkCenterFrequencies = [
8
+ 50, 150, 250, 350, 450, 570, 700, 840, 1000, 1170, 1370, 1600, 1850, 2150, 2500, 2900, 3400, 4000, 4800, 5800, 7000,
9
+ 8500, 10500, 13500,
10
+ ]; // Center frequency value in Hz
11
+ // Min/max values from https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData
12
+ const minValue = 0;
13
+ const maxValue = 255;
14
+ function convertLinearFrequenciesToBark(linearData, sampleRate) {
15
+ const maxFrequency = sampleRate / 2;
16
+ const frequencyResolution = maxFrequency / linearData.length;
17
+ const barkFrequencies = barkCenterFrequencies.map((barkFreq) => {
18
+ var _a;
19
+ const linearDataIndex = Math.round(barkFreq / frequencyResolution);
20
+ if (linearDataIndex >= 0 && linearDataIndex < linearData.length) {
21
+ return ((((_a = linearData[linearDataIndex]) !== null && _a !== void 0 ? _a : 0) - minValue) / (maxValue - minValue)) * 2;
22
+ }
23
+ else {
24
+ return 0;
25
+ }
26
+ });
27
+ return barkFrequencies;
28
+ }
@@ -0,0 +1 @@
1
+ export declare function generateEmptyFft(): number[];
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEmptyFft = generateEmptyFft;
4
+ function generateEmptyFft() {
5
+ return Array.from({ length: 24 }).map(() => 0);
6
+ }
@@ -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";
package/wrapper/index.js CHANGED
@@ -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; } });
@@ -1,12 +0,0 @@
1
- name: api
2
- error-discrimination:
3
- strategy: status-code
4
- default-environment: Production
5
- environments:
6
- Production: https://api.hume.ai
7
- auth: HeaderAuthScheme
8
- auth-schemes:
9
- HeaderAuthScheme:
10
- header: X-Hume-Api-Key
11
- type: optional<string>
12
- name: apiKey