-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
180 additions
and
95 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 was deleted.
Oops, something went wrong.
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,18 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { initializeLogger, testutils } from '@livekit/agents'; | ||
import { STT } from '@livekit/agents-plugin-openai'; | ||
import { describe, it } from 'vitest'; | ||
import { tts } from '@livekit/agents-test'; | ||
import { describe } from 'vitest'; | ||
import { TTS } from './tts.js'; | ||
|
||
describe('ElevenLabs', () => { | ||
describe('TTS', () => { | ||
const tts = new TTS(); | ||
const stt = new STT(); | ||
it('should properly stream synthesize text', async () => { | ||
initializeLogger({ pretty: false }); | ||
await testutils.ttsStream(tts, stt); | ||
}); | ||
}); | ||
describe('ElevenLabs', async () => { | ||
await tts(new TTS(), new STT(), { nonStreaming: false }); | ||
}); |
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,23 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { initializeLogger, testutils, tts } from '@livekit/agents'; | ||
import { describe, it } from 'vitest'; | ||
import { basic } from '../../../agents/src/tokenize/index.js'; | ||
import { tts } from '@livekit/agents-test'; | ||
import { describe } from 'vitest'; | ||
import { STT } from './stt.js'; | ||
import { TTS } from './tts.js'; | ||
|
||
describe('OpenAI', () => { | ||
describe('TTS', () => { | ||
const etts = new TTS(); | ||
const stt = new STT(); | ||
it('should properly synthesize text', async () => { | ||
initializeLogger({ pretty: false }); | ||
await testutils.tts(etts, stt); | ||
}); | ||
it('should properly stream synthesize text', async () => { | ||
initializeLogger({ pretty: false }); | ||
await testutils.ttsStream(new tts.StreamAdapter(etts, new basic.SentenceTokenizer()), stt); | ||
}); | ||
}); | ||
describe('OpenAI', async () => { | ||
await tts(new TTS(), new STT(), { streaming: false }); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ packages: | |
- "agents" | ||
- "plugins/*" | ||
- "examples" | ||
- "test" |
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 @@ | ||
{ | ||
"name": "@livekit/agents-test", | ||
"version": "0.0.0", | ||
"description": "Testing suite for LiveKit Agents", | ||
"author": "LiveKit", | ||
"type": "module", | ||
"repository": "[email protected]:livekit/agents-js.git", | ||
"license": "Apache-2.0", | ||
"main": "dist/index.js", | ||
"require": "dist/index.cjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"build": "tsup --onSuccess \"tsc --declaration --emitDeclarationOnly\"", | ||
"lint": "eslint -f unix \"src/**/*.{ts,js}\"" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.5.5", | ||
"typescript": "^5.0.0", | ||
"@livekit/agents": "workspace:^x", | ||
"@livekit/rtc-node": "^0.12.1", | ||
"tsup": "^8.3.5" | ||
}, | ||
"dependencies": { | ||
"vitest": "^1.6.0", | ||
"fastest-levenshtein": "^1.0.16" | ||
}, | ||
"peerDependencies": { | ||
"@livekit/agents": "workspace:^x", | ||
"@livekit/rtc-node": "^0.12.1" | ||
} | ||
} |
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,5 +1,4 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { tts, ttsStream } from './tts.js'; | ||
export { tts } 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,76 @@ | ||
// SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import type { stt } from '@livekit/agents'; | ||
import { type AudioBuffer, initializeLogger, tokenize, tts as ttslib } from '@livekit/agents'; | ||
import type { AudioFrame } from '@livekit/rtc-node'; | ||
import { distance } from 'fastest-levenshtein'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
const TEXT = | ||
'The people who are crazy enough to think they can change the world are the ones who do.\n' + | ||
'The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man.\n' + | ||
"Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it's the only thing that ever has.\n" + | ||
'Do not go where the path may lead, go instead where there is no path and leave a trail.'; | ||
|
||
const validate = async (frames: AudioBuffer, stt: stt.STT, text: string, threshold: number) => { | ||
const event = await stt.recognize(frames); | ||
const eventText = event.alternatives![0].text.toLowerCase().replace(/\s/g, ' ').trim(); | ||
text = text.toLowerCase().replace(/\s/g, ' ').trim(); | ||
expect(distance(text, eventText) / text.length).toBeLessThanOrEqual(threshold); | ||
}; | ||
|
||
export const tts = async ( | ||
tts: ttslib.TTS, | ||
stt: stt.STT, | ||
supports: Partial<{ streaming: boolean; nonStreaming: boolean }> = {}, | ||
) => { | ||
initializeLogger({ pretty: false }); | ||
supports = { streaming: true, nonStreaming: true, ...supports }; | ||
describe('TTS', () => { | ||
it.skipIf(!supports.nonStreaming)('should properly synthesize text', async () => { | ||
const synthesize = tts.synthesize(TEXT); | ||
const frames = await synthesize.collect(); | ||
synthesize.close(); | ||
await validate(frames, stt, TEXT, 0.2); | ||
}); | ||
|
||
it('should properly stream synthesize tests', async () => { | ||
let stream: ttslib.SynthesizeStream; | ||
if (supports.streaming) { | ||
stream = tts.stream(); | ||
} else { | ||
stream = new ttslib.StreamAdapter(tts, new tokenize.basic.SentenceTokenizer()).stream(); | ||
} | ||
|
||
const pattern = [1, 2, 4]; | ||
let text = TEXT; | ||
const chunks = []; | ||
const patternIter = Array(Math.ceil(text.length / pattern.reduce((sum, num) => sum + num, 0))) | ||
.fill(pattern) | ||
.flat() | ||
[Symbol.iterator](); | ||
|
||
for (const size of patternIter) { | ||
if (!text) break; | ||
chunks.push(text.slice(undefined, size)); | ||
text = text.slice(size); | ||
} | ||
|
||
for (const chunk of chunks) { | ||
stream.pushText(chunk); | ||
} | ||
stream.flush(); | ||
stream.endInput(); | ||
|
||
const frames: AudioFrame[] = []; | ||
for await (const event of stream) { | ||
if (event === ttslib.SynthesizeStream.END_OF_STREAM) break; | ||
frames.push(event.frame); | ||
} | ||
|
||
await validate(frames, stt, TEXT, 0.2); | ||
stream.close(); | ||
}); | ||
}); | ||
}; |
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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["./src"], | ||
"compilerOptions": { | ||
// match output dir to input dir. e.g. dist/index instead of dist/src/index | ||
"rootDir": "./src", | ||
"declarationDir": "./dist", | ||
"outDir": "./dist", | ||
} | ||
} |
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,8 @@ | ||
import { defineConfig } from 'tsup'; | ||
|
||
import defaults from '../tsup.config'; | ||
|
||
export default defineConfig({ | ||
...defaults, | ||
}); | ||
|