From 7ad7353a909c29ea47596b22631d423954b6d6fa Mon Sep 17 00:00:00 2001 From: Nicolas Bonamy Date: Fri, 17 Jan 2025 16:27:31 -0600 Subject: [PATCH] tts tests --- src/voice/tts-replicate.ts | 4 ++-- tests/unit/tts.test.ts | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/voice/tts-replicate.ts b/src/voice/tts-replicate.ts index 9298653c..8f8071c6 100644 --- a/src/voice/tts-replicate.ts +++ b/src/voice/tts-replicate.ts @@ -1,5 +1,5 @@ -import { Configuration } from '../types/config' +/*import { Configuration } from '../types/config' import { SynthesisResponse, TTSEngine } from './tts' import Replicate, { FileOutput, Prediction } from 'replicate' @@ -54,4 +54,4 @@ export default class TTSReplicate implements TTSEngine { reader.readAsDataURL(blob) }) } -} \ No newline at end of file +}*/ diff --git a/tests/unit/tts.test.ts b/tests/unit/tts.test.ts index 5d8b510b..042cf07f 100644 --- a/tests/unit/tts.test.ts +++ b/tests/unit/tts.test.ts @@ -14,12 +14,35 @@ vi.mock('openai', async () => { return { default : OpenAI } }) +vi.mock('elevenlabs', async () => { + const ElevenLabsClient = vi.fn() + ElevenLabsClient.prototype.textToSpeech = { + convertAsStream: vi.fn((_, opts) => opts.text) + } + return { ElevenLabsClient } +}) + beforeEach(() => { store.config = defaults }) -test('Synthetizes text', async () => { +test('OpenAI', async () => { + const tts = getTTSEngine(store.config) + const response = await tts.synthetize('hello openai') + expect(response).toStrictEqual({ type: 'audio', content: 'hello openai' }) +}) + +test('ElevenLabs', async () => { + store.config.tts.engine = 'elevenlabs' const tts = getTTSEngine(store.config) - const response = await tts.synthetize('hello') - expect(response).toStrictEqual({ type: 'audio', content: 'hello' }) + const response = await tts.synthetize('hello elevenlabs') + expect(response).toStrictEqual({ type: 'audio', content: 'hello elevenlabs' }) }) + +test('Kokoro', async () => { + store.config.tts.engine = 'kokoro' + const tts = getTTSEngine(store.config) + const response = await tts.synthetize('hello kokoro') + expect(response).toStrictEqual({ type: 'audio', content: 'hello kokoro' }) +}) +