Skip to content

Commit

Permalink
plugins/elevenlabs: re-add
Browse files Browse the repository at this point in the history
This reverts commit 0946936.
  • Loading branch information
nbsp committed Sep 18, 2024
1 parent 0946936 commit c03492b
Show file tree
Hide file tree
Showing 10 changed files with 512 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@livekit/agents": "workspace:*",
"@livekit/agents-plugin-elevenlabs": "workspace:*",
"@livekit/agents-plugin-openai": "workspace:*",
"@livekit/rtc-node": "^0.8.1",
"zod": "^3.23.8"
Expand Down
37 changes: 37 additions & 0 deletions examples/src/minimal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { type JobContext, WorkerOptions, cli, defineAgent } from '@livekit/agents';
import { TTS } from '@livekit/agents-plugin-elevenlabs';
import { AudioSource, LocalAudioTrack, TrackPublishOptions, TrackSource } from '@livekit/rtc-node';

export default defineAgent({
entry: async (ctx: JobContext) => {
await ctx.connect();
console.log('starting TTS example agent');

// prepare our audio track and start publishing it to the room
const source = new AudioSource(24000, 1);
const track = LocalAudioTrack.createAudioTrack('agent-mic', source);
const options = new TrackPublishOptions();
options.source = TrackSource.SOURCE_MICROPHONE;
await ctx.room.localParticipant?.publishTrack(track, options);

// ask ElevenLabs to synthesize "Hello!"
const tts = new TTS();
console.log('speaking "Hello!"');
await tts
.synthesize('Hello!')
.then((output) => output.collect())
.then((output) => {
// send the audio to our track
source.captureFrame(output);
});
},
});

// check that we're running this file and not importing functions from it
// without this if closure, our code would start` a new Agents process on every job process.
if (process.argv[1] === import.meta.filename) {
cli.runApp(new WorkerOptions({ agent: import.meta.filename }));
}
43 changes: 43 additions & 0 deletions examples/src/tts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { type JobContext, WorkerOptions, cli, defineAgent, log } from '@livekit/agents';
import { TTS } from '@livekit/agents-plugin-elevenlabs';
import { AudioSource, LocalAudioTrack, TrackPublishOptions, TrackSource } from '@livekit/rtc-node';
import { fileURLToPath } from 'url';

if (process.argv[1] === fileURLToPath(import.meta.url)) {
cli.runApp(new WorkerOptions({ agent: import.meta.filename }));
}

export default defineAgent({
entry: async (ctx: JobContext) => {
await ctx.connect();
log().info('starting TTS example agent');

const source = new AudioSource(24000, 1);
const track = LocalAudioTrack.createAudioTrack('agent-mic', source);
const options = new TrackPublishOptions();
options.source = TrackSource.SOURCE_MICROPHONE;
await ctx.room.localParticipant?.publishTrack(track, options);

const tts = new TTS();
log().info('speaking "Hello!"');
await tts
.synthesize('Hello!')
.then((output) => output.collect())
.then((output) => {
source.captureFrame(output);
});

await new Promise((resolve) => setTimeout(resolve, 1000));

log().info('speaking "Goodbye."');
await tts
.synthesize('Goodbye.')
.then((output) => output.collect())
.then((output) => {
source.captureFrame(output);
});
},
});
20 changes: 20 additions & 0 deletions plugins/elevenlabs/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

/**
* Optionally specifies another JSON config file that this file extends from. This provides a way for
* standard settings to be shared across multiple projects.
*
* If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains
* the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
* resolved using NodeJS require().
*
* SUPPORTED TOKENS: none
* DEFAULT VALUE: ""
*/
"extends": "../../api-extractor-shared.json",
"mainEntryPointFilePath": "./dist/index.d.ts"
}
25 changes: 25 additions & 0 deletions plugins/elevenlabs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@livekit/agents-plugin-elevenlabs",
"version": "0.1.0",
"description": "ElevenLabs plugin for LiveKit Node Agents",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "aoife cassidy <[email protected]>",
"type": "module",
"scripts": {
"build": "tsc",
"lint": "eslint -f unix \"src/**/*.{ts,js}\"",
"api:check": "api-extractor run --typescript-compiler-folder ../../node_modules/typescript",
"api:update": "api-extractor run --local --typescript-compiler-folder ../../node_modules/typescript --verbose"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.35.0",
"@types/ws": "^8.5.10",
"typescript": "^5.0.0"
},
"dependencies": {
"@livekit/agents": "workspace:*",
"@livekit/rtc-node": "^0.8.1",
"ws": "^8.16.0"
}
}
5 changes: 5 additions & 0 deletions plugins/elevenlabs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

export * from './tts.js';
9 changes: 9 additions & 0 deletions plugins/elevenlabs/src/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

export type TTSModels =
| 'eleven_monolingual_v1'
| 'eleven_multilingual_v1'
| 'eleven_multilingual_v2'
| 'eleven_turbo_v2';
Loading

0 comments on commit c03492b

Please sign in to comment.