@fonoster/apiserver 0.26.0 → 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.
@@ -20,7 +20,7 @@ import { Stream } from "stream";
20
20
  import * as z from "zod";
21
21
  import { SpeechToText } from "../types";
22
22
  import { AbstractSpeechToText } from "./AbstractSpeechToText";
23
- import { DeepgramSttConfig, SpeechResult, StreamSpeech } from "./types";
23
+ import { DeepgramLanguage, DeepgramModel, DeepgramSttConfig, SpeechResult, StreamSpeech } from "./types";
24
24
  declare const DeepgramClient: any;
25
25
  declare const ENGINE_NAME = "stt.deepgram";
26
26
  declare class Deepgram extends AbstractSpeechToText<typeof ENGINE_NAME> implements SpeechToText {
@@ -33,4 +33,28 @@ declare class Deepgram extends AbstractSpeechToText<typeof ENGINE_NAME> implemen
33
33
  static getConfigValidationSchema(): z.Schema;
34
34
  static getCredentialsValidationSchema(): z.Schema;
35
35
  }
36
- export { Deepgram, ENGINE_NAME };
36
+ declare function buildTranscribeConfig(config: {
37
+ model: DeepgramModel;
38
+ languageCode: DeepgramLanguage;
39
+ smartFormat?: boolean;
40
+ noDelay?: boolean;
41
+ interimResults?: boolean;
42
+ utteranceEndMs?: number;
43
+ }): {
44
+ endpointing: number;
45
+ model: DeepgramModel;
46
+ language: DeepgramLanguage;
47
+ encoding: string;
48
+ sample_rate: number;
49
+ channels: number;
50
+ smart_format: boolean;
51
+ no_delay: boolean;
52
+ interim_results: boolean;
53
+ utterance_end_ms: number;
54
+ languageCode: DeepgramLanguage;
55
+ smartFormat?: boolean;
56
+ noDelay?: boolean;
57
+ interimResults?: boolean;
58
+ utteranceEndMs?: number;
59
+ };
60
+ export { buildTranscribeConfig, Deepgram, ENGINE_NAME };
@@ -43,6 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.ENGINE_NAME = exports.Deepgram = void 0;
46
+ exports.buildTranscribeConfig = buildTranscribeConfig;
46
47
  /**
47
48
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
48
49
  * http://github.com/fonoster/fonoster
@@ -72,6 +73,11 @@ const { DeepgramClient, LiveTranscriptionEvents, createClient
72
73
  } = require("@deepgram/sdk"); // Why Deepgram :(
73
74
  const ENGINE_NAME = "stt.deepgram";
74
75
  exports.ENGINE_NAME = ENGINE_NAME;
76
+ // Nova-3 detects English, Spanish and eight other languages; Nova-2 only
77
+ // English + Spanish. The phonecall/conversationalai variants are English-only.
78
+ const MULTILINGUAL_MODELS = [types_1.DeepgramModel.NOVA_3, types_1.DeepgramModel.NOVA_2];
79
+ // Deepgram's recommended endpointing for code-switching (its default is 10ms)
80
+ const MULTILINGUAL_ENDPOINTING_MS = 100;
75
81
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
76
82
  class Deepgram extends AbstractSpeechToText_1.AbstractSpeechToText {
77
83
  constructor(config) {
@@ -269,19 +275,24 @@ class Deepgram extends AbstractSpeechToText_1.AbstractSpeechToText {
269
275
  });
270
276
  }
271
277
  static getConfigValidationSchema() {
272
- return z.object({
278
+ return z
279
+ .object({
273
280
  smartFormat: z.boolean().optional(),
274
281
  noDelay: z.boolean().optional(),
275
282
  languageCode: z
276
- .nativeEnum(common_1.VoiceLanguage, {
277
- message: common_1.Messages.VALID_LANGUAGE_CODE
278
- })
283
+ .union([z.nativeEnum(common_1.VoiceLanguage), z.literal(types_1.DEEPGRAM_MULTILINGUAL)], { errorMap: () => ({ message: common_1.Messages.VALID_LANGUAGE_CODE }) })
279
284
  .optional(),
280
285
  model: z
281
286
  .nativeEnum(types_1.DeepgramModel, { message: "Invalid Deepgram model" })
282
287
  .optional(),
283
288
  interimResults: z.boolean().optional(),
284
289
  utteranceEndMs: z.number().int().min(1000).max(5000).optional()
290
+ })
291
+ .refine((config) => config.languageCode !== types_1.DEEPGRAM_MULTILINGUAL ||
292
+ !config.model ||
293
+ MULTILINGUAL_MODELS.includes(config.model), {
294
+ message: `Language "${types_1.DEEPGRAM_MULTILINGUAL}" requires one of these models: ${MULTILINGUAL_MODELS.join(", ")}`,
295
+ path: ["model"]
285
296
  });
286
297
  }
287
298
  static getCredentialsValidationSchema() {
@@ -298,11 +309,15 @@ function buildTranscribeConfig(config) {
298
309
  // Default utterance_end_ms to 1000ms (minimum required value)
299
310
  // This enables UtteranceEnd events as a fallback when speech_final never becomes true
300
311
  const utteranceEndMs = config.utteranceEndMs || 1000;
301
- return Object.assign(Object.assign({}, config), { model: config.model || types_1.DeepgramModel.NOVA_2_PHONECALL, language: config.languageCode || common_1.VoiceLanguage.EN_US, encoding: "linear16", sample_rate: 16000, channels: 1, smart_format: config.smartFormat !== false,
312
+ const isMultilingual = config.languageCode === types_1.DEEPGRAM_MULTILINGUAL;
313
+ return Object.assign(Object.assign(Object.assign({}, config), {
314
+ // The phonecall default is English-only, so multilingual needs its own
315
+ model: config.model ||
316
+ (isMultilingual ? types_1.DeepgramModel.NOVA_3 : types_1.DeepgramModel.NOVA_2_PHONECALL), language: config.languageCode || common_1.VoiceLanguage.EN_US, encoding: "linear16", sample_rate: 16000, channels: 1, smart_format: config.smartFormat !== false,
302
317
  // This needs to be set to true to avoid delays while using smart_format
303
318
  no_delay: config.noDelay !== false,
304
319
  // REQUIRED for UtteranceEnd: interim_results must be true
305
320
  interim_results: interimResults,
306
321
  // REQUIRED for UtteranceEnd: utterance_end_ms parameter
307
- utterance_end_ms: utteranceEndMs });
322
+ utterance_end_ms: utteranceEndMs }), (isMultilingual && { endpointing: MULTILINGUAL_ENDPOINTING_MS }));
308
323
  }
@@ -27,7 +27,7 @@ type StreamSpeech = {
27
27
  };
28
28
  type SttConfig = {
29
29
  config: {
30
- languageCode: VoiceLanguage;
30
+ languageCode: string;
31
31
  };
32
32
  };
33
33
  type GoogleSttConfig = {
@@ -45,9 +45,11 @@ declare enum DeepgramModel {
45
45
  NOVA_2_PHONECALL = "nova-2-phonecall",
46
46
  NOVA_2_CONVERSATIONALAI = "nova-2-conversationalai"
47
47
  }
48
+ declare const DEEPGRAM_MULTILINGUAL = "multi";
49
+ type DeepgramLanguage = VoiceLanguage | typeof DEEPGRAM_MULTILINGUAL;
48
50
  type DeepgramSttConfig = {
49
51
  config: {
50
- languageCode: VoiceLanguage;
52
+ languageCode: DeepgramLanguage;
51
53
  model: DeepgramModel;
52
54
  smartFormat: boolean;
53
55
  noDelay: boolean;
@@ -58,4 +60,4 @@ type DeepgramSttConfig = {
58
60
  apiKey: string;
59
61
  };
60
62
  };
61
- export { DeepgramModel, DeepgramSttConfig, GoogleSttConfig, SpeechResult, StreamSpeech, SttConfig };
63
+ export { DEEPGRAM_MULTILINGUAL, DeepgramLanguage, DeepgramModel, DeepgramSttConfig, GoogleSttConfig, SpeechResult, StreamSpeech, SttConfig };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeepgramModel = void 0;
3
+ exports.DeepgramModel = exports.DEEPGRAM_MULTILINGUAL = void 0;
4
4
  var DeepgramModel;
5
5
  (function (DeepgramModel) {
6
6
  DeepgramModel["NOVA_3"] = "nova-3";
@@ -8,3 +8,7 @@ var DeepgramModel;
8
8
  DeepgramModel["NOVA_2_PHONECALL"] = "nova-2-phonecall";
9
9
  DeepgramModel["NOVA_2_CONVERSATIONALAI"] = "nova-2-conversationalai";
10
10
  })(DeepgramModel || (exports.DeepgramModel = DeepgramModel = {}));
11
+ // Deepgram's code-switching mode: transcribes speech that mixes languages
12
+ // (e.g. a caller who answers "Hello" on a Spanish call). Nova-3 and Nova-2.
13
+ const DEEPGRAM_MULTILINGUAL = "multi";
14
+ exports.DEEPGRAM_MULTILINGUAL = DEEPGRAM_MULTILINGUAL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -22,14 +22,14 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@deepgram/sdk": "^3.5.1",
25
- "@fonoster/authz": "^0.26.0",
26
- "@fonoster/autopilot": "^0.26.0",
27
- "@fonoster/common": "^0.26.0",
28
- "@fonoster/identity": "^0.26.0",
29
- "@fonoster/logger": "^0.26.0",
30
- "@fonoster/sipnet": "^0.26.0",
31
- "@fonoster/streams": "^0.26.0",
32
- "@fonoster/types": "^0.26.0",
25
+ "@fonoster/authz": "^0.27.0",
26
+ "@fonoster/autopilot": "^0.27.0",
27
+ "@fonoster/common": "^0.27.0",
28
+ "@fonoster/identity": "^0.27.0",
29
+ "@fonoster/logger": "^0.27.0",
30
+ "@fonoster/sipnet": "^0.27.0",
31
+ "@fonoster/streams": "^0.27.0",
32
+ "@fonoster/types": "^0.27.0",
33
33
  "@google-cloud/speech": "^6.6.0",
34
34
  "@google-cloud/text-to-speech": "^5.3.0",
35
35
  "@grpc/grpc-js": "~1.10.11",
@@ -76,7 +76,7 @@
76
76
  "@types/uuid": "^10.0.0",
77
77
  "@types/validator": "^13.15.10"
78
78
  },
79
- "gitHead": "d14f414d791a33f92e8c4225f7e462abc440a142",
79
+ "gitHead": "1191b34677b51a36000177887ff82303ef2693e1",
80
80
  "optionalDependencies": {
81
81
  "@ai-coustics/aic-sdk": "^0.24.0"
82
82
  }