@contentgrowth/llm-service 1.3.0 → 1.3.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/dist/index.cjs CHANGED
@@ -1222,6 +1222,52 @@ ${prompt}` : prompt;
1222
1222
  throw error;
1223
1223
  }
1224
1224
  }
1225
+ /**
1226
+ * Text-to-Speech synthesis using Gemini TTS models
1227
+ * @param {string} text - Text to synthesize
1228
+ * @param {Object} options - TTS options
1229
+ * @param {string} options.voice - Voice name (default: 'Aoede')
1230
+ * @param {string} options.model - Model to use (default: from config)
1231
+ * @returns {Promise<Buffer>} Audio data as Buffer
1232
+ */
1233
+ async textToSpeech(text, options = {}) {
1234
+ var _a, _b, _c, _d, _e;
1235
+ const voice = options.voice || "Aoede";
1236
+ const modelName = options.model || this.models.tts || "gemini-3.1-flash-tts-preview";
1237
+ const requestOptions = {
1238
+ model: modelName,
1239
+ contents: [{
1240
+ role: "user",
1241
+ parts: [{ text }]
1242
+ }],
1243
+ config: {
1244
+ responseModalities: ["AUDIO"],
1245
+ speechConfig: {
1246
+ voiceConfig: {
1247
+ prebuiltVoiceConfig: {
1248
+ voiceName: voice
1249
+ }
1250
+ }
1251
+ }
1252
+ }
1253
+ };
1254
+ try {
1255
+ const response = await this._generateContent(requestOptions);
1256
+ const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1257
+ if (!candidate) {
1258
+ throw new LLMServiceException("No candidates returned from TTS model", 500);
1259
+ }
1260
+ const audioPart = (_c = (_b = candidate.content) == null ? void 0 : _b.parts) == null ? void 0 : _c.find((p) => p.inlineData || p.inline_data);
1261
+ 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);
1262
+ if (!audioB64) {
1263
+ throw new LLMServiceException("No audio data returned from TTS model", 500);
1264
+ }
1265
+ return Buffer.from(audioB64, "base64");
1266
+ } catch (error) {
1267
+ console.error(`[${this.constructor.name}] textToSpeech failed (API Key: ${this._getMaskedApiKey()}):`, error);
1268
+ throw error;
1269
+ }
1270
+ }
1225
1271
  };
1226
1272
 
1227
1273
  // src/llm/providers/anthropic-provider.js