@fonoster/apiserver 0.25.2 → 0.27.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/dist/applications/createGetFnUtil.d.ts +1 -1
- package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +18 -0
- package/dist/applications/validation/createValidationSchema.d.ts +44 -2
- package/dist/voice/VoiceDispatcher.js +1 -0
- package/dist/voice/client/AudioSocketHandler.d.ts +3 -0
- package/dist/voice/client/AudioSocketHandler.js +3 -1
- package/dist/voice/client/VoiceClientImpl.d.ts +8 -0
- package/dist/voice/client/VoiceClientImpl.js +36 -1
- package/dist/voice/filters/AudioFilterFactory.d.ts +35 -0
- package/dist/voice/filters/AudioFilterFactory.js +94 -0
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +64 -0
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +252 -0
- package/dist/voice/filters/aiCoustics/types.d.ts +45 -0
- package/dist/voice/filters/aiCoustics/types.js +29 -0
- package/dist/voice/filters/createAudioFilterChain.d.ts +9 -0
- package/dist/voice/filters/createAudioFilterChain.js +171 -0
- package/dist/voice/filters/createAudioFilterSession.d.ts +15 -0
- package/dist/voice/filters/createAudioFilterSession.js +114 -0
- package/dist/voice/filters/index.d.ts +25 -0
- package/dist/voice/filters/index.js +41 -0
- package/dist/voice/filters/pcm.d.ts +21 -0
- package/dist/voice/filters/pcm.js +37 -0
- package/dist/voice/filters/types.d.ts +61 -0
- package/dist/voice/filters/types.js +26 -0
- package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +11 -0
- package/dist/voice/handlers/createSetAudioFiltersHandler.js +74 -0
- package/dist/voice/handlers/index.d.ts +1 -0
- package/dist/voice/handlers/index.js +1 -0
- package/dist/voice/stt/Deepgram.d.ts +26 -2
- package/dist/voice/stt/Deepgram.js +21 -6
- package/dist/voice/stt/types.d.ts +5 -3
- package/dist/voice/stt/types.js +5 -1
- package/dist/voice/transcribeOnConnection.d.ts +14 -1
- package/dist/voice/transcribeOnConnection.js +67 -2
- package/dist/voice/types/voice.d.ts +2 -0
- package/package.json +13 -10
|
@@ -26,9 +26,9 @@ declare function createGetFnUtil(prisma: Prisma): (ref: string) => Promise<{
|
|
|
26
26
|
};
|
|
27
27
|
ref: string;
|
|
28
28
|
accessKeyId: string;
|
|
29
|
-
endpoint: string;
|
|
30
29
|
type: import(".prisma/client").$Enums.ApplicationType;
|
|
31
30
|
name: string;
|
|
31
|
+
endpoint: string;
|
|
32
32
|
createdAt: Date;
|
|
33
33
|
updatedAt: Date;
|
|
34
34
|
}>;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
declare const assistantWithoutApiKeySchema: z.ZodObject<{
|
|
3
|
+
audioFilters: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
options?: Record<string, unknown>;
|
|
8
|
+
name?: string;
|
|
9
|
+
}, {
|
|
10
|
+
options?: Record<string, unknown>;
|
|
11
|
+
name?: string;
|
|
12
|
+
}>, "many">>;
|
|
3
13
|
conversationSettings: z.ZodObject<{
|
|
4
14
|
firstMessage: z.ZodOptional<z.ZodString>;
|
|
5
15
|
systemPrompt: z.ZodString;
|
|
@@ -606,6 +616,10 @@ declare const assistantWithoutApiKeySchema: z.ZodObject<{
|
|
|
606
616
|
};
|
|
607
617
|
}[];
|
|
608
618
|
};
|
|
619
|
+
audioFilters?: {
|
|
620
|
+
options?: Record<string, unknown>;
|
|
621
|
+
name?: string;
|
|
622
|
+
}[];
|
|
609
623
|
conversationSettings?: {
|
|
610
624
|
firstMessage?: string;
|
|
611
625
|
systemPrompt?: string;
|
|
@@ -702,6 +716,10 @@ declare const assistantWithoutApiKeySchema: z.ZodObject<{
|
|
|
702
716
|
};
|
|
703
717
|
}[];
|
|
704
718
|
};
|
|
719
|
+
audioFilters?: {
|
|
720
|
+
options?: Record<string, unknown>;
|
|
721
|
+
name?: string;
|
|
722
|
+
}[];
|
|
705
723
|
conversationSettings?: {
|
|
706
724
|
firstMessage?: string;
|
|
707
725
|
systemPrompt?: string;
|
|
@@ -38,6 +38,16 @@ declare function createValidationSchema(request: {
|
|
|
38
38
|
intelligence: z.ZodUndefined | z.ZodEffects<z.ZodObject<{
|
|
39
39
|
productRef: z.ZodString;
|
|
40
40
|
config: z.ZodObject<{
|
|
41
|
+
audioFilters: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
options?: Record<string, unknown>;
|
|
46
|
+
name?: string;
|
|
47
|
+
}, {
|
|
48
|
+
options?: Record<string, unknown>;
|
|
49
|
+
name?: string;
|
|
50
|
+
}>, "many">>;
|
|
41
51
|
conversationSettings: z.ZodObject<{
|
|
42
52
|
firstMessage: z.ZodOptional<z.ZodString>;
|
|
43
53
|
systemPrompt: z.ZodString;
|
|
@@ -644,6 +654,10 @@ declare function createValidationSchema(request: {
|
|
|
644
654
|
};
|
|
645
655
|
}[];
|
|
646
656
|
};
|
|
657
|
+
audioFilters?: {
|
|
658
|
+
options?: Record<string, unknown>;
|
|
659
|
+
name?: string;
|
|
660
|
+
}[];
|
|
647
661
|
conversationSettings?: {
|
|
648
662
|
firstMessage?: string;
|
|
649
663
|
systemPrompt?: string;
|
|
@@ -740,6 +754,10 @@ declare function createValidationSchema(request: {
|
|
|
740
754
|
};
|
|
741
755
|
}[];
|
|
742
756
|
};
|
|
757
|
+
audioFilters?: {
|
|
758
|
+
options?: Record<string, unknown>;
|
|
759
|
+
name?: string;
|
|
760
|
+
}[];
|
|
743
761
|
conversationSettings?: {
|
|
744
762
|
firstMessage?: string;
|
|
745
763
|
systemPrompt?: string;
|
|
@@ -838,6 +856,10 @@ declare function createValidationSchema(request: {
|
|
|
838
856
|
};
|
|
839
857
|
}[];
|
|
840
858
|
};
|
|
859
|
+
audioFilters?: {
|
|
860
|
+
options?: Record<string, unknown>;
|
|
861
|
+
name?: string;
|
|
862
|
+
}[];
|
|
841
863
|
conversationSettings?: {
|
|
842
864
|
firstMessage?: string;
|
|
843
865
|
systemPrompt?: string;
|
|
@@ -937,6 +959,10 @@ declare function createValidationSchema(request: {
|
|
|
937
959
|
};
|
|
938
960
|
}[];
|
|
939
961
|
};
|
|
962
|
+
audioFilters?: {
|
|
963
|
+
options?: Record<string, unknown>;
|
|
964
|
+
name?: string;
|
|
965
|
+
}[];
|
|
940
966
|
conversationSettings?: {
|
|
941
967
|
firstMessage?: string;
|
|
942
968
|
systemPrompt?: string;
|
|
@@ -1036,6 +1062,10 @@ declare function createValidationSchema(request: {
|
|
|
1036
1062
|
};
|
|
1037
1063
|
}[];
|
|
1038
1064
|
};
|
|
1065
|
+
audioFilters?: {
|
|
1066
|
+
options?: Record<string, unknown>;
|
|
1067
|
+
name?: string;
|
|
1068
|
+
}[];
|
|
1039
1069
|
conversationSettings?: {
|
|
1040
1070
|
firstMessage?: string;
|
|
1041
1071
|
systemPrompt?: string;
|
|
@@ -1135,6 +1165,10 @@ declare function createValidationSchema(request: {
|
|
|
1135
1165
|
};
|
|
1136
1166
|
}[];
|
|
1137
1167
|
};
|
|
1168
|
+
audioFilters?: {
|
|
1169
|
+
options?: Record<string, unknown>;
|
|
1170
|
+
name?: string;
|
|
1171
|
+
}[];
|
|
1138
1172
|
conversationSettings?: {
|
|
1139
1173
|
firstMessage?: string;
|
|
1140
1174
|
systemPrompt?: string;
|
|
@@ -1246,6 +1280,10 @@ declare function createValidationSchema(request: {
|
|
|
1246
1280
|
};
|
|
1247
1281
|
}[];
|
|
1248
1282
|
};
|
|
1283
|
+
audioFilters?: {
|
|
1284
|
+
options?: Record<string, unknown>;
|
|
1285
|
+
name?: string;
|
|
1286
|
+
}[];
|
|
1249
1287
|
conversationSettings?: {
|
|
1250
1288
|
firstMessage?: string;
|
|
1251
1289
|
systemPrompt?: string;
|
|
@@ -1311,9 +1349,9 @@ declare function createValidationSchema(request: {
|
|
|
1311
1349
|
};
|
|
1312
1350
|
productRef?: string;
|
|
1313
1351
|
};
|
|
1314
|
-
endpoint?: string;
|
|
1315
1352
|
type?: "EXTERNAL" | "AUTOPILOT";
|
|
1316
1353
|
name?: string;
|
|
1354
|
+
endpoint?: string;
|
|
1317
1355
|
}, {
|
|
1318
1356
|
textToSpeech?: {
|
|
1319
1357
|
[x: string]: any;
|
|
@@ -1360,6 +1398,10 @@ declare function createValidationSchema(request: {
|
|
|
1360
1398
|
};
|
|
1361
1399
|
}[];
|
|
1362
1400
|
};
|
|
1401
|
+
audioFilters?: {
|
|
1402
|
+
options?: Record<string, unknown>;
|
|
1403
|
+
name?: string;
|
|
1404
|
+
}[];
|
|
1363
1405
|
conversationSettings?: {
|
|
1364
1406
|
firstMessage?: string;
|
|
1365
1407
|
systemPrompt?: string;
|
|
@@ -1425,8 +1467,8 @@ declare function createValidationSchema(request: {
|
|
|
1425
1467
|
};
|
|
1426
1468
|
productRef?: string;
|
|
1427
1469
|
};
|
|
1428
|
-
endpoint?: string;
|
|
1429
1470
|
type?: "EXTERNAL" | "AUTOPILOT";
|
|
1430
1471
|
name?: string;
|
|
1472
|
+
endpoint?: string;
|
|
1431
1473
|
}>;
|
|
1432
1474
|
export { createValidationSchema };
|
|
@@ -89,6 +89,7 @@ class VoiceDispatcher {
|
|
|
89
89
|
vc.stopStreamGather();
|
|
90
90
|
});
|
|
91
91
|
vc.on(common_1.StreamContent.START_STREAM_REQUEST, (0, handlers_1.createStreamHandler)(vc).bind(this));
|
|
92
|
+
vc.on(common_1.StreamContent.SET_AUDIO_FILTERS_REQUEST, (0, handlers_1.createSetAudioFiltersHandler)(vc).bind(this));
|
|
92
93
|
// Connect to voice server (must await to ensure speechHandler is initialized)
|
|
93
94
|
yield vc.connect();
|
|
94
95
|
voiceClients.set(channel.id, vc);
|
|
@@ -19,14 +19,17 @@
|
|
|
19
19
|
import { Stream } from "stream";
|
|
20
20
|
import { VoiceClientConfig } from "@fonoster/common";
|
|
21
21
|
import { AudioStream } from "@fonoster/streams";
|
|
22
|
+
import { AudioFilterChain } from "../filters";
|
|
22
23
|
declare class AudioSocketHandler {
|
|
23
24
|
private audioSocket;
|
|
24
25
|
private audioStream;
|
|
25
26
|
private transcriptionsStream;
|
|
26
27
|
private config;
|
|
28
|
+
private getFilterChain;
|
|
27
29
|
constructor(params: {
|
|
28
30
|
transcriptionsStream: Stream;
|
|
29
31
|
config: VoiceClientConfig;
|
|
32
|
+
getFilterChain?: () => AudioFilterChain | null;
|
|
30
33
|
});
|
|
31
34
|
setupAudioSocket(port: number): Promise<void>;
|
|
32
35
|
getAudioStream(): AudioStream;
|
|
@@ -16,8 +16,10 @@ const transcribeOnConnection_1 = require("../transcribeOnConnection");
|
|
|
16
16
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
17
17
|
class AudioSocketHandler {
|
|
18
18
|
constructor(params) {
|
|
19
|
+
var _a;
|
|
19
20
|
this.transcriptionsStream = params.transcriptionsStream;
|
|
20
21
|
this.config = params.config;
|
|
22
|
+
this.getFilterChain = (_a = params.getFilterChain) !== null && _a !== void 0 ? _a : (() => null);
|
|
21
23
|
}
|
|
22
24
|
setupAudioSocket(port) {
|
|
23
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -29,7 +31,7 @@ class AudioSocketHandler {
|
|
|
29
31
|
ref: req.ref,
|
|
30
32
|
mediaSessionRef: this.config.mediaSessionRef
|
|
31
33
|
});
|
|
32
|
-
(0, transcribeOnConnection_1.transcribeOnConnection)(this.transcriptionsStream)(req, res);
|
|
34
|
+
(0, transcribeOnConnection_1.transcribeOnConnection)(this.transcriptionsStream, this.getFilterChain)(req, res);
|
|
33
35
|
res.onClose(() => {
|
|
34
36
|
logger.verbose("session audio stream closed", {
|
|
35
37
|
mediaSessionRef: this.config.mediaSessionRef
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { Stream } from "stream";
|
|
20
20
|
import { SayOptions, VoiceClientConfig, VoiceIn } from "@fonoster/common";
|
|
21
21
|
import { Bridge, Client } from "ari-client";
|
|
22
|
+
import { AudioFilterConfig } from "../filters";
|
|
22
23
|
import { SpeechResult } from "../stt/types";
|
|
23
24
|
import { SpeechToText, TextToSpeech, VoiceClient } from "../types";
|
|
24
25
|
declare class VoiceClientImpl implements VoiceClient {
|
|
@@ -32,6 +33,7 @@ declare class VoiceClientImpl implements VoiceClient {
|
|
|
32
33
|
private externalMediaHandler;
|
|
33
34
|
private grpcHandler;
|
|
34
35
|
private speechHandler;
|
|
36
|
+
private readonly audioFilters;
|
|
35
37
|
private _tts;
|
|
36
38
|
private _stt;
|
|
37
39
|
constructor(params: {
|
|
@@ -64,7 +66,13 @@ declare class VoiceClientImpl implements VoiceClient {
|
|
|
64
66
|
}>;
|
|
65
67
|
stopStreamGather(): void;
|
|
66
68
|
getTranscriptionsStream(): Stream;
|
|
69
|
+
/**
|
|
70
|
+
* Replaces the session's audio filters. Rejects when they cannot be
|
|
71
|
+
* applied, leaving the call on whatever it had before.
|
|
72
|
+
*/
|
|
73
|
+
setAudioFilters(filters: AudioFilterConfig[]): Promise<void>;
|
|
67
74
|
close(): void;
|
|
75
|
+
private logFilterStats;
|
|
68
76
|
get tts(): TextToSpeech;
|
|
69
77
|
get stt(): SpeechToText;
|
|
70
78
|
}
|
|
@@ -31,6 +31,7 @@ exports.VoiceClientImpl = void 0;
|
|
|
31
31
|
const stream_1 = require("stream");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
33
|
const pick_port_1 = require("pick-port");
|
|
34
|
+
const filters_1 = require("../filters");
|
|
34
35
|
const AudioSocketHandler_1 = require("./AudioSocketHandler");
|
|
35
36
|
const AuthorizationHandler_1 = require("./AuthorizationHandler");
|
|
36
37
|
const ExternalMediaHandler_1 = require("./ExternalMediaHandler");
|
|
@@ -39,6 +40,8 @@ const SpeechHandler_1 = require("./SpeechHandler");
|
|
|
39
40
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
40
41
|
class VoiceClientImpl {
|
|
41
42
|
constructor(params) {
|
|
43
|
+
// Owns the call's filter chain: building, replacing and retiring it
|
|
44
|
+
this.audioFilters = (0, filters_1.createAudioFilterSession)();
|
|
42
45
|
const { config, tts, stt, ari } = params;
|
|
43
46
|
this.config = config;
|
|
44
47
|
this.ari = ari;
|
|
@@ -53,7 +56,8 @@ class VoiceClientImpl {
|
|
|
53
56
|
});
|
|
54
57
|
this.audioSocketHandler = new AudioSocketHandler_1.AudioSocketHandler({
|
|
55
58
|
transcriptionsStream: this.transcriptionsStream,
|
|
56
|
-
config: this.config
|
|
59
|
+
config: this.config,
|
|
60
|
+
getFilterChain: () => this.audioFilters.current()
|
|
57
61
|
});
|
|
58
62
|
this.externalMediaHandler = new ExternalMediaHandler_1.ExternalMediaHandler({
|
|
59
63
|
ari: this.ari,
|
|
@@ -149,10 +153,41 @@ class VoiceClientImpl {
|
|
|
149
153
|
getTranscriptionsStream() {
|
|
150
154
|
return this.transcriptionsStream;
|
|
151
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Replaces the session's audio filters. Rejects when they cannot be
|
|
158
|
+
* applied, leaving the call on whatever it had before.
|
|
159
|
+
*/
|
|
160
|
+
setAudioFilters(filters) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
yield this.audioFilters.set(filters);
|
|
163
|
+
logger.verbose("audio filters set", {
|
|
164
|
+
mediaSessionRef: this.config.mediaSessionRef,
|
|
165
|
+
filters: filters.map((filter) => filter.name)
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
152
169
|
close() {
|
|
170
|
+
this.logFilterStats(this.audioFilters.close());
|
|
153
171
|
this.grpcHandler.close();
|
|
154
172
|
this.audioSocketHandler.close();
|
|
155
173
|
}
|
|
174
|
+
// One line per filtered call, so filter cost and any filter that gave up are
|
|
175
|
+
// visible in production without turning on verbose logging
|
|
176
|
+
logFilterStats(stats) {
|
|
177
|
+
if (!stats) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
logger.info("audio filter stats for session", {
|
|
181
|
+
mediaSessionRef: this.config.mediaSessionRef,
|
|
182
|
+
frames: stats.total.frames,
|
|
183
|
+
p50Ms: stats.total.p50Ms,
|
|
184
|
+
p95Ms: stats.total.p95Ms,
|
|
185
|
+
delayMs: stats.total.delayMs,
|
|
186
|
+
disabled: stats.filters
|
|
187
|
+
.filter((filter) => filter.disabled)
|
|
188
|
+
.map((filter) => `${filter.name}: ${filter.error}`)
|
|
189
|
+
});
|
|
190
|
+
}
|
|
156
191
|
get tts() {
|
|
157
192
|
return this._tts;
|
|
158
193
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AudioFilter, AudioFilterChain, AudioFilterConfig } from "./types";
|
|
3
|
+
declare const audioFiltersConfigSchema: z.ZodArray<z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
options?: Record<string, unknown>;
|
|
8
|
+
name?: string;
|
|
9
|
+
}, {
|
|
10
|
+
options?: Record<string, unknown>;
|
|
11
|
+
name?: string;
|
|
12
|
+
}>, "many">;
|
|
13
|
+
type FilterDefinition = {
|
|
14
|
+
description: string;
|
|
15
|
+
optionsSchema: z.ZodObject<z.ZodRawShape>;
|
|
16
|
+
publicOptionsSchema: z.ZodObject<z.ZodRawShape>;
|
|
17
|
+
create: (options: Record<string, unknown>) => AudioFilter;
|
|
18
|
+
};
|
|
19
|
+
type CreateOptions = {
|
|
20
|
+
trusted?: boolean;
|
|
21
|
+
};
|
|
22
|
+
declare class AudioFilterFactory {
|
|
23
|
+
private static filters;
|
|
24
|
+
static registerFilter(name: string, definition: FilterDefinition): void;
|
|
25
|
+
static createFilter(config: AudioFilterConfig, { trusted }?: CreateOptions): AudioFilter;
|
|
26
|
+
static createChainFromConfig(configs: unknown, options?: CreateOptions): AudioFilterChain;
|
|
27
|
+
static listFilters(): {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
defaults: {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
export { AudioFilterFactory, audioFiltersConfigSchema };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.audioFiltersConfigSchema = exports.AudioFilterFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const logger_1 = require("@fonoster/logger");
|
|
23
|
+
const zod_1 = require("zod");
|
|
24
|
+
const createAiCousticsFilter_1 = require("./aiCoustics/createAiCousticsFilter");
|
|
25
|
+
const createAudioFilterChain_1 = require("./createAudioFilterChain");
|
|
26
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
27
|
+
const audioFiltersConfigSchema = zod_1.z.array(zod_1.z.object({
|
|
28
|
+
name: zod_1.z.string().min(1),
|
|
29
|
+
options: zod_1.z.record(zod_1.z.unknown()).optional()
|
|
30
|
+
}));
|
|
31
|
+
exports.audioFiltersConfigSchema = audioFiltersConfigSchema;
|
|
32
|
+
class AudioFilterFactory {
|
|
33
|
+
static registerFilter(name, definition) {
|
|
34
|
+
logger.verbose("registering audio filter", { name });
|
|
35
|
+
this.filters.set(name, definition);
|
|
36
|
+
}
|
|
37
|
+
static createFilter(config, { trusted = false } = {}) {
|
|
38
|
+
var _a;
|
|
39
|
+
const definition = this.filters.get(config.name);
|
|
40
|
+
if (!definition) {
|
|
41
|
+
throw new Error(`Unknown audio filter "${config.name}". Available filters: ${[
|
|
42
|
+
...this.filters.keys()
|
|
43
|
+
].join(", ")}`);
|
|
44
|
+
}
|
|
45
|
+
const schema = trusted
|
|
46
|
+
? definition.optionsSchema
|
|
47
|
+
: definition.publicOptionsSchema;
|
|
48
|
+
const parsed = schema.safeParse((_a = config.options) !== null && _a !== void 0 ? _a : {});
|
|
49
|
+
if (!parsed.success) {
|
|
50
|
+
const issues = parsed.error.issues
|
|
51
|
+
.map((issue) => `${issue.path.join(".")}: ${issue.message}`)
|
|
52
|
+
.join("; ");
|
|
53
|
+
throw new Error(`Invalid options for audio filter "${config.name}": ${issues}`);
|
|
54
|
+
}
|
|
55
|
+
return definition.create(parsed.data);
|
|
56
|
+
}
|
|
57
|
+
static createChainFromConfig(configs, options = {}) {
|
|
58
|
+
const parsed = audioFiltersConfigSchema.parse(configs);
|
|
59
|
+
const filters = [];
|
|
60
|
+
try {
|
|
61
|
+
parsed.forEach((c) => filters.push(this.createFilter(c, options)));
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
// A filter may already hold a model or a native handle, so nothing
|
|
65
|
+
// built here is left behind when a later one is rejected
|
|
66
|
+
filters.forEach((filter) => {
|
|
67
|
+
var _a;
|
|
68
|
+
try {
|
|
69
|
+
(_a = filter.close) === null || _a === void 0 ? void 0 : _a.call(filter);
|
|
70
|
+
}
|
|
71
|
+
catch (_b) {
|
|
72
|
+
// Best effort
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
return (0, createAudioFilterChain_1.createAudioFilterChain)(filters);
|
|
78
|
+
}
|
|
79
|
+
static listFilters() {
|
|
80
|
+
return [...this.filters.entries()].map(([name, definition]) => ({
|
|
81
|
+
name,
|
|
82
|
+
description: definition.description,
|
|
83
|
+
defaults: definition.publicOptionsSchema.parse({})
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.AudioFilterFactory = AudioFilterFactory;
|
|
88
|
+
AudioFilterFactory.filters = new Map();
|
|
89
|
+
AudioFilterFactory.registerFilter(createAiCousticsFilter_1.AI_COUSTICS_NAME, {
|
|
90
|
+
description: "ai-coustics speech enhancement: keeps the primary speaker, suppressing noise and competing voices",
|
|
91
|
+
optionsSchema: createAiCousticsFilter_1.aiCousticsOptionsSchema,
|
|
92
|
+
publicOptionsSchema: createAiCousticsFilter_1.aiCousticsPublicOptionsSchema,
|
|
93
|
+
create: (options) => (0, createAiCousticsFilter_1.createAiCousticsFilter)(options)
|
|
94
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AudioFilter } from "../types";
|
|
3
|
+
import { AiCousticsSdk } from "./types";
|
|
4
|
+
declare const AI_COUSTICS_NAME = "aiCoustics";
|
|
5
|
+
declare const aiCousticsOptionsSchema: z.ZodObject<{
|
|
6
|
+
model: z.ZodDefault<z.ZodString>;
|
|
7
|
+
modelDir: z.ZodDefault<z.ZodString>;
|
|
8
|
+
modelFile: z.ZodOptional<z.ZodString>;
|
|
9
|
+
autoDownload: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
enhancementLevel: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
bypass: z.ZodDefault<z.ZodBoolean>;
|
|
12
|
+
licenseEnv: z.ZodDefault<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
model?: string;
|
|
15
|
+
modelDir?: string;
|
|
16
|
+
modelFile?: string;
|
|
17
|
+
autoDownload?: boolean;
|
|
18
|
+
enhancementLevel?: number;
|
|
19
|
+
bypass?: boolean;
|
|
20
|
+
licenseEnv?: string;
|
|
21
|
+
}, {
|
|
22
|
+
model?: string;
|
|
23
|
+
modelDir?: string;
|
|
24
|
+
modelFile?: string;
|
|
25
|
+
autoDownload?: boolean;
|
|
26
|
+
enhancementLevel?: number;
|
|
27
|
+
bypass?: boolean;
|
|
28
|
+
licenseEnv?: string;
|
|
29
|
+
}>;
|
|
30
|
+
type AiCousticsOptions = z.input<typeof aiCousticsOptionsSchema>;
|
|
31
|
+
declare const aiCousticsPublicOptionsSchema: z.ZodObject<Pick<{
|
|
32
|
+
model: z.ZodDefault<z.ZodString>;
|
|
33
|
+
modelDir: z.ZodDefault<z.ZodString>;
|
|
34
|
+
modelFile: z.ZodOptional<z.ZodString>;
|
|
35
|
+
autoDownload: z.ZodDefault<z.ZodBoolean>;
|
|
36
|
+
enhancementLevel: z.ZodDefault<z.ZodNumber>;
|
|
37
|
+
bypass: z.ZodDefault<z.ZodBoolean>;
|
|
38
|
+
licenseEnv: z.ZodDefault<z.ZodString>;
|
|
39
|
+
}, "enhancementLevel" | "bypass"> & {
|
|
40
|
+
model: z.ZodDefault<z.ZodString>;
|
|
41
|
+
}, "strict", z.ZodTypeAny, {
|
|
42
|
+
model?: string;
|
|
43
|
+
enhancementLevel?: number;
|
|
44
|
+
bypass?: boolean;
|
|
45
|
+
}, {
|
|
46
|
+
model?: string;
|
|
47
|
+
enhancementLevel?: number;
|
|
48
|
+
bypass?: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* ai-coustics speech enhancement (Quail Voice Focus by default), which keeps
|
|
52
|
+
* the primary speaker and suppresses noise and competing voices.
|
|
53
|
+
*
|
|
54
|
+
* The SDK works on fixed blocks of Float32 samples at the model's optimal
|
|
55
|
+
* size, so frames are re-chunked here and the output is delayed by one block.
|
|
56
|
+
* Processing runs on libuv worker threads, off the event loop.
|
|
57
|
+
*
|
|
58
|
+
* Until the model is loaded, audio passes through untouched rather than
|
|
59
|
+
* stalling the call.
|
|
60
|
+
*/
|
|
61
|
+
declare function createAiCousticsFilter(input?: AiCousticsOptions, deps?: {
|
|
62
|
+
loadSdk: () => AiCousticsSdk;
|
|
63
|
+
}): AudioFilter;
|
|
64
|
+
export { AI_COUSTICS_NAME, aiCousticsOptionsSchema, AiCousticsOptions, aiCousticsPublicOptionsSchema, createAiCousticsFilter };
|