@contentgrowth/llm-service 1.3.0 → 1.3.2

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/index.cjs CHANGED
@@ -342,6 +342,15 @@ var BaseLLMProvider = class {
342
342
  async imageGeneration(prompt, systemPrompt, options = {}) {
343
343
  throw new Error("Image generation not supported by this provider");
344
344
  }
345
+ /**
346
+ * Text-to-Speech synthesis
347
+ * @param {string} text - Text to synthesize
348
+ * @param {Object} options - TTS options (voice, model, etc.)
349
+ * @returns {Promise<Buffer>} Audio data as Buffer
350
+ */
351
+ async textToSpeech(text, options = {}) {
352
+ throw new Error("Text-to-speech not supported by this provider");
353
+ }
345
354
  /**
346
355
  * Start video generation (returns operation name for polling)
347
356
  * @param {string} prompt
@@ -1222,6 +1231,52 @@ ${prompt}` : prompt;
1222
1231
  throw error;
1223
1232
  }
1224
1233
  }
1234
+ /**
1235
+ * Text-to-Speech synthesis using Gemini TTS models
1236
+ * @param {string} text - Text to synthesize
1237
+ * @param {Object} options - TTS options
1238
+ * @param {string} options.voice - Voice name (default: 'Aoede')
1239
+ * @param {string} options.model - Model to use (default: from config)
1240
+ * @returns {Promise<Buffer>} Audio data as Buffer
1241
+ */
1242
+ async textToSpeech(text, options = {}) {
1243
+ var _a, _b, _c, _d, _e;
1244
+ const voice = options.voice || "Aoede";
1245
+ const modelName = options.model || this.models.tts || "gemini-3.1-flash-tts-preview";
1246
+ const requestOptions = {
1247
+ model: modelName,
1248
+ contents: [{
1249
+ role: "user",
1250
+ parts: [{ text }]
1251
+ }],
1252
+ config: {
1253
+ responseModalities: ["AUDIO"],
1254
+ speechConfig: {
1255
+ voiceConfig: {
1256
+ prebuiltVoiceConfig: {
1257
+ voiceName: voice
1258
+ }
1259
+ }
1260
+ }
1261
+ }
1262
+ };
1263
+ try {
1264
+ const response = await this._generateContent(requestOptions);
1265
+ const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1266
+ if (!candidate) {
1267
+ throw new LLMServiceException("No candidates returned from TTS model", 500);
1268
+ }
1269
+ const audioPart = (_c = (_b = candidate.content) == null ? void 0 : _b.parts) == null ? void 0 : _c.find((p) => p.inlineData || p.inline_data);
1270
+ const audioB64 = ((_d = audioPart == null ? void 0 : audioPart.inlineData) == null ? void 0 : _d.data) || ((_e = audioPart == null ? void 0 : audioPart.inline_data) == null ? void 0 : _e.data);
1271
+ if (!audioB64) {
1272
+ throw new LLMServiceException("No audio data returned from TTS model", 500);
1273
+ }
1274
+ return Buffer.from(audioB64, "base64");
1275
+ } catch (error) {
1276
+ console.error(`[${this.constructor.name}] textToSpeech failed (API Key: ${this._getMaskedApiKey()}):`, error);
1277
+ throw error;
1278
+ }
1279
+ }
1225
1280
  };
1226
1281
 
1227
1282
  // src/llm/providers/anthropic-provider.js
@@ -1692,6 +1747,17 @@ var LLMService = class {
1692
1747
  const provider = await this._getProvider(tenantId);
1693
1748
  return provider.imageGeneration(prompt, systemPrompt, options);
1694
1749
  }
1750
+ /**
1751
+ * Text-to-Speech synthesis
1752
+ * @param {string} text - Text to synthesize
1753
+ * @param {string} tenantId - Tenant identifier
1754
+ * @param {Object} options - TTS options (voice, model, etc.)
1755
+ * @returns {Promise<Buffer>} Audio data as Buffer
1756
+ */
1757
+ async textToSpeech(text, tenantId, options = {}) {
1758
+ const provider = await this._getProvider(tenantId);
1759
+ return provider.textToSpeech(text, options);
1760
+ }
1695
1761
  /**
1696
1762
  * Start a Deep Research task
1697
1763
  * @param {string} prompt - Research prompt/query