AI Notes
Build voice system. Speech recognition, NLP. Project 2024.
Project Overview
Build a voice-activated AI assistant that processes spoken commands through a complete pipeline: speech recognition (ASR), natural language understanding (NLU), dialogue management, response generation, and speech synthesis (TTS). This project teaches the end-to-end spoken dialogue system architecture that powers Siri, Alexa, and Google Assistant.
Pipeline Architecture
| User speaks | [ASR: Speech-to-Text] → text transcript |
| [NLU: Intent + Entities] | structured meaning |
| [Dialogue Manager] | decides response strategy |
| [Response Generator] | natural language response text |
| [TTS: Text-to-Speech] | audio output → User hears |
Implementation
Speech Recognition (ASR)
Wake Word Detection
class WakeWordDetector:
def __init__(self, wake_word="hey assistant"):
# Small, efficient model running continuously
self.model = load_wake_word_model()
self.listening = True
def detect(self, audio_frame):
# Runs on every 100ms audio frame
# Very lightweight: <5% CPU
score = self.model.predict(audio_frame)
if score > 0.9:
return True # Wake word detected → start full ASR
return FalseNatural Language Understanding
class DialogueNLU:
def __init__(self):
self.intent_model = train_intent_classifier()
self.entity_extractor = load_ner_model()
def understand(self, text):
intent = self.intent_model.predict(text)
entities = self.entity_extractor.extract(text)
# "Set a timer for 5 minutes"
# → intent: set_timer, entities: {duration: "5 minutes"}
# "What's the weather like tomorrow in Paris?"
# → intent: get_weather, entities: {date: "tomorrow", location: "Paris"}
return {'intent': intent, 'entities': entities}Dialogue Management
Text-to-Speech (TTS)
class SpeechSynthesizer:
def __init__(self):
# Options: edge-tts (Microsoft), pyttsx3, Coqui TTS
self.tts = load_tts_model('tts_models/en/ljspeech/tacotron2')
def speak(self, text):
# Generate audio from text
audio = self.tts.synthesize(text)
play_audio(audio)
def speak_with_emotion(self, text, emotion='neutral'):
# Advanced: adjust prosody based on content
if emotion == 'excited':
audio = self.tts.synthesize(text, speed=1.1, pitch=1.05)
elif emotion == 'calm':
audio = self.tts.synthesize(text, speed=0.9, pitch=0.95)
play_audio(audio)Complete Interaction Flow
| User: "Hey Assistant" | [Wake word detected] |
| User | "What time is my meeting tomorrow?" |
| ASR | "what time is my meeting tomorrow" |
| NLU | intent=query_calendar, entities={date: "tomorrow", type: "meeting"} |
| DM: Check calendar API | "Team standup at 9:00 AM, Project review at 2:00 PM" |
| Response | "You have two meetings tomorrow. Team standup at 9 AM and project review at 2 PM." |
| TTS | [Synthesizes and plays response audio] |
Handling Challenges
Noise robustness
- Noise cancellation preprocessing (RNNoise)
- Beamforming with microphone array
- Train ASR on noisy data
Multi-turn dialogue
- Maintain context across turns
- Coreference: "Play it again" → refers to previous song
- Ellipsis: "And tomorrow?" → same query, different date
Error recovery
- Low ASR confidence → "Sorry, could you repeat that?"
- Ambiguous intent → "Did you mean X or Y?"
- API failure → "I'm having trouble connecting. Try again?"
Technologies
| ASR | OpenAI Whisper (accuracy), Vosk (offline/lightweight) |
| NLU | Rasa, spaCy + custom intent classifier |
| TTS | Coqui TTS, Microsoft Edge TTS, pyttsx3 |
| Audio | PyAudio, sounddevice for microphone input |
| APIs | Weather, Calendar, Music, Timer |
| Hardware | Raspberry Pi 4 + USB microphone + speaker |
Interview Questions
Q: How do you handle latency in a voice assistant? A: Optimize each pipeline stage: use streaming ASR (process audio as it arrives, don't wait for silence), lightweight NLU models, pre-cached common responses, and neural TTS that starts speaking before generating the full audio. Target: <1 second from end of speech to start of response. Use wake word detection to "warm up" the pipeline.
Q: How would you add a new skill/capability to the assistant? A: Define the new intent, add training examples to the NLU model, implement the fulfillment logic (API calls, device control), design the response templates, and add to the dialogue manager's routing. Modern approaches: use LLMs as the dialogue manager—new skills just need a description and API access, no retraining needed.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Voice Assistant Project.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, projects, voice, assistant, project
Related Artificial Intelligence Topics