Text to Speech
@capacitor-community/text-to-speech
Capacitor community plugin for synthesizing speech from text.
Maintainers
Installation
npm install @capacitor-community/text-to-speech
npx cap sync
On iOS, no further steps are needed.
On Android, register the plugin in your main activity:
import com.getcapacitor.community.tts.TextToSpeech;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
add(TextToSpeech.class);
}
}
);
}
}
Configuration
No configuration required for this plugin.
Supported methods
Name | Android | iOS | Web |
---|
speak | ✅ | ✅ | ✅ |
stop | ✅ | ✅ | ✅ |
getSupportedLanguages | ✅ | ✅ | ✅ |
openInstall | ✅ | ✅ | ❌ |
setPitchRate | ✅ | ✅ | ❌ |
setSpeechRate | ✅ | ✅ | ❌ |
Usage
import '@capacitor-community/text-to-speech';
import { Plugins } from '@capacitor/core';
const { TextToSpeech } = Plugins;
TextToSpeech.speak({
text: 'This is a sample text.',
locale: 'en_US',
speechRate: 1.0,
pitchRate: 1,
volume: 1.0,
voice: 10,
category: 'ambient',
});
TextToSpeech.stop();
TextToSpeech.getSupportedLanguages();
TextToSpeech.getSupportedVoices();
TextToSpeech.openInstall();
TextToSpeech.setPitchRate({
pitchRate: 1.5,
});
TextToSpeech.setSpeechRate({
speechRate: 0.5,
});
Changelog
See CHANGELOG.md.
License
See LICENSE.