@elizaos/plugin-elevenlabs 1.0.0-beta.48 → 1.0.0-beta.51
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/README.md +60 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +17 -11
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# ElevenLabs Plugin
|
|
2
|
+
|
|
3
|
+
This plugin provides integration with ElevenLabs text-to-speech services through the ElizaOS platform.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Add the plugin to your character configuration:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
"plugins": ["@elizaos-plugins/plugin-elevenlabs"]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
The plugin requires these environment variables (can be set in .env file or character settings):
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
"settings": {
|
|
19
|
+
"ELEVENLABS_API_KEY": "your_elevenlabs_api_key",
|
|
20
|
+
"ELEVENLABS_VOICE_ID": "EXAVITQu4vr4xnSDxMaL",
|
|
21
|
+
"ELEVENLABS_MODEL_ID": "eleven_monolingual_v1",
|
|
22
|
+
"ELEVENLABS_VOICE_STABILITY": "0.5",
|
|
23
|
+
"ELEVENLABS_OPTIMIZE_STREAMING_LATENCY": "0",
|
|
24
|
+
"ELEVENLABS_OUTPUT_FORMAT": "pcm_16000",
|
|
25
|
+
"ELEVENLABS_VOICE_SIMILARITY_BOOST": "0.75",
|
|
26
|
+
"ELEVENLABS_VOICE_STYLE": "0",
|
|
27
|
+
"ELEVENLABS_VOICE_USE_SPEAKER_BOOST": "true"
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or in `.env` file:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
ELEVENLABS_API_KEY=your_elevenlabs_api_key
|
|
35
|
+
# Optional overrides:
|
|
36
|
+
ELEVENLABS_VOICE_ID=EXAVITQu4vr4xnSDxMaL
|
|
37
|
+
ELEVENLABS_MODEL_ID=eleven_monolingual_v1
|
|
38
|
+
ELEVENLABS_VOICE_STABILITY=0.5
|
|
39
|
+
ELEVENLABS_OPTIMIZE_STREAMING_LATENCY=0
|
|
40
|
+
ELEVENLABS_OUTPUT_FORMAT=pcm_16000
|
|
41
|
+
ELEVENLABS_VOICE_SIMILARITY_BOOST=0.75
|
|
42
|
+
ELEVENLABS_VOICE_STYLE=0
|
|
43
|
+
ELEVENLABS_VOICE_USE_SPEAKER_BOOST=true
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Configuration Options
|
|
47
|
+
|
|
48
|
+
- `ELEVENLABS_API_KEY` (required): Your ElevenLabs API credentials.
|
|
49
|
+
- `ELEVENLABS_VOICE_ID`: Optional. Voice selection ID. Defaults to `EXAVITQu4vr4xnSDxMaL`.
|
|
50
|
+
- `ELEVENLABS_MODEL_ID`: Optional. Speech model ID. Defaults to `eleven_monolingual_v1`.
|
|
51
|
+
- `ELEVENLABS_VOICE_STABILITY`: Optional. Controls voice stability. Defaults to `0.5`.
|
|
52
|
+
- `ELEVENLABS_OPTIMIZE_STREAMING_LATENCY`: Optional. Adjusts streaming latency. Defaults to `0`.
|
|
53
|
+
- `ELEVENLABS_OUTPUT_FORMAT`: Optional. Output format (e.g., pcm_16000). Defaults to `pcm_16000`.
|
|
54
|
+
- `ELEVENLABS_VOICE_SIMILARITY_BOOST`: Optional. Adjusts similarity to the reference voice (0-1). Defaults to `0.75`.
|
|
55
|
+
- `ELEVENLABS_VOICE_STYLE`: Optional. Controls voice style intensity (0-1). Defaults to `0`.
|
|
56
|
+
- `ELEVENLABS_VOICE_USE_SPEAKER_BOOST`: Optional. Enhances speaker presence (true/false). Defaults to `true`.
|
|
57
|
+
|
|
58
|
+
The plugin provides the following model type:
|
|
59
|
+
|
|
60
|
+
- `TEXT_TO_SPEECH`: Converts text into spoken audio.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from '@elizaos/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the ElevenLabs plugin.
|
|
5
|
+
* This plugin provides functionality related to ElevenLabs API, including text to speech conversion.
|
|
6
|
+
* @type {Plugin}
|
|
7
|
+
*/
|
|
8
|
+
declare const elevenLabsPlugin: Plugin;
|
|
9
|
+
|
|
10
|
+
export { elevenLabsPlugin as default, elevenLabsPlugin };
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,9 @@ function getVoiceSettings(runtime) {
|
|
|
17
17
|
outputFormat: getSetting("ELEVENLABS_OUTPUT_FORMAT", "pcm_16000"),
|
|
18
18
|
similarity: getSetting("ELEVENLABS_VOICE_SIMILARITY_BOOST", "0.75"),
|
|
19
19
|
style: getSetting("ELEVENLABS_VOICE_STYLE", "0"),
|
|
20
|
-
speakerBoost: parseBooleanFromText(
|
|
20
|
+
speakerBoost: parseBooleanFromText(
|
|
21
|
+
getSetting("ELEVENLABS_VOICE_USE_SPEAKER_BOOST", "true")
|
|
22
|
+
)
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
async function fetchSpeech(runtime, text) {
|
|
@@ -48,15 +50,19 @@ async function fetchSpeech(runtime, text) {
|
|
|
48
50
|
const errorBody = JSON.parse(errorBodyString);
|
|
49
51
|
if (response.status === 401 && errorBody.detail?.status === "quota_exceeded") {
|
|
50
52
|
logger.log("ElevenLabs quota exceeded");
|
|
51
|
-
throw
|
|
53
|
+
throw logger.error("QUOTA_EXCEEDED");
|
|
52
54
|
}
|
|
53
|
-
throw
|
|
55
|
+
throw logger.error(
|
|
54
56
|
`Received status ${response.status} from Eleven Labs API: ${JSON.stringify(errorBody)}`
|
|
55
57
|
);
|
|
56
58
|
}
|
|
59
|
+
if (!response.body) {
|
|
60
|
+
throw logger.error("Empty response body from Eleven Labs API");
|
|
61
|
+
}
|
|
57
62
|
return Readable.fromWeb(response.body);
|
|
58
63
|
} catch (error) {
|
|
59
|
-
|
|
64
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
65
|
+
throw logger.error(msg);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
var elevenLabsPlugin = {
|
|
@@ -76,9 +82,8 @@ var elevenLabsPlugin = {
|
|
|
76
82
|
16
|
|
77
83
|
) : stream;
|
|
78
84
|
} catch (error) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
85
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
86
|
+
throw logger.error(msg);
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
89
|
},
|
|
@@ -90,7 +95,9 @@ var elevenLabsPlugin = {
|
|
|
90
95
|
name: "Eleven Labs API key validation",
|
|
91
96
|
fn: async (runtime) => {
|
|
92
97
|
if (!getVoiceSettings(runtime).apiKey) {
|
|
93
|
-
throw new Error(
|
|
98
|
+
throw new Error(
|
|
99
|
+
"Missing API key: Please provide a valid Eleven Labs API key."
|
|
100
|
+
);
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
},
|
|
@@ -100,9 +107,8 @@ var elevenLabsPlugin = {
|
|
|
100
107
|
try {
|
|
101
108
|
await fetchSpeech(runtime, "test");
|
|
102
109
|
} catch (error) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
);
|
|
110
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
111
|
+
throw logger.error(msg);
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n type IAgentRuntime,\n ModelType,\n type Plugin,\n logger,\n prependWavHeader,\n parseBooleanFromText,\n} from
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n type IAgentRuntime,\n ModelType,\n type Plugin,\n logger,\n prependWavHeader,\n parseBooleanFromText,\n} from \"@elizaos/core\";\nimport { Readable } from \"node:stream\";\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 const getSetting = (key: string, fallback = \"\") =>\n process.env[key] || runtime.getSetting(key) || fallback;\n\n return {\n apiKey:\n getSetting(\"ELEVENLABS_API_KEY\") || getSetting(\"ELEVENLABS_XI_API_KEY\"),\n voiceId: getSetting(\"ELEVENLABS_VOICE_ID\", \"EXAVITQu4vr4xnSDxMaL\"),\n model: getSetting(\"ELEVENLABS_MODEL_ID\", \"eleven_monolingual_v1\"),\n stability: getSetting(\"ELEVENLABS_VOICE_STABILITY\", \"0.5\"),\n latency: getSetting(\"ELEVENLABS_OPTIMIZE_STREAMING_LATENCY\", \"0\"),\n outputFormat: getSetting(\"ELEVENLABS_OUTPUT_FORMAT\", \"pcm_16000\"),\n similarity: getSetting(\"ELEVENLABS_VOICE_SIMILARITY_BOOST\", \"0.75\"),\n style: getSetting(\"ELEVENLABS_VOICE_STYLE\", \"0\"),\n speakerBoost: parseBooleanFromText(\n getSetting(\"ELEVENLABS_VOICE_USE_SPEAKER_BOOST\", \"true\")\n ),\n };\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 const settings = getVoiceSettings(runtime);\n try {\n const response = await fetch(\n `https://api.elevenlabs.io/v1/text-to-speech/${settings.voiceId}/stream?optimize_streaming_latency=${settings.latency}&output_format=${settings.outputFormat}`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"xi-api-key\": settings.apiKey,\n },\n body: JSON.stringify({\n model_id: settings.model,\n text,\n voice_settings: {\n similarity_boost: settings.similarity,\n stability: settings.stability,\n style: settings.style,\n use_speaker_boost: settings.speakerBoost,\n },\n }),\n }\n );\n if (response.status !== 200) {\n const errorBodyString = await response.text();\n const errorBody = JSON.parse(errorBodyString);\n\n if (\n response.status === 401 &&\n errorBody.detail?.status === \"quota_exceeded\"\n ) {\n logger.log(\"ElevenLabs quota exceeded\");\n throw logger.error(\"QUOTA_EXCEEDED\");\n }\n throw logger.error(\n `Received status ${response.status} from Eleven Labs API: ${JSON.stringify(errorBody)}`\n );\n }\n\n if (!response.body) {\n throw logger.error(\"Empty response body from Eleven Labs API\");\n }\n\n return Readable.fromWeb(response.body);\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : String(error);\n throw logger.error(msg);\n }\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 name: \"elevenLabs\",\n description: \"ElevenLabs plugin\",\n models: {\n [ModelType.TEXT_TO_SPEECH]: async (runtime, text) => {\n const settings = getVoiceSettings(runtime);\n logger.log(`[ElevenLabs] Using TEXT_TO_SPEECH model: ${settings.model}`);\n try {\n const stream = await fetchSpeech(runtime, text);\n return settings.outputFormat.startsWith(\"pcm_\")\n ? prependWavHeader(\n stream,\n 1024 * 1024 * 100,\n Number.parseInt(settings.outputFormat.slice(4)),\n 1,\n 16\n )\n : stream;\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : String(error);\n throw logger.error(msg);\n }\n },\n },\n tests: [\n {\n name: \"test eleven labs\",\n tests: [\n {\n name: \"Eleven Labs API key validation\",\n fn: async (runtime: IAgentRuntime) => {\n if (!getVoiceSettings(runtime).apiKey) {\n throw new Error(\n \"Missing API key: Please provide a valid Eleven Labs API key.\"\n );\n }\n },\n },\n {\n name: \"Eleven Labs API response\",\n fn: async (runtime: IAgentRuntime) => {\n try {\n await fetchSpeech(runtime, \"test\");\n } catch (error: unknown) {\n const msg =\n error instanceof Error ? error.message : String(error);\n throw logger.error(msg);\n }\n },\n },\n ],\n },\n ],\n};\nexport default elevenLabsPlugin;\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAOzB,SAAS,iBAAiB,SAAwB;AAChD,QAAM,aAAa,CAAC,KAAa,WAAW,OAC1C,QAAQ,IAAI,GAAG,KAAK,QAAQ,WAAW,GAAG,KAAK;AAEjD,SAAO;AAAA,IACL,QACE,WAAW,oBAAoB,KAAK,WAAW,uBAAuB;AAAA,IACxE,SAAS,WAAW,uBAAuB,sBAAsB;AAAA,IACjE,OAAO,WAAW,uBAAuB,uBAAuB;AAAA,IAChE,WAAW,WAAW,8BAA8B,KAAK;AAAA,IACzD,SAAS,WAAW,yCAAyC,GAAG;AAAA,IAChE,cAAc,WAAW,4BAA4B,WAAW;AAAA,IAChE,YAAY,WAAW,qCAAqC,MAAM;AAAA,IAClE,OAAO,WAAW,0BAA0B,GAAG;AAAA,IAC/C,cAAc;AAAA,MACZ,WAAW,sCAAsC,MAAM;AAAA,IACzD;AAAA,EACF;AACF;AAQA,eAAe,YAAY,SAAwB,MAAc;AAC/D,QAAM,WAAW,iBAAiB,OAAO;AACzC,MAAI;AACF,UAAM,WAAW,MAAM;AAAA,MACrB,+CAA+C,SAAS,OAAO,sCAAsC,SAAS,OAAO,kBAAkB,SAAS,YAAY;AAAA,MAC5J;AAAA,QACE,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,UAChB,cAAc,SAAS;AAAA,QACzB;AAAA,QACA,MAAM,KAAK,UAAU;AAAA,UACnB,UAAU,SAAS;AAAA,UACnB;AAAA,UACA,gBAAgB;AAAA,YACd,kBAAkB,SAAS;AAAA,YAC3B,WAAW,SAAS;AAAA,YACpB,OAAO,SAAS;AAAA,YAChB,mBAAmB,SAAS;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACH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QACL;AAAA,UACE,MAAM;AAAA,UACN,IAAI,OAAO,YAA2B;AACpC,gBAAI,CAAC,iBAAiB,OAAO,EAAE,QAAQ;AACrC,oBAAM,IAAI;AAAA,gBACR;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,IAAI,OAAO,YAA2B;AACpC,gBAAI;AACF,oBAAM,YAAY,SAAS,MAAM;AAAA,YACnC,SAAS,OAAgB;AACvB,oBAAM,MACJ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACvD,oBAAM,OAAO,MAAM,GAAG;AAAA,YACxB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AACA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-elevenlabs",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.51",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@elizaos/core": "^1.0.0-beta.
|
|
25
|
+
"@elizaos/core": "^1.0.0-beta.51",
|
|
26
26
|
"tsup": "8.4.0"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
@@ -77,8 +77,10 @@
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "646c632924826e2b75c2304a75ee56959fe4a460",
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"
|
|
82
|
+
"@types/node": "^22.15.18",
|
|
83
|
+
"prettier": "3.5.3",
|
|
84
|
+
"typescript": "^5.8.2"
|
|
83
85
|
}
|
|
84
86
|
}
|