Design Echo

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-05-14

Problem Statement

Design the Low-Level Design (LLD) of a Voice Assistant system, similar to Amazon Echo / Google Home / Siri.


The system should continuously listen for a wake word (like “Alexa” or “Echo”), process user commands, execute appropriate actions (e.g., play music, tell the weather, set alarms), and respond back with speech or results.


🧠 Functional Requirements


Wake Word Detection

•System continuously listens for a wake word (e.g., “Echo”).
•When detected, the system activates and starts listening for commands.

Command Processing

•Once activated, Echo should:
•Listen to user’s command
•Identify command type (e.g., Music, Weather, Alarm)
•Delegate execution to the respective module/service

Action Execution

•Based on the recognized command, perform actions such as:

Play Music: Play/pause/stop specific song or playlist.

Tell Weather: Fetch and announce the current weather.

Set Alarm: Set or cancel alarms.

Answer Queries: Respond with stored or fetched information.

Voice Response

•Convert the system’s response text to voice output (Text-to-Speech simulation).

Extensibility

•Support for adding new command types in future (e.g., controlling IoT devices, reading news).


🚫 Non-Functional Requirements

•Modular and extensible design — new services (like Smart Lights, Calendar) can be plugged in easily.
•Low latency in command recognition and execution.
•Fault tolerance — handle unknown or invalid commands gracefully.
•Separation of concerns between input capture, processing, and response.


🧱 Suggested Classes


ClassResponsibility


EchoDevice


Represents the main device; manages listening, activation, and communication with modules.


WakeWordDetector


Continuously listens for the wake word (“Echo”).


VoiceCommandProcessor


Parses and classifies the command into a specific action type.


Command (Abstract)


Base class representing a generic voice command.


MusicCommand, WeatherCommand, AlarmCommand, InfoCommand


Concrete classes implementing specific commands.


Service (Interface)


Represents an executable service that processes a command and returns a response.


MusicService, WeatherService, AlarmService


Implementations for respective commands.


ResponseGenerator


Converts command output into a spoken response (Text-to-Speech).


User


Represents the owner or speaker interacting with the Echo device.


🔄 Example Flow


1.Idle State (Listening)
1 2Echo is listening...
1.Wake Word Detected
1 2User: "Echo" 3→ WakeWordDetector triggers activation 4Echo: "Yes?"
1.Command Processing
1 2User: "Play Coldplay songs" 3→ CommandProcessor identifies "MusicCommand" 4→ MusicService.play("Coldplay") 5Echo: "Playing songs by Coldplay"
1.Another Command
1 2User: "Echo, what’s the weather today?" 3→ CommandProcessor identifies "WeatherCommand" 4→ WeatherService.getWeather() 5Echo: "It's 27°C and sunny in Mumbai"
1.Unknown Command
1 2User: "Echo, teleport me to office" 3Echo: "Sorry, I can’t do that yet."


🧪 Example Input / Output


Input:

1 2Echo → "Play Shape of You" 3Echo → "What’s the weather today?" 4Echo → "Set an alarm for 7 AM"


Output:

1 2Playing 'Shape of You' by Ed Sheeran. 3It’s 25°C and clear. 4Alarm set for 7 AM tomorrow.


⚙️ Constraints


•Commands per session ≤ 100
•Support wake word detection latency ≤ 1 second
•Each command execution ≤ 2 seconds
•Multiple services should execute independently (using polymorphism)


🎯 Goals


Your design should:


•Demonstrate OOP principles — abstraction for commands, polymorphism for services.
•Clearly separate input capture, command parsing, and action execution.
•Support easy extensibility — adding new voice services with minimal changes.


✅ In short:


Design an object-oriented model for a voice assistant system (Echo) that listens for a wake word, understands user commands, executes them using specialized services, and responds appropriately — ensuring modularity and scalability.

Solution

Comments