Skip to content

Commit

Permalink
tts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Jan 17, 2025
1 parent 60d461f commit 7ad7353
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/voice/tts-replicate.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -54,4 +54,4 @@ export default class TTSReplicate implements TTSEngine {
reader.readAsDataURL(blob)
})
}
}
}*/
29 changes: 26 additions & 3 deletions tests/unit/tts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
})

0 comments on commit 7ad7353

Please sign in to comment.