capacitor-edge-tts
v1.0.1
Published
Capacitor plugin for Microsoft Edge Text-to-Speech. Free, high-quality TTS using Microsoft Edge's speech synthesis API. Works on Android (native) and Web.
Downloads
182
Maintainers
Readme
capacitor-edge-tts
Free, high-quality Text-to-Speech for Capacitor apps using Microsoft Edge's speech synthesis API.
No API key required. No server needed. Works offline-ready on Android.
Features
- Free: Uses Microsoft Edge's built-in TTS service (same as edge-tts Python library)
- High Quality: Access to 400+ neural voices in 100+ languages
- No API Key: Works without any Microsoft Azure subscription
- Cross-Platform: Works on Android (native) and Web (WebSocket)
- SSML Support: Control rate, pitch, and volume
- Lightweight: Minimal dependencies (only OkHttp on Android)
Why This Plugin?
WebSocket connections to Microsoft's TTS service are blocked in Android WebView due to security restrictions. This plugin uses native OkHttp WebSocket on Android to bypass this limitation, while falling back to standard WebSocket on web platforms.
Install
npm install capacitor-edge-tts
npx cap syncUsage
Basic Example
import { EdgeTTS } from 'capacitor-edge-tts';
// Simple text-to-speech
const result = await EdgeTTS.synthesize({
text: 'Hello, world!',
voice: 'en-US-AriaNeural'
});
// Decode and play audio
const audioData = Uint8Array.from(atob(result.audio), c => c.charCodeAt(0));
const audioContext = new AudioContext();
const audioBuffer = await audioContext.decodeAudioData(audioData.buffer);
const source = audioContext.createBufferSource();
source.buffer = audioBuffer;
source.connect(audioContext.destination);
source.start(0);With Options
const result = await EdgeTTS.synthesize({
text: 'Bonjour le monde!',
voice: 'fr-FR-VivienneMultilingualNeural',
rate: '+20%', // Speed: -50% to +100%
volume: '+0%', // Volume: -50% to +50%
pitch: '+0Hz' // Pitch adjustment
});Check Availability
const { available } = await EdgeTTS.isAvailable();
if (available) {
// Edge TTS is ready
}Get Available Voices
const { voices } = await EdgeTTS.getVoices();
// Filter by language
const frenchVoices = voices.filter(v => v.locale.startsWith('fr-'));
console.log(frenchVoices);
// [
// { id: 'fr-FR-VivienneMultilingualNeural', name: 'Vivienne', locale: 'fr-FR', gender: 'Female', multilingual: true },
// { id: 'fr-FR-RemyMultilingualNeural', name: 'Rémy', locale: 'fr-FR', gender: 'Male', multilingual: true },
// ...
// ]Popular Voices
| Voice ID | Name | Language | Gender |
|----------|------|----------|--------|
| en-US-AriaNeural | Aria | English (US) | Female |
| en-US-GuyNeural | Guy | English (US) | Male |
| en-GB-SoniaNeural | Sonia | English (UK) | Female |
| fr-FR-VivienneMultilingualNeural | Vivienne | French | Female |
| fr-FR-RemyMultilingualNeural | Rémy | French | Male |
| de-DE-KatjaNeural | Katja | German | Female |
| es-ES-ElviraNeural | Elvira | Spanish | Female |
| it-IT-ElsaNeural | Elsa | Italian | Female |
| ja-JP-NanamiNeural | Nanami | Japanese | Female |
| zh-CN-XiaoxiaoNeural | Xiaoxiao | Chinese | Female |
| ko-KR-SunHiNeural | SunHi | Korean | Female |
| pt-BR-FranciscaNeural | Francisca | Portuguese (BR) | Female |
For the full list of 400+ voices, see Microsoft's documentation.
API
synthesize(...)
synthesize(options: SynthesizeOptions) => Promise<SynthesizeResult>Synthesize text to speech and return audio data.
| Param | Type | Description |
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------ |
| options | SynthesizeOptions | - Synthesis options including text and voice settings. |
Returns: Promise<SynthesizeResult>
isAvailable()
isAvailable() => Promise<IsAvailableResult>Check if Edge TTS is available on this platform.
Returns: Promise<IsAvailableResult>
getVoices()
getVoices() => Promise<GetVoicesResult>Get list of available voices.
Note: On Android, this returns a curated list of popular voices. The full list of 400+ voices is available at: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support
Returns: Promise<GetVoicesResult>
Interfaces
SynthesizeResult
| Prop | Type | Description |
| ----------- | ------------------- | -------------------------------- |
| audio | string | Base64-encoded MP3 audio data. |
| size | number | Size of the audio data in bytes. |
SynthesizeOptions
| Prop | Type | Description | Default |
| ------------ | ------------------- | --------------------------------------------------------------------- | ------------------------------- |
| text | string | The text to synthesize into speech. | |
| voice | string | The voice to use for synthesis. | 'en-US-AriaNeural' |
| rate | string | Speech rate adjustment. Format: '+X%' or '-X%' where X is percentage. | '+0%' |
| volume | string | Volume adjustment. Format: '+X%' or '-X%' where X is percentage. | '+0%' |
| pitch | string | Pitch adjustment. Format: '+XHz' or '-XHz' where X is hertz. | '+0Hz' |
IsAvailableResult
| Prop | Type | Description |
| --------------- | -------------------- | ----------------------------------------------- |
| available | boolean | Whether Edge TTS is available on this platform. |
GetVoicesResult
| Prop | Type | Description |
| ------------ | ------------------------ | ------------------------- |
| voices | VoiceInfo[] | List of available voices. |
VoiceInfo
| Prop | Type | Description |
| ------------------ | ------------------------------- | ---------------------------------------------- |
| id | string | Voice identifier (e.g., 'en-US-AriaNeural'). |
| name | string | Display name of the voice. |
| locale | string | Locale/language code (e.g., 'en-US', 'fr-FR'). |
| gender | 'Male' | 'Female' | Gender of the voice ('Male' or 'Female'). |
| multilingual | boolean | Whether this is a multilingual voice. |
Platform Support
| Platform | Implementation | Notes | |----------|---------------|-------| | Android | Native (OkHttp WebSocket) | Full support, bypasses WebView restrictions | | Web | WebSocket | Full support | | iOS | Not yet supported | PRs welcome! |
How It Works
This plugin connects directly to Microsoft's Edge TTS WebSocket service (wss://speech.platform.bing.com). It uses the same protocol as the edge-tts Python library.
On Android, WebSocket connections from WebView are often blocked or unreliable. This plugin uses OkHttp's native WebSocket implementation to ensure reliable connections.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
# Clone the repo
git clone https://github.com/anthropics/capacitor-edge-tts.git
cd capacitor-edge-tts
# Install dependencies
npm install
# Build
npm run build
# Test in a Capacitor app
npm link
cd /path/to/your/capacitor/app
npm link capacitor-edge-tts
npx cap syncCredits
- Inspired by edge-tts Python library
- Uses Microsoft Edge's free TTS service
