@elizaos/plugin-openai 1.0.0-beta.29 → 1.0.0-beta.32

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.js CHANGED
@@ -16992,6 +16992,35 @@ function getJsonRepairFunction() {
16992
16992
  }
16993
16993
  };
16994
16994
  }
16995
+ async function fetchTextToSpeech(runtime, text) {
16996
+ const apiKey = getApiKey(runtime);
16997
+ const model = getSetting(runtime, "OPENAI_TTS_MODEL", "gpt-4o-mini-tts");
16998
+ const voice = getSetting(runtime, "OPENAI_TTS_VOICE", "nova");
16999
+ const instructions = getSetting(runtime, "OPENAI_TTS_INSTRUCTIONS", "");
17000
+ const baseURL = getBaseURL(runtime);
17001
+ try {
17002
+ const res = await lib_default(`${baseURL}/audio/speech`, {
17003
+ method: "POST",
17004
+ headers: {
17005
+ Authorization: `Bearer ${apiKey}`,
17006
+ "Content-Type": "application/json"
17007
+ },
17008
+ body: JSON.stringify({
17009
+ model,
17010
+ voice,
17011
+ input: text,
17012
+ ...instructions && { instructions }
17013
+ })
17014
+ });
17015
+ if (!res.ok) {
17016
+ const err = await res.text();
17017
+ throw new Error(`OpenAI TTS error ${res.status}: ${err}`);
17018
+ }
17019
+ return res.body;
17020
+ } catch (err) {
17021
+ throw new Error(`Failed to fetch speech from OpenAI TTS: ${err.message || err}`);
17022
+ }
17023
+ }
16995
17024
  var openaiPlugin = {
16996
17025
  name: "openai",
16997
17026
  description: "OpenAI plugin",
@@ -17268,34 +17297,7 @@ var openaiPlugin = {
17268
17297
  return data.text;
17269
17298
  },
17270
17299
  [ModelType.TEXT_TO_SPEECH]: async (runtime, text) => {
17271
- const getSetting2 = (key, fallback = "") => process.env[key] || runtime.getSetting(key) || fallback;
17272
- const apiKey = getApiKey(runtime);
17273
- const model = getSetting2("OPENAI_TTS_MODEL", "gpt-4o-mini-tts");
17274
- const voice = getSetting2("OPENAI_TTS_VOICE", "nova");
17275
- const instructions = getSetting2("OPENAI_TTS_INSTRUCTIONS", "");
17276
- const baseURL = getBaseURL(runtime);
17277
- try {
17278
- const res = await lib_default(`${baseURL}/audio/speech`, {
17279
- method: "POST",
17280
- headers: {
17281
- Authorization: `Bearer ${apiKey}`,
17282
- "Content-Type": "application/json"
17283
- },
17284
- body: JSON.stringify({
17285
- model,
17286
- voice,
17287
- input: text,
17288
- ...instructions && { instructions }
17289
- })
17290
- });
17291
- if (!res.ok) {
17292
- const err = await res.text();
17293
- throw new Error(`OpenAI TTS error ${res.status}: ${err}`);
17294
- }
17295
- return res.body;
17296
- } catch (err) {
17297
- throw new Error(`Failed to fetch speech from OpenAI TTS: ${err.message || err}`);
17298
- }
17300
+ return await fetchTextToSpeech(runtime, text);
17299
17301
  },
17300
17302
  [ModelType.OBJECT_SMALL]: async (runtime, params) => {
17301
17303
  return generateObjectByModelType(runtime, params, ModelType.OBJECT_SMALL, getSmallModel);
@@ -17456,6 +17458,22 @@ var openaiPlugin = {
17456
17458
  }
17457
17459
  logger.log("Decoded text:", decodedText);
17458
17460
  }
17461
+ },
17462
+ {
17463
+ name: "openai_test_text_to_speech",
17464
+ fn: async (runtime) => {
17465
+ try {
17466
+ const text = "Hello, this is a test for text-to-speech.";
17467
+ const response = await fetchTextToSpeech(runtime, text);
17468
+ if (!response) {
17469
+ throw new Error("Failed to generate speech");
17470
+ }
17471
+ logger.log("Generated speech successfully");
17472
+ } catch (error) {
17473
+ logger.error("Error in openai_test_text_to_speech:", error);
17474
+ throw error;
17475
+ }
17476
+ }
17459
17477
  }
17460
17478
  ]
17461
17479
  }