@angularai/voice-actions
v0.0.3
Published
<div align="center"> <h1>@angularai/voice-actions</h1> <p>π€ Voice command integration for Angular applications</p>
Readme
Overview
@angularai/voice-actions provides voice command integration for Angular applications. Add speech-to-text input, voice-activated commands, and text-to-speech responses with AI-powered natural language understanding.
β¨ Features
- π€ Speech-to-Text: Convert voice to text input
- π Text-to-Speech: Read responses aloud
- π§ AI Understanding: Natural language command processing
- π Multi-Language: Support for 50+ languages
- β‘ Real-time: Live transcription as you speak
- π§ Fully Typed: Complete TypeScript support
- π± Mobile Support: Works on mobile browsers
π¦ Installation
npm install @angularai/voice-actions @angularai/coreπ Quick Start
1. Voice Input Component
import { Component } from '@angular/core';
import { VoiceInputComponent } from '@angularai/voice-actions';
@Component({
selector: 'app-voice-search',
standalone: true,
imports: [VoiceInputComponent],
template: `
<voice-input
[language]="'en-US'"
placeholder="Click mic to speak..."
(transcriptChanged)="onTranscript($event)"
(commandDetected)="onCommand($event)"
/>
`
})
export class VoiceSearchComponent {
onTranscript(text: string) {
console.log('Transcribed:', text);
}
onCommand(command: VoiceCommand) {
console.log('Command detected:', command);
}
}2. Voice Actions Service
import { Component, inject } from '@angular/core';
import { VoiceActionsService } from '@angularai/voice-actions';
@Component({ ... })
export class VoiceComponent {
private voice = inject(VoiceActionsService);
startListening() {
this.voice.startListening({
language: 'en-US',
continuous: true
}).subscribe({
next: (result) => {
console.log('Heard:', result.transcript);
if (result.isFinal) {
this.processCommand(result.transcript);
}
}
});
}
speak(text: string) {
this.voice.speak(text, {
language: 'en-US',
rate: 1.0,
pitch: 1.0
});
}
stopListening() {
this.voice.stopListening();
}
}π API Reference
VoiceActionsService
@Injectable({ providedIn: 'root' })
export class VoiceActionsService {
// Start listening for voice input
startListening(options?: ListenOptions): Observable<SpeechResult>;
// Stop listening
stopListening(): void;
// Text-to-speech
speak(text: string, options?: SpeakOptions): Promise<void>;
// Stop speaking
stopSpeaking(): void;
// Check if listening
isListening(): boolean;
// Check if speaking
isSpeaking(): boolean;
// Get supported languages
getSupportedLanguages(): string[];
}VoiceInputComponent
Inputs
| Input | Type | Default | Description |
|-------|------|---------|-------------|
| language | string | 'en-US' | Recognition language |
| continuous | boolean | false | Continuous listening |
| placeholder | string | 'Speak...' | Input placeholder |
| showTranscript | boolean | true | Show live transcript |
Outputs
| Output | Type | Description |
|--------|------|-------------|
| transcriptChanged | EventEmitter<string> | Emitted on transcript update |
| commandDetected | EventEmitter<VoiceCommand> | Emitted when command detected |
| listeningStarted | EventEmitter<void> | Emitted when listening starts |
| listeningStopped | EventEmitter<void> | Emitted when listening stops |
π§ Advanced Usage
Custom Voice Commands
import { Component, inject } from '@angular/core';
import { VoiceCommandsService } from '@angularai/voice-actions';
@Component({ ... })
export class CommandsComponent {
private commands = inject(VoiceCommandsService);
ngOnInit() {
this.commands.register([
{
phrase: 'navigate to home',
action: () => this.router.navigate(['/home'])
},
{
phrase: 'search for *',
action: (query) => this.search(query)
},
{
phrase: 'scroll down',
action: () => window.scrollBy(0, 500)
}
]);
this.commands.startListening();
}
}AI-Powered Command Understanding
<voice-input
[provider]="'openai'"
[apiKey]="apiKey"
[aiUnderstanding]="true"
(commandDetected)="onCommand($event)"
/>π Supported Languages
| Language | Code | Status | |----------|------|--------| | English (US) | en-US | β | | English (UK) | en-GB | β | | Spanish | es-ES | β | | French | fr-FR | β | | German | de-DE | β | | Italian | it-IT | β | | Portuguese | pt-BR | β | | Japanese | ja-JP | β | | Korean | ko-KR | β | | Chinese | zh-CN | β |
π¦ Related Packages
| Package | Description | |---------|-------------| | @angularai/core | Core AI functionality | | @angularai/chatbot | AI chat components |
π Related Projects
| Framework | Repository | Status | |-----------|-----------|--------| | Vue.js | @aivue | β Available | | React | @anthropic-ai/react | β Available | | Angular | @angularai | β Available | | Svelte | @svelteai | π‘ Planned |
π License
MIT Β© AngularAI
