@elizaos/plugin-elevenlabs 1.0.0-alpha.6 → 1.0.0-alpha.7
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 +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +72 -72
- package/dist/index.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { Readable } from "node:stream";
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
ModelTypes,
|
|
5
|
+
logger
|
|
5
6
|
} from "@elizaos/core";
|
|
6
|
-
import { Readable } from "node:stream";
|
|
7
7
|
|
|
8
8
|
// src/utils.ts
|
|
9
9
|
import { PassThrough } from "node:stream";
|
|
@@ -50,7 +50,7 @@ function prependWavHeader(readable, audioLength, sampleRate, channelCount = 1, b
|
|
|
50
50
|
function getVoiceSettings(runtime) {
|
|
51
51
|
const getSetting = (key, fallback = "") => process.env[key] || runtime.getSetting(key) || fallback;
|
|
52
52
|
return {
|
|
53
|
-
apiKey: getSetting("ELEVENLABS_XI_API_KEY"),
|
|
53
|
+
apiKey: getSetting("ELEVENLABS_API_KEY") || getSetting("ELEVENLABS_XI_API_KEY"),
|
|
54
54
|
voiceId: getSetting("ELEVENLABS_VOICE_ID", "EXAVITQu4vr4xnSDxMaL"),
|
|
55
55
|
model: getSetting("ELEVENLABS_MODEL_ID", "eleven_monolingual_v1"),
|
|
56
56
|
stability: getSetting("ELEVENLABS_VOICE_STABILITY", "0.5"),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n\ttype IAgentRuntime,\n\ttype Plugin,\n\tlogger,\n\tModelTypes,\n} from \"@elizaos/core\";\nimport { Readable } from \"node:stream\";\nimport { prependWavHeader } from \"./utils.ts\";\n\nfunction getVoiceSettings(runtime: IAgentRuntime) {\n\tconst getSetting = (key: string, fallback = \"\") =>\n\t\tprocess.env[key] || runtime.getSetting(key) || fallback;\n\n\treturn {\n\t\tapiKey: getSetting(\"ELEVENLABS_XI_API_KEY\"),\n\t\tvoiceId: getSetting(\"ELEVENLABS_VOICE_ID\", \"EXAVITQu4vr4xnSDxMaL\"),\n\t\tmodel: getSetting(\"ELEVENLABS_MODEL_ID\", \"eleven_monolingual_v1\"),\n\t\tstability: getSetting(\"ELEVENLABS_VOICE_STABILITY\", \"0.5\"),\n\t\tlatency: getSetting(\"ELEVENLABS_OPTIMIZE_STREAMING_LATENCY\", \"0\"),\n\t\toutputFormat: getSetting(\"ELEVENLABS_OUTPUT_FORMAT\", \"pcm_16000\"),\n\t\tsimilarity: getSetting(\"ELEVENLABS_VOICE_SIMILARITY_BOOST\", \"0.75\"),\n\t\tstyle: getSetting(\"ELEVENLABS_VOICE_STYLE\", \"0\"),\n\t\tspeakerBoost: getSetting(\"ELEVENLABS_VOICE_USE_SPEAKER_BOOST\", \"true\"),\n\t};\n}\n\nasync function fetchSpeech(runtime: IAgentRuntime, text: string) {\n\tconst settings = getVoiceSettings(runtime);\n\ttry {\n\t\tconst response = await fetch(\n\t\t\t`https://api.elevenlabs.io/v1/text-to-speech/${settings.voiceId}/stream?optimize_streaming_latency=${settings.latency}&output_format=${settings.outputFormat}`,\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\"xi-api-key\": settings.apiKey,\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tmodel_id: settings.model,\n\t\t\t\t\ttext,\n\t\t\t\t\tvoice_settings: {\n\t\t\t\t\t\tsimilarity_boost: settings.similarity,\n\t\t\t\t\t\tstability: settings.stability,\n\t\t\t\t\t\tstyle: settings.style,\n\t\t\t\t\t\tuse_speaker_boost: settings.speakerBoost,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tconst errorBodyString = await response.text();\n\t\t\tconst errorBody = JSON.parse(errorBodyString);\n\n\t\t\tif (\n\t\t\t\tresponse.status === 401 &&\n\t\t\t\terrorBody.detail?.status === \"quota_exceeded\"\n\t\t\t) {\n\t\t\t\tlogger.log(\"ElevenLabs quota exceeded\");\n\t\t\t\tthrow new Error(\"QUOTA_EXCEEDED\");\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t`Received status ${response.status} from Eleven Labs API: ${JSON.stringify(errorBody)}`,\n\t\t\t);\n\t\t}\n\t\treturn Readable.fromWeb(response.body);\n\t} catch (error) {\n\t\tthrow new Error(error);\n\t}\n}\n\nexport const elevenLabsPlugin: Plugin = {\n\tname: \"elevenLabs\",\n\tdescription: \"ElevenLabs plugin\",\n\tmodels: {\n\t\t[ModelTypes.TEXT_TO_SPEECH]: async (runtime, text) => {\n\t\t\ttry {\n\t\t\t\tconst stream = await fetchSpeech(runtime, text);\n\t\t\t\treturn getVoiceSettings(runtime).outputFormat.startsWith(\"pcm_\")\n\t\t\t\t\t? prependWavHeader(\n\t\t\t\t\t\t\tstream,\n\t\t\t\t\t\t\t1024 * 1024 * 100,\n\t\t\t\t\t\t\tNumber.parseInt(getVoiceSettings(runtime).outputFormat.slice(4)),\n\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t16,\n\t\t\t\t\t\t)\n\t\t\t\t\t: stream;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to fetch speech from Eleven Labs API: ${error.message || \"Unknown error occurred\"}`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t},\n\ttests: [\n\t\t{\n\t\t\tname: \"test eleven labs\",\n\t\t\ttests: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Eleven Labs API key validation\",\n\t\t\t\t\tfn: async (runtime: IAgentRuntime) => {\n\t\t\t\t\t\tif (!getVoiceSettings(runtime).apiKey) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"Missing API key: Please provide a valid Eleven Labs API key.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"Eleven Labs API response\",\n\t\t\t\t\tfn: async (runtime: IAgentRuntime) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait fetchSpeech(runtime, \"test\");\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Failed to fetch speech from Eleven Labs API: ${error.message || \"Unknown error occurred\"}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t],\n};\nexport default elevenLabsPlugin;\n","import { PassThrough } from \"node:stream\";\nimport type { Readable } from \"node:stream\";\n\nexport function getWavHeader(\n\taudioLength: number,\n\tsampleRate: number,\n\tchannelCount = 1,\n\tbitsPerSample = 16,\n): Buffer {\n\tconst wavHeader = Buffer.alloc(44);\n\twavHeader.write(\"RIFF\", 0);\n\twavHeader.writeUInt32LE(36 + audioLength, 4); // Length of entire file in bytes minus 8\n\twavHeader.write(\"WAVE\", 8);\n\twavHeader.write(\"fmt \", 12);\n\twavHeader.writeUInt32LE(16, 16); // Length of format data\n\twavHeader.writeUInt16LE(1, 20); // Type of format (1 is PCM)\n\twavHeader.writeUInt16LE(channelCount, 22); // Number of channels\n\twavHeader.writeUInt32LE(sampleRate, 24); // Sample rate\n\twavHeader.writeUInt32LE((sampleRate * bitsPerSample * channelCount) / 8, 28); // Byte rate\n\twavHeader.writeUInt16LE((bitsPerSample * channelCount) / 8, 32); // Block align ((BitsPerSample * Channels) / 8)\n\twavHeader.writeUInt16LE(bitsPerSample, 34); // Bits per sample\n\twavHeader.write(\"data\", 36); // Data chunk header\n\twavHeader.writeUInt32LE(audioLength, 40); // Data chunk size\n\treturn wavHeader;\n}\n\nexport function prependWavHeader(\n\treadable: Readable,\n\taudioLength: number,\n\tsampleRate: number,\n\tchannelCount = 1,\n\tbitsPerSample = 16,\n): Readable {\n\tconst wavHeader = getWavHeader(\n\t\taudioLength,\n\t\tsampleRate,\n\t\tchannelCount,\n\t\tbitsPerSample,\n\t);\n\tlet pushedHeader = false;\n\tconst passThrough = new PassThrough();\n\treadable.on(\"data\", (data) => {\n\t\tif (!pushedHeader) {\n\t\t\tpassThrough.push(wavHeader);\n\t\t\tpushedHeader = true;\n\t\t}\n\t\tpassThrough.push(data);\n\t});\n\treadable.on(\"end\", () => {\n\t\tpassThrough.end();\n\t});\n\treturn passThrough;\n}\n"],"mappings":";AAAA;AAAA,EAGC;AAAA,EACA;AAAA,OACM;AACP,SAAS,gBAAgB;;;ACNzB,SAAS,mBAAmB;AAGrB,SAAS,aACf,aACA,YACA,eAAe,GACf,gBAAgB,IACP;AACT,QAAM,YAAY,OAAO,MAAM,EAAE;AACjC,YAAU,MAAM,QAAQ,CAAC;AACzB,YAAU,cAAc,KAAK,aAAa,CAAC;AAC3C,YAAU,MAAM,QAAQ,CAAC;AACzB,YAAU,MAAM,QAAQ,EAAE;AAC1B,YAAU,cAAc,IAAI,EAAE;AAC9B,YAAU,cAAc,GAAG,EAAE;AAC7B,YAAU,cAAc,cAAc,EAAE;AACxC,YAAU,cAAc,YAAY,EAAE;AACtC,YAAU,cAAe,aAAa,gBAAgB,eAAgB,GAAG,EAAE;AAC3E,YAAU,cAAe,gBAAgB,eAAgB,GAAG,EAAE;AAC9D,YAAU,cAAc,eAAe,EAAE;AACzC,YAAU,MAAM,QAAQ,EAAE;AAC1B,YAAU,cAAc,aAAa,EAAE;AACvC,SAAO;AACR;AAEO,SAAS,iBACf,UACA,aACA,YACA,eAAe,GACf,gBAAgB,IACL;AACX,QAAM,YAAY;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,MAAI,eAAe;AACnB,QAAM,cAA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ACA;AAAA,UACC,MAAM;AAAA,UACN,IAAI,OAAO,YAA2B;AACrC,gBAAI;AACH,oBAAM,YAAY,SAAS,MAAM;AAAA,YAClC,SAAS,OAAO;AACf,oBAAM,IAAI;AAAA,gBACT,gDAAgD,MAAM,WAAW,wBAAwB;AAAA,cAC1F;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AACA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport {\n\ttype IAgentRuntime,\n\tModelTypes,\n\ttype Plugin,\n\tlogger,\n} from \"@elizaos/core\";\nimport { prependWavHeader } from \"./utils\";\n\n/**\n * Function to retrieve voice settings based on runtime and environment variables.\n * @param {IAgentRuntime} runtime - The agent runtime object.\n * @returns {Object} - Object containing various voice settings.\n */\nfunction getVoiceSettings(runtime: IAgentRuntime) {\n\tconst getSetting = (key: string, fallback = \"\") =>\n\t\tprocess.env[key] || runtime.getSetting(key) || fallback;\n\n\treturn {\n\t\tapiKey:\n\t\t\tgetSetting(\"ELEVENLABS_API_KEY\") || getSetting(\"ELEVENLABS_XI_API_KEY\"),\n\t\tvoiceId: getSetting(\"ELEVENLABS_VOICE_ID\", \"EXAVITQu4vr4xnSDxMaL\"),\n\t\tmodel: getSetting(\"ELEVENLABS_MODEL_ID\", \"eleven_monolingual_v1\"),\n\t\tstability: getSetting(\"ELEVENLABS_VOICE_STABILITY\", \"0.5\"),\n\t\tlatency: getSetting(\"ELEVENLABS_OPTIMIZE_STREAMING_LATENCY\", \"0\"),\n\t\toutputFormat: getSetting(\"ELEVENLABS_OUTPUT_FORMAT\", \"pcm_16000\"),\n\t\tsimilarity: getSetting(\"ELEVENLABS_VOICE_SIMILARITY_BOOST\", \"0.75\"),\n\t\tstyle: getSetting(\"ELEVENLABS_VOICE_STYLE\", \"0\"),\n\t\tspeakerBoost: getSetting(\"ELEVENLABS_VOICE_USE_SPEAKER_BOOST\", \"true\"),\n\t};\n}\n\n/**\n * Fetch speech from Eleven Labs API using given text and runtime settings.\n * @param {IAgentRuntime} runtime - The runtime interface containing necessary data for the API call.\n * @param {string} text - The text to be converted into speech.\n * @returns {Promise<Readable>} A promise resolving to a readable stream of the fetched speech.\n */\nasync function fetchSpeech(runtime: IAgentRuntime, text: string) {\n\tconst settings = getVoiceSettings(runtime);\n\ttry {\n\t\tconst response = await fetch(\n\t\t\t`https://api.elevenlabs.io/v1/text-to-speech/${settings.voiceId}/stream?optimize_streaming_latency=${settings.latency}&output_format=${settings.outputFormat}`,\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\"xi-api-key\": settings.apiKey,\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tmodel_id: settings.model,\n\t\t\t\t\ttext,\n\t\t\t\t\tvoice_settings: {\n\t\t\t\t\t\tsimilarity_boost: settings.similarity,\n\t\t\t\t\t\tstability: settings.stability,\n\t\t\t\t\t\tstyle: settings.style,\n\t\t\t\t\t\tuse_speaker_boost: settings.speakerBoost,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tconst errorBodyString = await response.text();\n\t\t\tconst errorBody = JSON.parse(errorBodyString);\n\n\t\t\tif (\n\t\t\t\tresponse.status === 401 &&\n\t\t\t\terrorBody.detail?.status === \"quota_exceeded\"\n\t\t\t) {\n\t\t\t\tlogger.log(\"ElevenLabs quota exceeded\");\n\t\t\t\tthrow new Error(\"QUOTA_EXCEEDED\");\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t`Received status ${response.status} from Eleven Labs API: ${JSON.stringify(errorBody)}`,\n\t\t\t);\n\t\t}\n\t\treturn Readable.fromWeb(response.body);\n\t} catch (error) {\n\t\tthrow new Error(error);\n\t}\n}\n\n/**\n * Represents the ElevenLabs plugin.\n * This plugin provides functionality related to ElevenLabs API, including text to speech conversion.\n * @type {Plugin}\n */\nexport const elevenLabsPlugin: Plugin = {\n\tname: \"elevenLabs\",\n\tdescription: \"ElevenLabs plugin\",\n\tmodels: {\n\t\t[ModelTypes.TEXT_TO_SPEECH]: async (runtime, text) => {\n\t\t\ttry {\n\t\t\t\tconst stream = await fetchSpeech(runtime, text);\n\t\t\t\treturn getVoiceSettings(runtime).outputFormat.startsWith(\"pcm_\")\n\t\t\t\t\t? prependWavHeader(\n\t\t\t\t\t\t\tstream,\n\t\t\t\t\t\t\t1024 * 1024 * 100,\n\t\t\t\t\t\t\tNumber.parseInt(getVoiceSettings(runtime).outputFormat.slice(4)),\n\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t16,\n\t\t\t\t\t\t)\n\t\t\t\t\t: stream;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to fetch speech from Eleven Labs API: ${error.message || \"Unknown error occurred\"}`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t},\n\ttests: [\n\t\t{\n\t\t\tname: \"test eleven labs\",\n\t\t\ttests: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Eleven Labs API key validation\",\n\t\t\t\t\tfn: async (runtime: IAgentRuntime) => {\n\t\t\t\t\t\tif (!getVoiceSettings(runtime).apiKey) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"Missing API key: Please provide a valid Eleven Labs API key.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"Eleven Labs API response\",\n\t\t\t\t\tfn: async (runtime: IAgentRuntime) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait fetchSpeech(runtime, \"test\");\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Failed to fetch speech from Eleven Labs API: ${error.message || \"Unknown error occurred\"}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t],\n};\nexport default elevenLabsPlugin;\n","import { PassThrough } from \"node:stream\";\nimport type { Readable } from \"node:stream\";\n\n/**\n * Generates a WAV file header based on the provided audio parameters.\n * @param {number} audioLength - The length of the audio data in bytes.\n * @param {number} sampleRate - The sample rate of the audio.\n * @param {number} [channelCount=1] - The number of channels (default is 1).\n * @param {number} [bitsPerSample=16] - The number of bits per sample (default is 16).\n * @returns {Buffer} The WAV file header as a Buffer object.\n */\nexport function getWavHeader(\n\taudioLength: number,\n\tsampleRate: number,\n\tchannelCount = 1,\n\tbitsPerSample = 16,\n): Buffer {\n\tconst wavHeader = Buffer.alloc(44);\n\twavHeader.write(\"RIFF\", 0);\n\twavHeader.writeUInt32LE(36 + audioLength, 4); // Length of entire file in bytes minus 8\n\twavHeader.write(\"WAVE\", 8);\n\twavHeader.write(\"fmt \", 12);\n\twavHeader.writeUInt32LE(16, 16); // Length of format data\n\twavHeader.writeUInt16LE(1, 20); // Type of format (1 is PCM)\n\twavHeader.writeUInt16LE(channelCount, 22); // Number of channels\n\twavHeader.writeUInt32LE(sampleRate, 24); // Sample rate\n\twavHeader.writeUInt32LE((sampleRate * bitsPerSample * channelCount) / 8, 28); // Byte rate\n\twavHeader.writeUInt16LE((bitsPerSample * channelCount) / 8, 32); // Block align ((BitsPerSample * Channels) / 8)\n\twavHeader.writeUInt16LE(bitsPerSample, 34); // Bits per sample\n\twavHeader.write(\"data\", 36); // Data chunk header\n\twavHeader.writeUInt32LE(audioLength, 40); // Data chunk size\n\treturn wavHeader;\n}\n\n/**\n * Prepends a WAV header to a readable stream of audio data.\n *\n * @param {Readable} readable - The readable stream containing the audio data.\n * @param {number} audioLength - The length of the audio data in seconds.\n * @param {number} sampleRate - The sample rate of the audio data.\n * @param {number} [channelCount=1] - The number of channels in the audio data (default is 1).\n * @param {number} [bitsPerSample=16] - The number of bits per sample in the audio data (default is 16).\n * @returns {Readable} A new readable stream with the WAV header prepended to the audio data.\n */\nexport function prependWavHeader(\n\treadable: Readable,\n\taudioLength: number,\n\tsampleRate: number,\n\tchannelCount = 1,\n\tbitsPerSample = 16,\n): Readable {\n\tconst wavHeader = getWavHeader(\n\t\taudioLength,\n\t\tsampleRate,\n\t\tchannelCount,\n\t\tbitsPerSample,\n\t);\n\tlet pushedHeader = false;\n\tconst passThrough = new PassThrough();\n\treadable.on(\"data\", (data) => {\n\t\tif (!pushedHeader) {\n\t\t\tpassThrough.push(wavHeader);\n\t\t\tpushedHeader = true;\n\t\t}\n\t\tpassThrough.push(data);\n\t});\n\treadable.on(\"end\", () => {\n\t\tpassThrough.end();\n\t});\n\treturn passThrough;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB;AAAA,EAEC;AAAA,EAEA;AAAA,OACM;;;ACNP,SAAS,mBAAmB;AAWrB,SAAS,aACf,aACA,YACA,eAAe,GACf,gBAAgB,IACP;AACT,QAAM,YAAY,OAAO,MAAM,EAAE;AACjC,YAAU,MAAM,QAAQ,CAAC;AACzB,YAAU,cAAc,KAAK,aAAa,CAAC;AAC3C,YAAU,MAAM,QAAQ,CAAC;AACzB,YAAU,MAAM,QAAQ,EAAE;AAC1B,YAAU,cAAc,IAAI,EAAE;AAC9B,YAAU,cAAc,GAAG,EAAE;AAC7B,YAAU,cAAc,cAAc,EAAE;AACxC,YAAU,cAAc,YAAY,EAAE;AACtC,YAAU,cAAe,aAAa,gBAAgB,eAAgB,GAAG,EAAE;AAC3E,YAAU,cAAe,gBAAgB,eAAgB,GAAG,EAAE;AAC9D,YAAU,cAAc,eAAe,EAAE;AACzC,YAAU,MAAM,QAAQ,EAAE;AAC1B,YAAU,cAAc,aAAa,EAAE;AACvC,SAAO;AACR;AAYO,SAAS,iBACf,UACA,aACA,YACA,eAAe,GACf,gBAAgB,IACL;AACX,QAAM,YAAY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AiB,OAAO,EAAE,QAAQ;AACtC,oBAAM,IAAI;AAAA,gBACT;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,IAAI,OAAO,YAA2B;AACrC,gBAAI;AACH,oBAAM,YAAY,SAAS,MAAM;AAAA,YAClC,SAAS,OAAO;AACf,oBAAM,IAAI;AAAA,gBACT,gDAAgD,MAAM,WAAW,wBAAwB;AAAA,cAC1F;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AACA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
2
|
+
"name": "@elizaos/plugin-elevenlabs",
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@elizaos/core": "^1.0.0-alpha.7",
|
|
22
|
+
"tsup": "8.4.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"test": "vitest run"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"agentConfig": {
|
|
33
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
34
|
+
"pluginParameters": {
|
|
35
|
+
"ELEVENLABS_API_KEY": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "API key for ElevenLabs."
|
|
38
|
+
},
|
|
39
|
+
"ELEVENLABS_VOICE_ID": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"description": "Optional. Voice selection ID."
|
|
42
|
+
},
|
|
43
|
+
"ELEVENLABS_MODEL_ID": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"description": "Optional. Speech model ID."
|
|
46
|
+
},
|
|
47
|
+
"ELEVENLABS_VOICE_STABILITY": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Optional. Controls voice stability."
|
|
50
|
+
},
|
|
51
|
+
"ELEVENLABS_OPTIMIZE_STREAMING_LATENCY": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "Optional. Adjusts streaming latency."
|
|
54
|
+
},
|
|
55
|
+
"ELEVENLABS_OUTPUT_FORMAT": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "Optional. Output format (e.g., pcm_16000)."
|
|
58
|
+
},
|
|
59
|
+
"ELEVENLABS_VOICE_SIMILARITY_BOOST": {
|
|
60
|
+
"type": "string",
|
|
61
|
+
"description": "Optional. Adjusts similarity to the reference voice (0-1)."
|
|
62
|
+
},
|
|
63
|
+
"ELEVENLABS_VOICE_STYLE": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"description": "Optional. Controls voice style intensity (0-1)."
|
|
66
|
+
},
|
|
67
|
+
"ELEVENLABS_VOICE_USE_SPEAKER_BOOST": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "Optional. Enhances speaker presence (true/false)."
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "45175c735affb7ea45b3d9efecde34223e782b79"
|
|
74
74
|
}
|