Overview
TheSpeechService provides speech-to-text and text-to-speech capabilities using the browser’s native Web Speech API. This service enables voice input and audio output features throughout the application.
Service details
File:src/app/_services/__Utils/SpeechService/speech.service.tsProvided in:
root
Properties
SpeechRecognition instance (browser API)
Indicates whether speech recognition is currently active
The recognized speech text
Error message from speech recognition
Methods
startListening()
Starts listening for speech input.- Sets
isListeningtotrue - Starts the speech recognition engine
- Supports English (en-US) by default
- Only captures final results (no interim)
stopListening()
Stops listening for speech input.- Sets
isListeningtofalse - Stops the speech recognition engine
speakText()
Speaks the current transcript using text-to-speech.- Uses
SpeechSynthesisUtteranceAPI - Speaks in English (en-US)
- Shows alert if no text available
speakTextCustom()
Speaks custom text with optional language selection.The text to speak
Language code for speech synthesis
Browser compatibility
Supported browsers:- Chrome/Edge (full support)
- Safari (partial support)
- Firefox (limited support)
Usage example
Integration with components
The SpeechService is used by:- SpeechPanelComponent: Provides UI controls for voice input/output
- BaseComponent: Enables voice feedback for page titles
- Various form components for voice data entry
Error handling
The service captures speech recognition errors in theerror property:
no-speech: No speech detectedaudio-capture: Microphone access deniednot-allowed: Permission not grantednetwork: Network error
See also
- SpeechPanelComponent - UI component using this service
- BaseComponent - Component with speech integration