This document explains how to test the TTS wrapper and run examples for different TTS engines.
Before running tests or examples, make sure you have set up the necessary environment variables for the TTS engines you want to test:
MICROSOFT_TOKEN=your_azure_subscription_key
MICROSOFT_REGION=your_azure_region
ELEVENLABS_API_KEY=your_elevenlabs_api_key
GOOGLE_APPLICATION_CREDENTIALS=path_to_your_google_credentials_json
# or
GOOGLE_SA_PATH=path_to_your_google_service_account_json
CEREVOICE_EMAIL=your_cerevoice_email
CEREVOICE_PASSWORD=your_cerevoice_password
# Optional
CEREVOICE_ACCESS_TOKEN=existing_access_token
CEREVOICE_REFRESH_TOKEN=existing_refresh_token
You can set these environment variables in a .env file in the root of the project.
The project includes a unified test framework that can test all TTS engines or specific engines.
Before running tests, the framework automatically validates your credentials for each TTS engine using the checkCredentials() method. This ensures that only engines with valid credentials are tested.
To test all available TTS engines:
npm run test:ttsThis will run tests for all engines for which you have provided valid credentials.
To test a specific TTS engine:
# Test Azure TTS
npm run test:azure
# Test ElevenLabs TTS
npm run test:elevenlabs
# Test Google TTS
npm run test:google
# Test CereVoice unit coverage
npm run test:cerevoiceIf your credentials for the specified engine are invalid, the tests will be skipped with a clear message.
npm run test:cerevoice runs mocked unit coverage for auth, voice mapping, synthesis request shape, metadata fetching, and word-boundary conversion. It does not require live CereVoice credentials.
The project includes a unified example framework that can demonstrate all TTS engines or specific engines.
Before running examples, the framework automatically validates your credentials for each TTS engine using the checkCredentials() method. This ensures that only engines with valid credentials are demonstrated.
To run examples for all available TTS engines:
npm run exampleThis will run examples for all engines for which you have provided valid credentials.
To run an example for a specific TTS engine:
# Run Azure TTS example
npm run example:azure
# Run ElevenLabs TTS example
npm run example:elevenlabs
# Run Google TTS example
npm run example:googleIf your credentials for the specified engine are invalid, the example will be skipped with a clear message.
To add a new TTS engine to the unified test and example framework:
- Create a new engine implementation in
src/engines/ - Implement the
_getVoices()method to retrieve voices from the provider - Implement the
_mapVoicesToUnified()method to map the raw voice data to a unified format - Implement the
checkCredentials()method to validate credentials (or use the default implementation) - Update the factory function in
src/__tests__/tts-engine.test.tsto include your new engine - Update the factory function in
examples/tts-example.jsto include your new engine - Add the new engine to the
validEnginesarray inrun-tts-tests.js - Add new npm scripts in
package.jsonfor testing and running examples with your engine
The tests cover the following functionality for each TTS engine:
- Listing available voices
- Getting voices by language
- Setting and getting properties
- Synthesizing text using non-streaming approach
- Synthesizing SSML to speech (for engines that support SSML)
- Synthesizing text using streaming approach
- Handling word boundary events
The examples demonstrate the following functionality for each TTS engine:
- Listing available voices
- Getting voices by language
- Setting a voice
- Converting text to speech
- Converting SSML to speech (for engines that support SSML)
- Converting text to speech using streaming
- Handling word boundary events