AI & MLBeginnerPRJ-085

AI Voice Chatbot Using Speech Recognition

Talk to your computer and it talks back: greetings, the time, and more.

Built and tested by Aboobacker sidheeq K P · Industrial Robotics Institute

Laptop / PC with microphone

Python 3.11, SpeechRecognition, pyttsx3, PyAudio, PyCharm (recommended)

LevelBeginner
Build time1–2 hours
BoardLaptop / PC with microphone
Parts3 components

What is the AI Voice Chatbot Using Speech Recognition?

A voice assistant that lets you talk to your computer instead of typing. It listens through the microphone, turns your speech into text with speech recognition, picks a reply based on what you said, and speaks the answer back with text-to-speech. It shows the basics of AI speech recognition and voice output in a short Python program.

How it works

  1. The microphone records what you say.
  2. SpeechRecognition sends the audio to Google’s speech service and gets back the text.
  3. The program looks for keywords such as hello, time, name, stop or goodbye.
  4. It picks the matching reply, for example the current time.
  5. pyttsx3 speaks the reply out loud, then the assistant listens again until you say stop or goodbye.

Parts list

ComponentQty
Laptop / Computer1
Microphone (built-in or external)1
Speaker / Headphones1

Software

  • Python 3.11
  • SpeechRecognition
  • pyttsx3
  • PyAudio
  • PyCharm (recommended)

How to build the AI Voice Chatbot Using Speech Recognition

  1. Install Python 3.11 and tick ‘Add Python to PATH’ during setup.
  2. Install PyCharm Community Edition and create a new project with the Python 3.11 interpreter.
  3. In the PyCharm terminal run: pip install SpeechRecognition pyttsx3 pyaudio
  4. Check the libraries are listed with pip list.
  5. Paste the code into a new Python file.
  6. Make sure you are online (speech recognition uses Google’s service).
  7. Run the file and say ‘hello’, ‘what is the time’ or ‘what is your name’.
  8. Say ‘stop’ or ‘goodbye’ to close the assistant.

AI Voice Chatbot Using Speech Recognition code

Complete, tested Python code for this project. Copy it into Python 3.11 and upload it and run it.

import speech_recognition as sr
import pyttsx3
import datetime
import time


def speak(text):
    print("Assistant:", text)
    engine = pyttsx3.init()
    engine.setProperty('rate', 170)
    engine.setProperty('volume', 1.0)
    engine.say(text)
    engine.runAndWait()
    engine.stop()


recognizer = sr.Recognizer()
recognizer.energy_threshold = 300
recognizer.pause_threshold = 0.8


def listen():
    try:
        with sr.Microphone() as source:
            print("\nListening...")
            recognizer.adjust_for_ambient_noise(source, duration=0.3)
            audio = recognizer.listen(source, timeout=5, phrase_time_limit=5)
        print("Recognizing...")
        command = recognizer.recognize_google(audio, language="en-IN")
        print("You:", command)
        return command.lower()
    except Exception:
        return ""


def reply(cmd):
    if cmd == "":
        return True
    elif "hello" in cmd:
        speak("Hello sir")
    elif "time" in cmd:
        now = datetime.datetime.now().strftime("%I:%M %p")
        speak(f"The time is {now}")
    elif "goodbye" in cmd or "stop" in cmd:
        speak("Goodbye sir")
        return False
    elif "name" in cmd:
        speak("I'm your voice assistant")
    else:
        speak("Please repeat")
    return True


print("Starting Assistant...")
speak("Voice assistant started")

running = True
while running:
    command = listen()
    running = reply(command)

print("Program Closed")

Real-world uses

  • Hands-free computer use
  • Accessibility for elderly users
  • Learning speech AI
  • Smart home voice control

Frequently asked questions

What is a AI Voice Chatbot Using Speech Recognition?

A voice assistant that lets you talk to your computer instead of typing. It listens through the microphone, turns your speech into text with speech recognition, picks a reply based on what you said, and speaks the answer back with text-to-speech.

What components are needed for the AI Voice Chatbot Using Speech Recognition?

You need: Laptop / Computer (1), Microphone (built-in or external) (1), Speaker / Headphones (1). Software: Python 3.11, SpeechRecognition, pyttsx3, PyAudio, PyCharm (recommended).

Is the AI Voice Chatbot Using Speech Recognition project good for beginners?

Yes. It is rated beginner and takes about 1–2 hours to build, using the Laptop / PC with microphone. The guide on this page explains every connection and step.

Where can I get the code for the AI Voice Chatbot Using Speech Recognition?

The complete, tested Python code is free on this page. Copy it into Python 3.11 and upload it and run it.

Do I need any hardware for the AI Voice Chatbot Using Speech Recognition?

No kit is needed. This project runs on a laptop or PC with microphone. For help with the setup, message IRI on WhatsApp at +91 86060 82634.

Industrial Robotics Institute
Logo