-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix load calculation, report worker status (#24)
- Loading branch information
Showing
10 changed files
with
111 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@livekit/agents": minor | ||
"@livekit/agents-plugin-elevenlabs": minor | ||
"livekit-agents-examples": minor | ||
--- | ||
|
||
bump underlying dependencies | ||
fix load calculation | ||
report worker status |
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
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
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 |
---|---|---|
@@ -1,32 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
type Agent, | ||
type JobContext, | ||
type JobRequest, | ||
WorkerOptions, | ||
cli, | ||
defineAgent, | ||
} from '@livekit/agents'; | ||
import { fileURLToPath } from 'url'; | ||
import { type JobContext, type JobRequest, WorkerOptions, cli, defineAgent } from '@livekit/agents'; | ||
import { TTS } from '@livekit/agents-plugin-elevenlabs'; | ||
import { AudioSource, LocalAudioTrack, TrackPublishOptions, TrackSource } from '@livekit/rtc-node'; | ||
|
||
const requestFunc = async (req: JobRequest) => { | ||
console.log('received request', req); | ||
await req.accept(fileURLToPath(import.meta.url)); | ||
}; | ||
export default defineAgent({ | ||
entry: async (job: JobContext) => { | ||
console.log('starting TTS example agent'); | ||
|
||
if (process.argv[1] === fileURLToPath(import.meta.url)) { | ||
cli.runApp(new WorkerOptions({ requestFunc })); | ||
} | ||
// 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 job.room.localParticipant?.publishTrack(track, options); | ||
|
||
const myAgent: Agent = { | ||
entry: async (job: JobContext) => { | ||
console.log('starting voice assistant...'); | ||
job; | ||
// 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); | ||
}); | ||
}, | ||
}); | ||
|
||
// the requestFunc function allows us to do some things on the main thread after worker connection | ||
const requestFunc = async (req: JobRequest) => { | ||
// this line needs to be exact. | ||
// we are passing this file's path to Agents, in order to import it later and run our entry function. | ||
await req.accept(import.meta.filename); | ||
}; | ||
|
||
// your entry file has to provide a default export of type Agent. | ||
// use the defineAgent() helper function to generate your agent. | ||
export default defineAgent(myAgent); | ||
// 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({ requestFunc })); | ||
} |
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 |
---|---|---|
|
@@ -39,5 +39,6 @@ | |
"typedoc": "^0.25.13", | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.6.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
Oops, something went wrong.