-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 0946936.
- Loading branch information
Showing
10 changed files
with
512 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.