@fonoster/apiserver 0.5.5 → 0.6.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.
- package/LICENSE +2 -2
- package/README.md +3 -0
- package/dist/applications/buildService.d.ts +29 -0
- package/dist/applications/buildService.js +43 -0
- package/dist/applications/createApplication.d.ts +6 -0
- package/dist/applications/createApplication.js +56 -0
- package/dist/applications/createGetFnUtil.d.ts +33 -0
- package/dist/applications/createGetFnUtil.js +31 -0
- package/dist/applications/deleteApplication.d.ts +6 -0
- package/dist/applications/deleteApplication.js +25 -0
- package/dist/applications/getApplication.d.ts +6 -0
- package/dist/applications/getApplication.js +46 -0
- package/dist/applications/hostOrHostPortSchema.d.ts +3 -0
- package/dist/applications/hostOrHostPortSchema.js +34 -0
- package/dist/applications/index.d.ts +1 -0
- package/dist/applications/index.js +23 -0
- package/dist/applications/listApplications.d.ts +6 -0
- package/dist/applications/listApplications.js +68 -0
- package/dist/applications/types.d.ts +27 -0
- package/dist/applications/types.js +2 -0
- package/dist/applications/updateApplication.d.ts +8 -0
- package/dist/applications/updateApplication.js +56 -0
- package/dist/applications/utils/applicationWithEncodedStruct.d.ts +3 -0
- package/dist/applications/utils/applicationWithEncodedStruct.js +22 -0
- package/dist/applications/utils/convertToApplicationData.d.ts +4 -0
- package/dist/applications/utils/convertToApplicationData.js +37 -0
- package/dist/applications/utils/getApplicationValidationSchema.d.ts +64 -0
- package/dist/applications/utils/getApplicationValidationSchema.js +63 -0
- package/dist/applications/utils/prepareForValidation.d.ts +3 -0
- package/dist/applications/utils/prepareForValidation.js +35 -0
- package/dist/applications/utils/validOrThrow.d.ts +3 -0
- package/dist/applications/utils/validOrThrow.js +14 -0
- package/dist/calls/ListCallsRequestSchema.d.ts +28 -0
- package/dist/calls/ListCallsRequestSchema.js +58 -0
- package/dist/calls/buildService.d.ts +26 -0
- package/dist/calls/buildService.js +57 -0
- package/dist/calls/createCall.d.ts +6 -0
- package/dist/calls/createCall.js +63 -0
- package/dist/calls/createCallPublisher.d.ts +7 -0
- package/dist/calls/createCallPublisher.js +46 -0
- package/dist/calls/createFetchCalls.d.ts +3 -0
- package/dist/calls/createFetchCalls.js +86 -0
- package/dist/calls/createFetchSingleCall.d.ts +3 -0
- package/dist/calls/createFetchSingleCall.js +47 -0
- package/dist/calls/createTrackCallSubscriber.d.ts +5 -0
- package/dist/calls/createTrackCallSubscriber.js +52 -0
- package/dist/calls/getCall.d.ts +6 -0
- package/dist/calls/getCall.js +59 -0
- package/dist/calls/index.d.ts +1 -0
- package/dist/calls/index.js +23 -0
- package/dist/calls/influxdb.d.ts +2 -0
- package/dist/calls/influxdb.js +29 -0
- package/dist/calls/listCalls.d.ts +6 -0
- package/dist/calls/listCalls.js +51 -0
- package/dist/calls/runCallManager.d.ts +8 -0
- package/dist/calls/runCallManager.js +81 -0
- package/dist/calls/trackCall.d.ts +14 -0
- package/dist/calls/trackCall.js +63 -0
- package/dist/calls/types.d.ts +96 -0
- package/dist/calls/types.js +42 -0
- package/dist/core/allowList.d.ts +2 -0
- package/dist/core/allowList.js +31 -0
- package/dist/core/db.d.ts +13 -0
- package/dist/core/db.js +29 -0
- package/dist/core/filesServer.d.ts +5 -0
- package/dist/{ari_proxy.js → core/filesServer.js} +23 -20
- package/dist/core/identityConfig.d.ts +21 -0
- package/dist/core/identityConfig.js +43 -0
- package/dist/core/loadServices.d.ts +8 -0
- package/dist/core/loadServices.js +43 -0
- package/dist/core/notFoundError.d.ts +6 -0
- package/dist/core/notFoundError.js +27 -0
- package/dist/core/removeSwaggerNotice.d.ts +2 -0
- package/dist/core/removeSwaggerNotice.js +34 -0
- package/dist/core/routrConfig.d.ts +5 -0
- package/dist/core/routrConfig.js +27 -0
- package/dist/core/runServices.d.ts +2 -0
- package/dist/core/runServices.js +97 -0
- package/dist/core/seed.js +76 -0
- package/dist/core/services.d.ts +432 -0
- package/dist/core/services.js +53 -0
- package/dist/core/upsertDefaultPeer.d.ts +3 -0
- package/dist/core/upsertDefaultPeer.js +88 -0
- package/dist/envs.d.ts +46 -6
- package/dist/envs.js +94 -8
- package/dist/events/createInfluxDbPub.d.ts +13 -0
- package/dist/events/createInfluxDbPub.js +53 -0
- package/dist/events/nats.d.ts +10 -0
- package/dist/events/nats.js +84 -0
- package/dist/events/types.d.ts +8 -0
- package/dist/events/types.js +20 -0
- package/dist/index.js +53 -122
- package/dist/secrets/buildService.d.ts +31 -0
- package/dist/secrets/buildService.js +43 -0
- package/dist/secrets/createGetFnUtil.d.ts +16 -0
- package/dist/secrets/createGetFnUtil.js +45 -0
- package/dist/secrets/createSecret.d.ts +7 -0
- package/dist/secrets/createSecret.js +56 -0
- package/dist/secrets/deleteSecret.d.ts +8 -0
- package/dist/secrets/deleteSecret.js +43 -0
- package/dist/secrets/getSecret.d.ts +6 -0
- package/dist/secrets/getSecret.js +42 -0
- package/dist/secrets/index.d.ts +1 -0
- package/dist/secrets/index.js +23 -0
- package/dist/secrets/listSecrets.d.ts +7 -0
- package/dist/secrets/listSecrets.js +61 -0
- package/dist/secrets/types.d.ts +32 -0
- package/dist/secrets/types.js +2 -0
- package/dist/secrets/updateSecret.d.ts +8 -0
- package/dist/secrets/updateSecret.js +52 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/makeCheckNumberPreconditions.d.ts +6 -0
- package/dist/utils/makeCheckNumberPreconditions.js +48 -0
- package/dist/voice/ChannelVarNotFoundError.d.ts +5 -0
- package/dist/voice/ChannelVarNotFoundError.js +10 -0
- package/dist/voice/MethodNotImplementedError.d.ts +4 -0
- package/dist/voice/MethodNotImplementedError.js +27 -0
- package/dist/voice/VoiceClientImpl.d.ts +41 -0
- package/dist/voice/VoiceClientImpl.js +192 -0
- package/dist/voice/VoiceDispatcher.d.ts +17 -0
- package/dist/voice/VoiceDispatcher.js +99 -0
- package/dist/voice/VoiceServiceClientConst.d.ts +3 -0
- package/dist/voice/VoiceServiceClientConst.js +53 -0
- package/dist/voice/connectToAri.d.ts +2 -0
- package/dist/voice/connectToAri.js +79 -0
- package/dist/voice/createExternalMediaConfig.d.ts +9 -0
- package/dist/voice/createExternalMediaConfig.js +34 -0
- package/dist/voice/handlers/Answer.d.ts +5 -0
- package/dist/voice/handlers/Answer.js +24 -0
- package/dist/voice/handlers/Hangup.d.ts +5 -0
- package/dist/voice/handlers/Hangup.js +25 -0
- package/dist/voice/handlers/Mute.d.ts +4 -0
- package/dist/voice/handlers/Mute.js +27 -0
- package/dist/voice/handlers/Play.d.ts +4 -0
- package/dist/voice/handlers/Play.js +33 -0
- package/dist/voice/handlers/PlayDtmf.d.ts +4 -0
- package/dist/voice/handlers/PlayDtmf.js +27 -0
- package/dist/voice/handlers/PlaybackControl.d.ts +4 -0
- package/dist/voice/handlers/PlaybackControl.js +27 -0
- package/dist/voice/handlers/Record.d.ts +4 -0
- package/dist/voice/handlers/Record.js +58 -0
- package/dist/voice/handlers/Say.d.ts +4 -0
- package/dist/voice/handlers/Say.js +45 -0
- package/dist/voice/handlers/StasisEnd.d.ts +4 -0
- package/dist/voice/handlers/StasisEnd.js +27 -0
- package/dist/voice/handlers/Unmute.d.ts +4 -0
- package/dist/voice/handlers/Unmute.js +27 -0
- package/dist/voice/handlers/awaitForPlaybackFinished.d.ts +3 -0
- package/dist/voice/handlers/awaitForPlaybackFinished.js +25 -0
- package/dist/voice/handlers/awaitForRecordingFinished.d.ts +5 -0
- package/dist/voice/handlers/awaitForRecordingFinished.js +53 -0
- package/dist/voice/handlers/dial/Dial.d.ts +5 -0
- package/dist/voice/handlers/dial/Dial.js +71 -0
- package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +6 -0
- package/dist/voice/handlers/dial/handleChannelLeftBridge.js +29 -0
- package/dist/voice/handlers/dial/handleDialEvents.d.ts +5 -0
- package/dist/voice/handlers/dial/handleDialEvents.js +54 -0
- package/dist/voice/handlers/dial/handleStasisEnd.d.ts +3 -0
- package/dist/voice/handlers/dial/handleStasisEnd.js +19 -0
- package/dist/voice/handlers/dial/handleStasisStart.d.ts +9 -0
- package/dist/voice/handlers/dial/handleStasisStart.js +53 -0
- package/dist/voice/handlers/dial/recordChannel.d.ts +4 -0
- package/dist/voice/handlers/dial/recordChannel.js +45 -0
- package/dist/voice/handlers/gather/Gather.d.ts +3 -0
- package/dist/voice/handlers/gather/Gather.js +72 -0
- package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +8 -0
- package/dist/voice/handlers/gather/getTimeoutPromise.js +18 -0
- package/dist/voice/handlers/withErrorHandling.d.ts +4 -0
- package/dist/voice/handlers/withErrorHandling.js +35 -0
- package/dist/voice/integrations/ApplicationNotFoundError.d.ts +4 -0
- package/dist/voice/integrations/ApplicationNotFoundError.js +28 -0
- package/dist/voice/integrations/findIntegrationsCredentials.d.ts +3 -0
- package/dist/voice/integrations/findIntegrationsCredentials.js +6 -0
- package/dist/voice/integrations/getSttConfig.d.ts +7 -0
- package/dist/voice/integrations/getSttConfig.js +9 -0
- package/dist/voice/integrations/getTtsConfig.d.ts +7 -0
- package/dist/voice/integrations/getTtsConfig.js +10 -0
- package/dist/voice/integrations/index.d.ts +1 -0
- package/dist/voice/integrations/index.js +35 -0
- package/dist/voice/integrations/makeCreateContainer.d.ts +4 -0
- package/dist/voice/integrations/makeCreateContainer.js +88 -0
- package/dist/voice/integrations/types.d.ts +15 -0
- package/dist/voice/integrations/types.js +2 -0
- package/dist/voice/makeCreateVoiceClient.d.ts +9 -0
- package/dist/voice/makeCreateVoiceClient.js +77 -0
- package/dist/voice/makeGetChannelVar.d.ts +4 -0
- package/dist/voice/makeGetChannelVar.js +25 -0
- package/dist/voice/stt/AbstractSpeechToText.d.ts +14 -0
- package/dist/voice/stt/AbstractSpeechToText.js +19 -0
- package/dist/voice/stt/Google.d.ts +19 -0
- package/dist/voice/stt/Google.js +99 -0
- package/dist/voice/stt/SpeechToTextFactory.d.ts +9 -0
- package/dist/voice/stt/SpeechToTextFactory.js +41 -0
- package/dist/voice/stt/types.d.ts +25 -0
- package/dist/voice/stt/types.js +2 -0
- package/dist/voice/transcribeOnConnection.d.ts +4 -0
- package/dist/voice/transcribeOnConnection.js +26 -0
- package/dist/voice/tts/AbstractTextToSpeech.d.ts +18 -0
- package/dist/voice/tts/AbstractTextToSpeech.js +82 -0
- package/dist/voice/tts/Azure.d.ts +30 -0
- package/dist/voice/tts/Azure.js +128 -0
- package/dist/voice/tts/Google.d.ts +25 -0
- package/dist/voice/tts/Google.js +116 -0
- package/dist/voice/tts/TextToSpeechFactory.d.ts +9 -0
- package/dist/voice/tts/TextToSpeechFactory.js +43 -0
- package/dist/voice/tts/computeFilename.d.ts +7 -0
- package/dist/voice/tts/computeFilename.js +38 -0
- package/dist/voice/tts/flattenObject.d.ts +2 -0
- package/dist/voice/tts/flattenObject.js +38 -0
- package/dist/voice/tts/isSsml.d.ts +2 -0
- package/dist/voice/tts/isSsml.js +25 -0
- package/dist/voice/tts/types.d.ts +7 -0
- package/dist/voice/tts/types.js +2 -0
- package/dist/voice/types/ari.d.ts +21 -0
- package/dist/voice/types/ari.js +43 -0
- package/dist/voice/types/index.d.ts +2 -0
- package/dist/voice/types/index.js +36 -0
- package/dist/voice/types/voice.d.ts +33 -0
- package/dist/voice/types/voice.js +2 -0
- package/package.json +46 -36
- package/dist/upsert_peer.d.ts +0 -1
- package/dist/upsert_peer.js +0 -63
- /package/dist/{ari_proxy.d.ts → core/seed.d.ts} +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ENGINE_NAME = exports.Google = void 0;
|
|
36
|
+
const common_1 = require("@fonoster/common");
|
|
37
|
+
const speech_1 = require("@google-cloud/speech");
|
|
38
|
+
const z = __importStar(require("zod"));
|
|
39
|
+
const AbstractSpeechToText_1 = require("./AbstractSpeechToText");
|
|
40
|
+
const ENGINE_NAME = "stt.google";
|
|
41
|
+
exports.ENGINE_NAME = ENGINE_NAME;
|
|
42
|
+
const AUDIO_ENCODING = "LINEAR16";
|
|
43
|
+
const SAMPLE_RATE_HERTZ = 16000;
|
|
44
|
+
class Google extends AbstractSpeechToText_1.AbstractSpeechToText {
|
|
45
|
+
constructor(config) {
|
|
46
|
+
super(config);
|
|
47
|
+
this.engineName = ENGINE_NAME;
|
|
48
|
+
this.AUDIO_ENCODING = AUDIO_ENCODING;
|
|
49
|
+
this.SAMPLE_RATE_HERTZ = SAMPLE_RATE_HERTZ;
|
|
50
|
+
this.client = new speech_1.SpeechClient(config);
|
|
51
|
+
this.config = Object.assign(Object.assign({}, config), { config: {
|
|
52
|
+
encoding: AUDIO_ENCODING,
|
|
53
|
+
sampleRateHertz: SAMPLE_RATE_HERTZ,
|
|
54
|
+
interimResults: false,
|
|
55
|
+
languageCode: config.languageCode
|
|
56
|
+
} });
|
|
57
|
+
}
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
streamTranscribe(_) {
|
|
60
|
+
// Not implemented
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
transcribe(stream) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const recognizeStream = this.client
|
|
67
|
+
.streamingRecognize(this.config)
|
|
68
|
+
.on("error", (e) => reject(e))
|
|
69
|
+
.on("data", (data) => {
|
|
70
|
+
var _a;
|
|
71
|
+
if ((_a = data.results[0]) === null || _a === void 0 ? void 0 : _a.alternatives[0]) {
|
|
72
|
+
const result = {
|
|
73
|
+
speech: data.results[0].alternatives[0].transcript,
|
|
74
|
+
isFinal: true
|
|
75
|
+
};
|
|
76
|
+
resolve(result);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
resolve({ speech: "", isFinal: true });
|
|
80
|
+
}
|
|
81
|
+
recognizeStream.destroy();
|
|
82
|
+
});
|
|
83
|
+
stream.pipe(recognizeStream);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
static getConfigValidationSchema() {
|
|
88
|
+
return z.object({
|
|
89
|
+
languageCode: z.nativeEnum(common_1.VoiceLanguage)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
static getCredentialsValidationSchema() {
|
|
93
|
+
return z.object({
|
|
94
|
+
client_email: z.string(),
|
|
95
|
+
private_key: z.string()
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.Google = Google;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractSpeechToText } from "./AbstractSpeechToText";
|
|
2
|
+
import { SttConfig } from "./types";
|
|
3
|
+
type EngineConstructor<T extends SttConfig = SttConfig> = new (options: T) => AbstractSpeechToText<string>;
|
|
4
|
+
declare class SpeechToTextFactory {
|
|
5
|
+
private static engines;
|
|
6
|
+
static registerEngine<T extends SttConfig>(name: string, ctor: EngineConstructor<T>): void;
|
|
7
|
+
static getEngine<T extends SttConfig>(engineName: string, config: T): AbstractSpeechToText<string>;
|
|
8
|
+
}
|
|
9
|
+
export { SpeechToTextFactory };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpeechToTextFactory = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 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 Google_1 = require("./Google");
|
|
24
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
25
|
+
class SpeechToTextFactory {
|
|
26
|
+
static registerEngine(name, ctor) {
|
|
27
|
+
logger.info("registering stt engine", { name });
|
|
28
|
+
this.engines.set(name, ctor);
|
|
29
|
+
}
|
|
30
|
+
static getEngine(engineName, config) {
|
|
31
|
+
const EngineConstructor = this.engines.get(engineName);
|
|
32
|
+
if (!EngineConstructor) {
|
|
33
|
+
throw new Error(`Engine ${engineName} not found`);
|
|
34
|
+
}
|
|
35
|
+
return new EngineConstructor(config);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.SpeechToTextFactory = SpeechToTextFactory;
|
|
39
|
+
SpeechToTextFactory.engines = new Map();
|
|
40
|
+
// Register engines
|
|
41
|
+
SpeechToTextFactory.registerEngine(Google_1.ENGINE_NAME, Google_1.Google);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VoiceLanguage } from "@fonoster/common/src/tts/types";
|
|
2
|
+
type SttConfig = {
|
|
3
|
+
languageCode: VoiceLanguage;
|
|
4
|
+
};
|
|
5
|
+
type SpeechResult = {
|
|
6
|
+
speech: string;
|
|
7
|
+
isFinal: boolean;
|
|
8
|
+
};
|
|
9
|
+
type StreamSpeechResult = {
|
|
10
|
+
on(events: string, callback: (result: SpeechResult) => void): void;
|
|
11
|
+
close: () => void;
|
|
12
|
+
};
|
|
13
|
+
type GoogleSttConfig = SttConfig & {
|
|
14
|
+
config: {
|
|
15
|
+
encoding: "LINEAR16";
|
|
16
|
+
sampleRateHertz: 16000;
|
|
17
|
+
interimResults: boolean;
|
|
18
|
+
languageCode: VoiceLanguage;
|
|
19
|
+
};
|
|
20
|
+
credentials: {
|
|
21
|
+
client_email: string;
|
|
22
|
+
private_key: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export { SttConfig, SpeechResult, StreamSpeechResult, GoogleSttConfig };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.transcribeOnConnection = transcribeOnConnection;
|
|
13
|
+
const logger_1 = require("@fonoster/logger");
|
|
14
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
15
|
+
function transcribeOnConnection(stream) {
|
|
16
|
+
return (_, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
logger.verbose("starting instance of audio stream for transcription");
|
|
18
|
+
res
|
|
19
|
+
.onData((data) => {
|
|
20
|
+
stream.emit("data", data);
|
|
21
|
+
})
|
|
22
|
+
.onError((err) => {
|
|
23
|
+
logger.error("stream error:", err);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { SynthOptions, TtsConfig } from "./types";
|
|
3
|
+
declare abstract class AbstractTextToSpeech<E, T extends TtsConfig = TtsConfig, S extends SynthOptions = SynthOptions> {
|
|
4
|
+
abstract readonly engineName: E;
|
|
5
|
+
protected abstract OUTPUT_FORMAT: "wav" | "sln16";
|
|
6
|
+
protected abstract CACHING_FIELDS: string[];
|
|
7
|
+
config: T;
|
|
8
|
+
constructor(config: T);
|
|
9
|
+
protected createFilename(text: string, options: SynthOptions): string;
|
|
10
|
+
protected fileExists(filename: string): boolean;
|
|
11
|
+
protected getFilenameWithoutExtension(filename: string): string;
|
|
12
|
+
protected getFullPathToFile(filename: string): string;
|
|
13
|
+
abstract synthesize(text: string, options: S): Promise<string>;
|
|
14
|
+
static getConfigValidationSchema(): z.Schema;
|
|
15
|
+
static getCredentialsValidationSchema(): z.Schema;
|
|
16
|
+
getName(): E;
|
|
17
|
+
}
|
|
18
|
+
export { AbstractTextToSpeech };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.AbstractTextToSpeech = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster/fonoster
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Fonoster
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License");
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const logger_1 = require("@fonoster/logger");
|
|
47
|
+
const computeFilename_1 = require("./computeFilename");
|
|
48
|
+
const MethodNotImplementedError_1 = require("../MethodNotImplementedError");
|
|
49
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
50
|
+
class AbstractTextToSpeech {
|
|
51
|
+
constructor(config) {
|
|
52
|
+
logger.silly("tts pathToFiles", { engine: config.pathToFiles });
|
|
53
|
+
this.config = config;
|
|
54
|
+
}
|
|
55
|
+
createFilename(text, options) {
|
|
56
|
+
return (0, computeFilename_1.computeFilename)({
|
|
57
|
+
text,
|
|
58
|
+
options,
|
|
59
|
+
cachingFields: this.CACHING_FIELDS,
|
|
60
|
+
format: this.OUTPUT_FORMAT
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
fileExists(filename) {
|
|
64
|
+
return fs.existsSync(filename);
|
|
65
|
+
}
|
|
66
|
+
getFilenameWithoutExtension(filename) {
|
|
67
|
+
return filename.replace(`.${this.OUTPUT_FORMAT}`, "");
|
|
68
|
+
}
|
|
69
|
+
getFullPathToFile(filename) {
|
|
70
|
+
return `${this.config.pathToFiles}/${filename}`;
|
|
71
|
+
}
|
|
72
|
+
static getConfigValidationSchema() {
|
|
73
|
+
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
74
|
+
}
|
|
75
|
+
static getCredentialsValidationSchema() {
|
|
76
|
+
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
77
|
+
}
|
|
78
|
+
getName() {
|
|
79
|
+
return this.engineName;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.AbstractTextToSpeech = AbstractTextToSpeech;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as sdk from "microsoft-cognitiveservices-speech-sdk";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import { AbstractTextToSpeech } from "./AbstractTextToSpeech";
|
|
4
|
+
import { SynthOptions, TtsConfig } from "./types";
|
|
5
|
+
declare const ENGINE_NAME = "tts.azure";
|
|
6
|
+
type AzureTTSConfig = TtsConfig & {
|
|
7
|
+
[key: string]: Record<string, string>;
|
|
8
|
+
credentials: {
|
|
9
|
+
subscriptionKey: string;
|
|
10
|
+
serviceRegion: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
declare class Azure extends AbstractTextToSpeech<typeof ENGINE_NAME> {
|
|
14
|
+
config: AzureTTSConfig;
|
|
15
|
+
pathToFiles: string;
|
|
16
|
+
readonly engineName = "tts.azure";
|
|
17
|
+
protected readonly OUTPUT_FORMAT = "sln16";
|
|
18
|
+
protected readonly CACHING_FIELDS: string[];
|
|
19
|
+
constructor(config: AzureTTSConfig);
|
|
20
|
+
synthesize(text: string, options: SynthOptions): Promise<string>;
|
|
21
|
+
doSynthesize(params: {
|
|
22
|
+
text: string;
|
|
23
|
+
filename: string;
|
|
24
|
+
speechConfig: sdk.SpeechConfig;
|
|
25
|
+
isSSML?: boolean;
|
|
26
|
+
}): Promise<unknown>;
|
|
27
|
+
getConfigValidationSchema(): z.Schema;
|
|
28
|
+
getCredentialsValidationSchema(): z.Schema;
|
|
29
|
+
}
|
|
30
|
+
export { Azure, ENGINE_NAME };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ENGINE_NAME = exports.Azure = void 0;
|
|
36
|
+
/*
|
|
37
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
38
|
+
* http://github.com/fonoster/fonoster
|
|
39
|
+
*
|
|
40
|
+
* This file is part of Fonoster
|
|
41
|
+
*
|
|
42
|
+
* Licensed under the MIT License (the "License");
|
|
43
|
+
* you may not use this file except in compliance with
|
|
44
|
+
* the License. You may obtain a copy of the License at
|
|
45
|
+
*
|
|
46
|
+
* https://opensource.org/licenses/MIT
|
|
47
|
+
*
|
|
48
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
49
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
50
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
51
|
+
* See the License for the specific language governing permissions and
|
|
52
|
+
* limitations under the License.
|
|
53
|
+
*/
|
|
54
|
+
const common_1 = require("@fonoster/common");
|
|
55
|
+
const logger_1 = require("@fonoster/logger");
|
|
56
|
+
const sdk = __importStar(require("microsoft-cognitiveservices-speech-sdk"));
|
|
57
|
+
const z = __importStar(require("zod"));
|
|
58
|
+
const AbstractTextToSpeech_1 = require("./AbstractTextToSpeech");
|
|
59
|
+
const isSsml_1 = require("./isSsml");
|
|
60
|
+
const ENGINE_NAME = "tts.azure";
|
|
61
|
+
exports.ENGINE_NAME = ENGINE_NAME;
|
|
62
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
63
|
+
class Azure extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
64
|
+
constructor(config) {
|
|
65
|
+
super(config);
|
|
66
|
+
this.engineName = ENGINE_NAME;
|
|
67
|
+
this.OUTPUT_FORMAT = "sln16";
|
|
68
|
+
this.CACHING_FIELDS = ["voice"];
|
|
69
|
+
this.config = config;
|
|
70
|
+
}
|
|
71
|
+
synthesize(text, options) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
logger.verbose(`synthesize [input: ${text}, isSsml=${(0, isSsml_1.isSsml)(text)} options: ${JSON.stringify(options)}]`);
|
|
74
|
+
const effectiveOptions = Object.assign(Object.assign({}, this.config), options);
|
|
75
|
+
const filename = this.createFilename(text, effectiveOptions);
|
|
76
|
+
if (this.fileExists(this.getFullPathToFile(filename))) {
|
|
77
|
+
return this.getFilenameWithoutExtension(filename);
|
|
78
|
+
}
|
|
79
|
+
const { subscriptionKey, serviceRegion } = this.config.credentials;
|
|
80
|
+
const speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
|
|
81
|
+
speechConfig.speechSynthesisVoiceName = options.voice;
|
|
82
|
+
speechConfig.speechSynthesisOutputFormat =
|
|
83
|
+
sdk.SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm;
|
|
84
|
+
yield this.doSynthesize({
|
|
85
|
+
text,
|
|
86
|
+
filename: this.getFullPathToFile(filename),
|
|
87
|
+
speechConfig,
|
|
88
|
+
isSSML: (0, isSsml_1.isSsml)(text)
|
|
89
|
+
});
|
|
90
|
+
return this.getFilenameWithoutExtension(filename);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
doSynthesize(params) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const { text, filename, speechConfig } = params;
|
|
96
|
+
const audioConfig = sdk.AudioConfig.fromAudioFileOutput(filename);
|
|
97
|
+
const synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
|
|
98
|
+
// FIXME: Let's turn this into constants
|
|
99
|
+
const func = params.isSSML ? "speakSsmlAsync" : "speakTextAsync";
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
synthesizer[func](text, function (result) {
|
|
102
|
+
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
|
|
103
|
+
resolve(filename);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
reject(new Error("speech synthesis canceled: " + result.errorDetails));
|
|
107
|
+
}
|
|
108
|
+
synthesizer.close();
|
|
109
|
+
}, function (err) {
|
|
110
|
+
synthesizer.close();
|
|
111
|
+
reject(new Error(err));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getConfigValidationSchema() {
|
|
117
|
+
return z.object({
|
|
118
|
+
voice: z.nativeEnum(common_1.AzureVoice)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getCredentialsValidationSchema() {
|
|
122
|
+
return z.object({
|
|
123
|
+
subscriptionKey: z.string(),
|
|
124
|
+
serviceRegion: z.string()
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.Azure = Azure;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TextToSpeechClient } from "@google-cloud/text-to-speech";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import { AbstractTextToSpeech } from "./AbstractTextToSpeech";
|
|
4
|
+
import { SynthOptions, TtsConfig } from "./types";
|
|
5
|
+
declare const ENGINE_NAME = "tts.google";
|
|
6
|
+
type GoogleTtsConfig = TtsConfig & {
|
|
7
|
+
[key: string]: Record<string, string>;
|
|
8
|
+
credentials: {
|
|
9
|
+
client_email: string;
|
|
10
|
+
private_key: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
declare class Google extends AbstractTextToSpeech<typeof ENGINE_NAME> {
|
|
14
|
+
client: TextToSpeechClient;
|
|
15
|
+
config: GoogleTtsConfig;
|
|
16
|
+
readonly engineName = "tts.google";
|
|
17
|
+
protected readonly OUTPUT_FORMAT = "sln16";
|
|
18
|
+
protected readonly CACHING_FIELDS: string[];
|
|
19
|
+
protected readonly AUDIO_ENCODING: "LINEAR16";
|
|
20
|
+
constructor(config: GoogleTtsConfig);
|
|
21
|
+
synthesize(text: string, options: SynthOptions): Promise<string>;
|
|
22
|
+
static getConfigValidationSchema(): z.Schema;
|
|
23
|
+
static getCredentialsValidationSchema(): z.Schema;
|
|
24
|
+
}
|
|
25
|
+
export { Google, ENGINE_NAME };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ENGINE_NAME = exports.Google = void 0;
|
|
36
|
+
/*
|
|
37
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
38
|
+
* http://github.com/fonoster/fonoster
|
|
39
|
+
*
|
|
40
|
+
* This file is part of Fonoster
|
|
41
|
+
*
|
|
42
|
+
* Licensed under the MIT License (the "License");
|
|
43
|
+
* you may not use this file except in compliance with
|
|
44
|
+
* the License. You may obtain a copy of the License at
|
|
45
|
+
*
|
|
46
|
+
* https://opensource.org/licenses/MIT
|
|
47
|
+
*
|
|
48
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
49
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
50
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
51
|
+
* See the License for the specific language governing permissions and
|
|
52
|
+
* limitations under the License.
|
|
53
|
+
*/
|
|
54
|
+
const fs = __importStar(require("fs"));
|
|
55
|
+
const util = __importStar(require("util"));
|
|
56
|
+
const common_1 = require("@fonoster/common");
|
|
57
|
+
const logger_1 = require("@fonoster/logger");
|
|
58
|
+
const text_to_speech_1 = require("@google-cloud/text-to-speech");
|
|
59
|
+
const z = __importStar(require("zod"));
|
|
60
|
+
const AbstractTextToSpeech_1 = require("./AbstractTextToSpeech");
|
|
61
|
+
const isSsml_1 = require("./isSsml");
|
|
62
|
+
const ENGINE_NAME = "tts.google";
|
|
63
|
+
exports.ENGINE_NAME = ENGINE_NAME;
|
|
64
|
+
const AUDIO_ENCODING = "LINEAR16";
|
|
65
|
+
const SAMPLE_RATE_HERTZ = 16000;
|
|
66
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
67
|
+
class Google extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
68
|
+
constructor(config) {
|
|
69
|
+
super(config);
|
|
70
|
+
this.engineName = ENGINE_NAME;
|
|
71
|
+
this.OUTPUT_FORMAT = "sln16";
|
|
72
|
+
this.CACHING_FIELDS = ["voice"];
|
|
73
|
+
this.AUDIO_ENCODING = AUDIO_ENCODING;
|
|
74
|
+
this.client = new text_to_speech_1.TextToSpeechClient(config);
|
|
75
|
+
this.config = config;
|
|
76
|
+
}
|
|
77
|
+
synthesize(text, options) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
logger.verbose(`synthesize [input: ${text}, isSsml=${(0, isSsml_1.isSsml)(text)} options: ${JSON.stringify(options)}]`);
|
|
80
|
+
const effectiveOptions = Object.assign(Object.assign({}, this.config), options);
|
|
81
|
+
const { voice } = effectiveOptions;
|
|
82
|
+
const lang = `${voice.split("-")[0]}-${voice.split("-")[1]}`;
|
|
83
|
+
const filename = this.createFilename(text, effectiveOptions);
|
|
84
|
+
if (this.fileExists(this.getFullPathToFile(filename))) {
|
|
85
|
+
return this.getFilenameWithoutExtension(filename);
|
|
86
|
+
}
|
|
87
|
+
const request = {
|
|
88
|
+
input: (0, isSsml_1.isSsml)(text) ? { ssml: text } : { text },
|
|
89
|
+
audioConfig: {
|
|
90
|
+
audioEncoding: AUDIO_ENCODING,
|
|
91
|
+
sampleRateHertz: SAMPLE_RATE_HERTZ
|
|
92
|
+
},
|
|
93
|
+
voice: {
|
|
94
|
+
languageCode: lang,
|
|
95
|
+
name: voice
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const [response] = yield this.client.synthesizeSpeech(request);
|
|
99
|
+
const writeFile = util.promisify(fs.writeFile);
|
|
100
|
+
yield writeFile(this.getFullPathToFile(filename), response.audioContent, "binary");
|
|
101
|
+
return this.getFilenameWithoutExtension(filename);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
static getConfigValidationSchema() {
|
|
105
|
+
return z.object({
|
|
106
|
+
voice: z.nativeEnum(common_1.GoogleVoice)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
static getCredentialsValidationSchema() {
|
|
110
|
+
return z.object({
|
|
111
|
+
client_email: z.string(),
|
|
112
|
+
private_key: z.string()
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.Google = Google;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractTextToSpeech } from "./AbstractTextToSpeech";
|
|
2
|
+
import { TtsConfig } from "./types";
|
|
3
|
+
type EngineConstructor<T extends TtsConfig = TtsConfig> = new (options: T) => AbstractTextToSpeech<string>;
|
|
4
|
+
declare class TextToSpeechFactory {
|
|
5
|
+
private static engines;
|
|
6
|
+
static registerEngine<T extends TtsConfig>(name: string, ctor: EngineConstructor<T>): void;
|
|
7
|
+
static getEngine<T extends TtsConfig>(engineName: string, config: T): AbstractTextToSpeech<string>;
|
|
8
|
+
}
|
|
9
|
+
export { TextToSpeechFactory };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextToSpeechFactory = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 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 Azure_1 = require("./Azure");
|
|
24
|
+
const Google_1 = require("./Google");
|
|
25
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
26
|
+
class TextToSpeechFactory {
|
|
27
|
+
static registerEngine(name, ctor) {
|
|
28
|
+
logger.info("registering tts engine", { name });
|
|
29
|
+
this.engines.set(name, ctor);
|
|
30
|
+
}
|
|
31
|
+
static getEngine(engineName, config) {
|
|
32
|
+
const EngineConstructor = this.engines.get(engineName);
|
|
33
|
+
if (!EngineConstructor) {
|
|
34
|
+
throw new Error(`Engine ${engineName} not found`);
|
|
35
|
+
}
|
|
36
|
+
return new EngineConstructor(config);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.TextToSpeechFactory = TextToSpeechFactory;
|
|
40
|
+
TextToSpeechFactory.engines = new Map();
|
|
41
|
+
// Register engines
|
|
42
|
+
TextToSpeechFactory.registerEngine(Google_1.ENGINE_NAME, Google_1.Google);
|
|
43
|
+
TextToSpeechFactory.registerEngine(Azure_1.ENGINE_NAME, Azure_1.Azure);
|