Offline AI Model
Lesson 2 Teaching Plan (ICT)
Lesson Title
Offline Speech Recognition & Synthesis + Python Basics (Data Types, Input, Comments)
Duration
80 minutes
Learning Objectives
Use
whisperfor offline speech recognition andpyttsx3for offline speech synthesis.Understand and use different data types in Python (strings, integers, floats, booleans).
Use
input()to get information from the user.Write comments to explain and document code.
Teaching Materials
Software
PyCharm (pre‑installed)
Python 3.8 or higher (pre‑installed)
Libraries:
whisper,pyttsx3,speech_recognition(pre‑installed)
Hardware
Teacher’s computer with projector and speakers
Student computers (one per student/pair)
Microphones (built‑in or external)
Headphones or speakers for audio output
Additional Resources
Student Handbook (Lesson 2 section, printed or digital)
Pre‑downloaded Whisper model (small)
Teaching Process
Segment 1 (30 minutes) – Content Delivering
1. Lesson 1 Recap & Lesson 2 Introduction (3 minutes)
Lesson 1: online TTS (
edge_tts) + offline recognition (whisper).Today: both synthesis and recognition work offline.
New Python topics: data types,
input(), comments.
Quick recap questions:
What does
importdo? (Brings tools into Python)How do you identify a function? (It has parentheses
())What is a parameter? (Information inside the parentheses)
2. Python Concept 1: Comments
# This is a comment — Python ignores this line
print("Hello") # This comment explains what print doesPurpose: for humans only, explains code.
Use in homework and projects.
3. Python Concept 2: Data Types (7 minutes)
# String (text, inside quotes)
name = "Alice"
message = 'Hello'
# Integer (whole number, no decimal)
age = 12
score = -5
# Float (decimal number)
height = 1.55
price = 19.99
# Boolean (True or False)
is_student = True
like_python = FalseData Type | What it stores | Example |
String | Text |
|
Integer | Whole numbers |
|
Float | Decimal numbers |
|
Boolean | True or False |
|
4. Python Concept 3:
# input() asks the user to type something
name = input("What is your name? ")
print("Hello, " + name)
# input() always returns a STRING
age_input = input("How old are you? ")
age_number = int(age_input) # convert string to integer
next_age = age_number + 1
print("Next year you will be", next_age)Key point:
input()→ string; useint()/float()for numbers.
5. New Libraries:
Library | Purpose | Online/Offline |
| Speech recognition | Offline |
| Text‑to‑speech synthesis | Offline |
Both work without internet, private and portable.
6. Code Walkthrough – Offline Speech Recognition (
import whisper
import speech_recognition as sr
# Load whisper model
model = whisper.load_model("small")
# Record from microphone
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Please speak...")
audio = recognizer.listen(source)
# Save temporary audio file
with open("temp.wav", "wb") as f:
f.write(audio.get_wav_data())
# Offline recognition
result = model.transcribe("temp.wav")
print("You said:", result["text"])7. Code Walkthrough – Offline Speech Synthesis (
import pyttsx3
# Initialize TTS engine
engine = pyttsx3.init()
# Optional settings
engine.setProperty('rate', 150) # speed
engine.setProperty('volume', 0.9) # volume
# Speak text
engine.say("Hello, I am your offline voice assistant.")
engine.say("I don't need internet to work.")
engine.runAndWait()Segment 2 (50 minutes) – Practice & Differentiated Tasks
Task 1: Data Types Practice (8 minutes)
File: task1_datatypes.py
# String
my_name = "Your Name"
print("My name is:", my_name)
# Integer
my_age = 12
print("My age is:", my_age)
# Float
my_height = 1.55
print("My height is:", my_height)
# Boolean
like_python = True
print("I like Python:", like_python)Change values to your own.
Add a comment above each variable.
Task 2:
File: task2_input.py
# Ask for name
name = input("What is your name? ")
print("Nice to meet you, " + name + "!")
# Ask for favourite subject
subject = input("What is your favourite subject? ")
print(subject + " is a great subject!")
# Ask for a number and do maths
number = input("Choose a number: ")
number_int = int(number)
print("Your number plus 10 is", number_int + 10)Task 3: Offline Speech Synthesis (
File: task3_speak.py
import pyttsx3
# Initialize the TTS engine
engine = pyttsx3.init()
# Change speed and volume
engine.setProperty('rate', 150)
engine.setProperty('volume', 0.9)
# Speak sentences
engine.say("Hello! I am your offline voice assistant.")
engine.say("I can speak without internet connection.")
engine.say("This is lesson two of our Python course.")
engine.runAndWait()Change the sentences.
Try different
rateandvolumevalues.
Task 4: Offline Speech Recognition (
File: task4_listen.py
import whisper
import speech_recognition as sr
print("Loading whisper model...")
model = whisper.load_model("small")
print("Model loaded!")
# Record
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Please speak a sentence...")
audio = recognizer.listen(source)
# Save temp file
with open("temp.wav", "wb") as f:
f.write(audio.get_wav_data())
# Recognize
print("Recognising...")
result = model.transcribe("temp.wav")
print("You said:", result["text"])
print("Characters:", len(result["text"]))Task 5: Combine
File: task5_echo.py
import pyttsx3
engine = pyttsx3.init()
user_text = input("What should I say? ")
engine.say(user_text)
engine.runAndWait()
print("Done speaking!")Teaching Evaluation
Learning Objective | Evaluation Method |
Offline recognition with | Completion of Task 4 |
Offline synthesis with | Completion of Task 3 |
Understand and use data types | Task 1: correct variable types |
Use | Task 2: program asks and responds |
Write comments | All tasks include meaningful comments |
Exit Ticket (5 minutes)
Write on a sticky note:
What is the difference between an integer and a float?
What does
input()always return?What symbol do you use to write a comment in Python?
Homework / Preparation for Lesson 3
Think of 5 questions you would like to ask a voice assistant.
Practice writing Python comments in your own code.
(Optional) Improve the echo program from Task 5.