WebSpeech for Vaadin - Vaadin Add-on Directory
An add-on for speech recognition and speech synthesis
# Voice Addon
An add-on for speech recognition and speech synthesis.
## Version 3.0: WebSpeech for Vaadin
From version 3.0 this add-on has been renamed to **WebSpeech for Vaadin**.
It has a rewritten API for Vaadin 25:
- Typed `SpeechRecognition` and `SpeechSynthesis` classes,
- Ready-made `DictationButton`, `ReadAloudButton`, `LanguageSelect` and `VoiceSelect` components.
The Maven coordinates changed to `org.parttio:web-speech`, and the package to `org.vaadin.webspeech`.
Source and full documentation changed to: https://github.com/parttio/web-speech
Version 3.x Requires Vaadin 25, check the [Migration guide](https://github.com/parttio/web-speech#migrating-from-voice-engine-1x2x)
Versions 1.x and 2.x (`org.vaadin.addons.manolo:voice-engine`) stay available.
## Migrating from 2.x
Replace `org.vaadin.addons.manolo:voice-engine` with `org.parttio:web-speech:3.0.0`.
| Voice Engine 2.x | WebSpeech 3.0 |
|---|---|
| `setButtons(MICROPHONE, PLAY, LANG, VOICE)` | `DictationButton`, `ReadAloudButton`, `LanguageSelect`, `VoiceSelect` |
| `start()` / `stop()` / `cancel()` | `SpeechRecognition#start()` / `stop()` / `abort()` |
| `addEndListener` + `getRecorded()` | `SpeechRecognition#addEndListener(text -> ...)` |
| `setSpeech(text)` + `play()` | `SpeechSynthesis.speak(text)` |
| `setLang(...)`, `setVoice(name)` | `Utterance.lang` / `Utterance.voice` |
The test sources of WebSpeech include `LegacyVoiceEngine`, a copy of the 2.x toolbar built on the new API.
## Example (WebSpeech 3.x)
The same view as the 2.x example below, written with the 3.x components.
```java
@Route("")
public class WebSpeechView extends Div {
public WebSpeechView() {
setSizeFull();
TextArea textArea = new TextArea();
textArea.setSizeFull();
// Dictates into the text area, replacing its content
DictationButton dictate = new DictationButton(textArea);
dictate.setAppend(false);
// Reads the text area aloud
ReadAloudButton readAloud = new ReadAloudButton(textArea);
LanguageSelect language = new LanguageSelect();
VoiceSelect voice = new VoiceSelect();
Button clearButton = new Button(LumoIcon.CROSS.create(), e -> textArea.clear());
language.addValueChangeListener(e -> {
voice.setLanguage(e.getValue());
dictate.setLang(e.getValue());
readAloud.setLang(e.getValue());
});
voice.addValueChangeListener(e -> readAloud.setVoice(e.getValue()));
add(new VerticalLayout(
new HorizontalLayout(dictate, readAloud, language, voice, clearButton),
textArea));
}
}
```
## Example (Voice Engine 2.x)
```java
@Route("")
public class VoiceEngineView extends Div {
public VoiceEngineView() {
setSizeFull();
Button clearButton = new Button(LumoIcon.CROSS.create());
VoiceEngine voiceEngine = new VoiceEngine().setButtons(MICROPHONE, PLAY, LANG, VOICE);
voiceEngine.add(clearButton);
TextArea textArea = new TextArea();
textArea.setSizeFull();
add(new VerticalLayout(voiceEngine, textArea));
clearButton.addClickListener(e -> textArea.clear());
voiceEngine.addStartListener(e -> textArea.clear());
textArea.addValueChangeListener(e -> voiceEngine.setSpeech(e.getValue()));
voiceEngine.addEndListener(e -> {
if (voiceEngine.getRecorded() != null) {
textArea.setValue(voiceEngine.getRecorded());
}
if (!textArea.getValue().isEmpty()) {
voiceEngine.setSpeech(voiceEngine.getRecorded());
}
});
}
}
```
Voice Engine 2.x source
View on GitHub
WebSpeech for Vaadin version 1.0.0
WebSpeech for Vaadin version 1.0.1
fixed place to put static TS file
WebSpeech for Vaadin version 1.0.2
fix firing end event twice
WebSpeech for Vaadin version 1.0.3
WebSpeech for Vaadin version 2.0.0
**Vaadin 25 Compatibility**
This release upgrades the addon to support Vaadin 25.
**Breaking changes**
- Minimum Vaadin version is now 25.0. For Vaadin 24.x projects, use version 1.0.3.
**Changes**
- Overlay migration: Replaced setOverlayClassName() with addClassName() to align with Vaadin 25's inline overlay architecture. Overlays are no longer rendered as separate DOM elements - they are now part of the component's own subtree using the native HTML popover mechanism.
- Jackson 3 migration: Replaced elemental.json.JsonArray with tools.jackson.databind.node.ArrayNode, as Vaadin 25 replaced the Elemental JSON library with Jackson 3.
WebSpeech for Vaadin version 2.0.1
Fix voice initialization race condition, and ensure v24/v25 compatibility
WebSpeech for Vaadin version 3.0.0
Renamed to WebSpeech for Vaadin and published to Maven Central as `org.parttio:web-speech`.