@fonoster/apiserver 0.7.23 → 0.7.24

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/core/seed.js CHANGED
@@ -93,6 +93,16 @@ function main() {
93
93
  type: "ASSISTANT"
94
94
  }
95
95
  });
96
+ yield prisma.product.upsert({
97
+ where: { ref: "tts.azure" },
98
+ update: {},
99
+ create: {
100
+ ref: "tts.azure",
101
+ name: "Azure Text-to-Speech",
102
+ vendor: "MICROSOFT",
103
+ type: "TTS"
104
+ }
105
+ });
96
106
  });
97
107
  }
98
108
  main()
@@ -1,5 +1,4 @@
1
1
  import { Readable } from "stream";
2
- import * as sdk from "microsoft-cognitiveservices-speech-sdk";
3
2
  import * as z from "zod";
4
3
  import { AbstractTextToSpeech } from "./AbstractTextToSpeech";
5
4
  import { SynthOptions } from "./types";
@@ -21,12 +20,7 @@ declare class Azure extends AbstractTextToSpeech<typeof ENGINE_NAME> {
21
20
  ref: string;
22
21
  stream: Readable;
23
22
  }>;
24
- doSynthesize(params: {
25
- text: string;
26
- speechConfig: sdk.SpeechConfig;
27
- isSSML?: boolean;
28
- }): Promise<unknown>;
29
- getConfigValidationSchema(): z.Schema;
30
- getCredentialsValidationSchema(): z.Schema;
23
+ static getConfigValidationSchema(): z.Schema;
24
+ static getCredentialsValidationSchema(): z.Schema;
31
25
  }
32
26
  export { Azure, ENGINE_NAME };
@@ -61,7 +61,6 @@ const isSsml_1 = require("./isSsml");
61
61
  const ENGINE_NAME = "tts.azure";
62
62
  exports.ENGINE_NAME = ENGINE_NAME;
63
63
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
64
- // XXX: Must re-implement to provide an id an a Readable stream
65
64
  class Azure extends AbstractTextToSpeech_1.AbstractTextToSpeech {
66
65
  constructor(config) {
67
66
  super();
@@ -78,44 +77,36 @@ class Azure extends AbstractTextToSpeech_1.AbstractTextToSpeech {
78
77
  speechConfig.speechSynthesisVoiceName = options.voice;
79
78
  speechConfig.speechSynthesisOutputFormat =
80
79
  sdk.SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm;
81
- yield this.doSynthesize({
82
- text,
83
- speechConfig,
84
- isSSML: (0, isSsml_1.isSsml)(text)
85
- });
86
- const ref = this.createMediaReference();
87
- // TODO: Fix this placeholder
88
- return { ref, stream: new stream_1.Readable() };
89
- });
90
- }
91
- doSynthesize(params) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const { text, speechConfig } = params;
94
80
  const synthesizer = new sdk.SpeechSynthesizer(speechConfig);
95
- // FIXME: Let's turn this into constants
96
- const func = params.isSSML ? "speakSsmlAsync" : "speakTextAsync";
97
- return new Promise((resolve, reject) => {
98
- synthesizer[func](text, function (result) {
81
+ const isSSML = (0, isSsml_1.isSsml)(text);
82
+ const func = isSSML ? "speakSsmlAsync" : "speakTextAsync";
83
+ const audioData = yield new Promise((resolve, reject) => {
84
+ const audioChunks = [];
85
+ synthesizer[func](text, (result) => {
99
86
  if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
100
- resolve("");
87
+ audioChunks.push(Buffer.from(result.audioData));
88
+ resolve(Buffer.concat(audioChunks));
101
89
  }
102
90
  else {
103
- reject(new Error("speech synthesis canceled: " + result.errorDetails));
91
+ reject(new Error("Speech synthesis canceled: " + result.errorDetails));
104
92
  }
105
93
  synthesizer.close();
106
- }, function (err) {
94
+ }, (err) => {
107
95
  synthesizer.close();
108
96
  reject(new Error(err));
109
97
  });
110
98
  });
99
+ const ref = this.createMediaReference();
100
+ const stream = stream_1.Readable.from(audioData);
101
+ return { ref, stream };
111
102
  });
112
103
  }
113
- getConfigValidationSchema() {
104
+ static getConfigValidationSchema() {
114
105
  return z.object({
115
106
  voice: z.nativeEnum(common_1.AzureVoice)
116
107
  });
117
108
  }
118
- getCredentialsValidationSchema() {
109
+ static getCredentialsValidationSchema() {
119
110
  return z.object({
120
111
  subscriptionKey: z.string(),
121
112
  serviceRegion: z.string()
@@ -33,6 +33,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.ENGINE_NAME = exports.Deepgram = 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 stream_1 = require("stream");
36
55
  const common_1 = require("@fonoster/common");
37
56
  const logger_1 = require("@fonoster/logger");
38
57
  const z = __importStar(require("zod"));
@@ -65,8 +84,7 @@ class Deepgram extends AbstractTextToSpeech_1.AbstractTextToSpeech {
65
84
  container: "none"
66
85
  });
67
86
  const ref = this.createMediaReference();
68
- // TODO: Needs testing
69
- return { ref, stream: yield response.getStream() };
87
+ return { ref, stream: stream_1.Readable.from(yield response.getStream()) };
70
88
  });
71
89
  }
72
90
  static getConfigValidationSchema() {
@@ -88,10 +88,9 @@ class Google extends AbstractTextToSpeech_1.AbstractTextToSpeech {
88
88
  name: voice
89
89
  }
90
90
  };
91
- yield this.client.synthesizeSpeech(request);
91
+ const [response] = yield this.client.synthesizeSpeech(request);
92
92
  const ref = this.createMediaReference();
93
- // TODO: Fix this placeholder
94
- return { ref, stream: new stream_1.Readable() };
93
+ return { ref, stream: stream_1.Readable.from(response.audioContent) };
95
94
  });
96
95
  }
97
96
  static getConfigValidationSchema() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.7.23",
3
+ "version": "0.7.24",
4
4
  "description": "APIServer for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -72,5 +72,5 @@
72
72
  "@types/uuid": "^9.0.8",
73
73
  "@types/validator": "^13.12.0"
74
74
  },
75
- "gitHead": "eaf6ffdfdaaed15b6077f36b0aaa529d5eed8048"
75
+ "gitHead": "58b141dc01f99f0aa903cad5497d12cd474f79df"
76
76
  }