@fonoster/apiserver 0.7.10 → 0.7.11
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/utils/getApplicationValidationSchema.js +5 -2
- package/dist/core/filesServer.js +12 -8
- package/dist/core/seed.js +10 -0
- package/dist/voice/tts/ElevenLabs.d.ts +23 -0
- package/dist/voice/tts/ElevenLabs.js +111 -0
- package/dist/voice/tts/TextToSpeechFactory.js +2 -0
- package/package.json +6 -5
|
@@ -26,18 +26,21 @@ const Deepgram_1 = require("../../voice/stt/Deepgram");
|
|
|
26
26
|
const Google_1 = require("../../voice/stt/Google");
|
|
27
27
|
const Azure_1 = require("../../voice/tts/Azure");
|
|
28
28
|
const Deepgram_2 = require("../../voice/tts/Deepgram");
|
|
29
|
+
const ElevenLabs_1 = require("../../voice/tts/ElevenLabs");
|
|
29
30
|
const Google_2 = require("../../voice/tts/Google");
|
|
30
31
|
const MAX_NAME_MESSAGE = "Name must contain at most 255 characters";
|
|
31
32
|
const validators = {
|
|
32
33
|
ttsConfigValidators: {
|
|
33
34
|
"tts.google": Google_2.Google.getConfigValidationSchema,
|
|
34
35
|
"tts.azure": Azure_1.Azure.getConfigValidationSchema,
|
|
35
|
-
"tts.deepgram": Deepgram_2.Deepgram.getConfigValidationSchema
|
|
36
|
+
"tts.deepgram": Deepgram_2.Deepgram.getConfigValidationSchema,
|
|
37
|
+
"tts.elevenlabs": ElevenLabs_1.ElevenLabs.getConfigValidationSchema
|
|
36
38
|
},
|
|
37
39
|
ttsCredentialsValidators: {
|
|
38
40
|
"tts.google": Google_2.Google.getCredentialsValidationSchema,
|
|
39
41
|
"tts.azure": Azure_1.Azure.getCredentialsValidationSchema,
|
|
40
|
-
"tts.deepgram": Deepgram_2.Deepgram.getCredentialsValidationSchema
|
|
42
|
+
"tts.deepgram": Deepgram_2.Deepgram.getCredentialsValidationSchema,
|
|
43
|
+
"tts.elevenlabs": ElevenLabs_1.ElevenLabs.getCredentialsValidationSchema
|
|
41
44
|
},
|
|
42
45
|
sttConfigValidators: {
|
|
43
46
|
"stt.google": Google_1.Google.getConfigValidationSchema,
|
package/dist/core/filesServer.js
CHANGED
|
@@ -32,18 +32,22 @@ function filesServer(params) {
|
|
|
32
32
|
const { pathToFiles, port } = params;
|
|
33
33
|
const app = (0, express_1.default)();
|
|
34
34
|
app.get("/sounds/:file", (req, res) => {
|
|
35
|
-
|
|
35
|
+
const filePath = (0, path_1.join)(pathToFiles, req.params.file);
|
|
36
|
+
fs_1.default.access(filePath, fs_1.default.constants.F_OK, (err) => {
|
|
36
37
|
if (err) {
|
|
37
|
-
res.status(404).send("
|
|
38
|
+
res.status(404).send("File not found!");
|
|
39
|
+
return;
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
res.setHeader("content-type", CONTENT_TYPE);
|
|
42
|
+
const readStream = fs_1.default.createReadStream(filePath);
|
|
43
|
+
readStream.on("error", (error) => {
|
|
44
|
+
logger.error(`Error reading file: ${error.message}`);
|
|
45
|
+
res.status(500).send("Error reading file!");
|
|
46
|
+
});
|
|
47
|
+
readStream.pipe(res);
|
|
44
48
|
});
|
|
45
49
|
});
|
|
46
50
|
app.listen(port, () => {
|
|
47
|
-
logger.info(`
|
|
51
|
+
logger.info(`Files server is running on port ${port}`);
|
|
48
52
|
});
|
|
49
53
|
}
|
package/dist/core/seed.js
CHANGED
|
@@ -73,6 +73,16 @@ function main() {
|
|
|
73
73
|
type: "TTS"
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
+
yield prisma.product.upsert({
|
|
77
|
+
where: { ref: "tts.elevenlabs" },
|
|
78
|
+
update: {},
|
|
79
|
+
create: {
|
|
80
|
+
ref: "tts.elevenlabs",
|
|
81
|
+
name: "Eleven Labs Text-to-Speech",
|
|
82
|
+
vendor: "ELEVEN_LABS",
|
|
83
|
+
type: "TTS"
|
|
84
|
+
}
|
|
85
|
+
});
|
|
76
86
|
yield prisma.product.upsert({
|
|
77
87
|
where: { ref: "llm.openai" },
|
|
78
88
|
update: {},
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ElevenLabsClient } from "elevenlabs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import { AbstractTextToSpeech } from "./AbstractTextToSpeech";
|
|
4
|
+
import { SynthOptions, TtsConfig } from "./types";
|
|
5
|
+
declare const ENGINE_NAME = "tts.elevenlabs";
|
|
6
|
+
type ElevenLabsTtsConfig = TtsConfig & {
|
|
7
|
+
[key: string]: Record<string, string>;
|
|
8
|
+
credentials: {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare class ElevenLabs extends AbstractTextToSpeech<typeof ENGINE_NAME> {
|
|
13
|
+
client: ElevenLabsClient;
|
|
14
|
+
engineConfig: ElevenLabsTtsConfig;
|
|
15
|
+
readonly engineName = "tts.elevenlabs";
|
|
16
|
+
protected readonly OUTPUT_FORMAT = "sln16";
|
|
17
|
+
protected readonly CACHING_FIELDS: string[];
|
|
18
|
+
constructor(config: ElevenLabsTtsConfig);
|
|
19
|
+
synthesize(text: string, options: SynthOptions): Promise<string>;
|
|
20
|
+
static getConfigValidationSchema(): z.Schema;
|
|
21
|
+
static getCredentialsValidationSchema(): z.Schema;
|
|
22
|
+
}
|
|
23
|
+
export { ENGINE_NAME, ElevenLabs };
|
|
@@ -0,0 +1,111 @@
|
|
|
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.ElevenLabs = exports.ENGINE_NAME = 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 common_1 = require("@fonoster/common");
|
|
56
|
+
const logger_1 = require("@fonoster/logger");
|
|
57
|
+
const elevenlabs_1 = require("elevenlabs");
|
|
58
|
+
const z = __importStar(require("zod"));
|
|
59
|
+
const AbstractTextToSpeech_1 = require("./AbstractTextToSpeech");
|
|
60
|
+
const isSsml_1 = require("./isSsml");
|
|
61
|
+
const ENGINE_NAME = "tts.elevenlabs";
|
|
62
|
+
exports.ENGINE_NAME = ENGINE_NAME;
|
|
63
|
+
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
64
|
+
class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
65
|
+
constructor(config) {
|
|
66
|
+
super(config);
|
|
67
|
+
this.engineName = ENGINE_NAME;
|
|
68
|
+
this.OUTPUT_FORMAT = "sln16";
|
|
69
|
+
this.CACHING_FIELDS = ["voice", "text"];
|
|
70
|
+
this.client = new elevenlabs_1.ElevenLabsClient(config.credentials);
|
|
71
|
+
this.engineConfig = config;
|
|
72
|
+
}
|
|
73
|
+
synthesize(text, options) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
logger.verbose(`synthesize [input: ${text}, isSsml=${(0, isSsml_1.isSsml)(text)} options: ${JSON.stringify(options)}]`);
|
|
76
|
+
const effectiveOptions = Object.assign(Object.assign({}, this.engineConfig), options);
|
|
77
|
+
const { voice } = this.engineConfig.config;
|
|
78
|
+
const filename = this.createFilename(text, effectiveOptions);
|
|
79
|
+
if (this.fileExists(this.getFullPathToFile(filename))) {
|
|
80
|
+
return this.getFilenameWithoutExtension(filename);
|
|
81
|
+
}
|
|
82
|
+
const response = yield this.client.generate({
|
|
83
|
+
voice,
|
|
84
|
+
text,
|
|
85
|
+
// TODO: This should be configurable
|
|
86
|
+
model_id: "eleven_turbo_v2_5",
|
|
87
|
+
output_format: "pcm_16000"
|
|
88
|
+
});
|
|
89
|
+
const writable = fs.createWriteStream(this.getFullPathToFile(filename), {
|
|
90
|
+
encoding: "binary"
|
|
91
|
+
});
|
|
92
|
+
yield new Promise((resolve, reject) => {
|
|
93
|
+
response.pipe(writable);
|
|
94
|
+
writable.on("finish", resolve);
|
|
95
|
+
writable.on("error", reject);
|
|
96
|
+
});
|
|
97
|
+
return this.getFilenameWithoutExtension(filename);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
static getConfigValidationSchema() {
|
|
101
|
+
return z.object({
|
|
102
|
+
voice: z.nativeEnum(common_1.ElevenLabsVoice)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
static getCredentialsValidationSchema() {
|
|
106
|
+
return z.object({
|
|
107
|
+
apiKey: z.string()
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.ElevenLabs = ElevenLabs;
|
|
@@ -22,6 +22,7 @@ exports.TextToSpeechFactory = void 0;
|
|
|
22
22
|
const logger_1 = require("@fonoster/logger");
|
|
23
23
|
const Azure_1 = require("./Azure");
|
|
24
24
|
const Deepgram_1 = require("./Deepgram");
|
|
25
|
+
const ElevenLabs_1 = require("./ElevenLabs");
|
|
25
26
|
const Google_1 = require("./Google");
|
|
26
27
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
27
28
|
class TextToSpeechFactory {
|
|
@@ -43,3 +44,4 @@ TextToSpeechFactory.engines = new Map();
|
|
|
43
44
|
TextToSpeechFactory.registerEngine(Google_1.ENGINE_NAME, Google_1.Google);
|
|
44
45
|
TextToSpeechFactory.registerEngine(Azure_1.ENGINE_NAME, Azure_1.Azure);
|
|
45
46
|
TextToSpeechFactory.registerEngine(Deepgram_1.ENGINE_NAME, Deepgram_1.Deepgram);
|
|
47
|
+
TextToSpeechFactory.registerEngine(ElevenLabs_1.ENGINE_NAME, ElevenLabs_1.ElevenLabs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.11",
|
|
4
4
|
"description": "APIServer for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@deepgram/sdk": "^3.5.1",
|
|
24
|
-
"@fonoster/common": "^0.7.
|
|
25
|
-
"@fonoster/identity": "^0.7.
|
|
24
|
+
"@fonoster/common": "^0.7.11",
|
|
25
|
+
"@fonoster/identity": "^0.7.11",
|
|
26
26
|
"@fonoster/logger": "^0.7.10",
|
|
27
|
-
"@fonoster/sipnet": "^0.7.
|
|
27
|
+
"@fonoster/sipnet": "^0.7.11",
|
|
28
28
|
"@fonoster/streams": "^0.7.10",
|
|
29
29
|
"@fonoster/types": "^0.7.10",
|
|
30
30
|
"@google-cloud/speech": "^6.6.0",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@routr/sdk": "^2.13.1",
|
|
37
37
|
"ari-client": "^2.2.0",
|
|
38
38
|
"dotenv": "^16.4.5",
|
|
39
|
+
"elevenlabs": "^0.15.0",
|
|
39
40
|
"express": "^4.19.2",
|
|
40
41
|
"grpc-health-check": "^2.0.1",
|
|
41
42
|
"jsonwebtoken": "^9.0.2",
|
|
@@ -71,5 +72,5 @@
|
|
|
71
72
|
"@types/uuid": "^9.0.8",
|
|
72
73
|
"@types/validator": "^13.12.0"
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "5c7629ecbe633d2d44fca0d9de8a24a38f4a4097"
|
|
75
76
|
}
|