How to Turn Your Computer into an AI Voice Assistant
Ideal solution for those who have difficulty typing or seeing
Imagine being able to talk to your computer and have it respond naturally, as if you were talking to a real person. What once seemed like science fiction is now possible — and it's completely free! In this guide, you'll learn how to create your own AI voice assistant, easily and step by step.
Why Use a Voice Assistant?
What You'll Need (All Free!)
Before you get started, see what you'll need. Don't worry — it's all free and doesn't require any technical knowledge:
Step by Step Instructions
Step 1: Open Google AI Studio
What is Google AI Studio?
This is a free Google service that allows you to use artificial intelligence tools. It's like a "lab" for AI experiments.
How to open it:
→ Open Google Chrome or any browser.
→ Type in the address bar: aistudio.google.com
→ Press Enter and sign in to your Google account.
If you don't have a Google account, go to gmail.com and select "Create an account."
Step 2: Create your API Key
What is an API key?
It is your personal "ticket" that gives you access to Google AI tools. It acts as a password for using the service.
How to create it:
→ In AI Studio, click "Get API Key".
→ Then select "Create API Key".
→ A long text of letters and numbers will appear — this is your key.
→ Click "Copy" to copy it.
Your API key is strictly personal — don't share it with anyone! Keep it safe, just like you would a bank account password.
Step 3: Prepare your System
Install Python:
Python is a language that your computer "understands." It's free and easy to install:
→ Go to python.org
→ Download the latest version (click the big yellow button).
→ Open the file and select “Add Python to PATH” before installation.
→ Click "Install Now" and wait for it to complete.
Install the necessary tools:
You will need a few additional programs. The installation is automatic!
For Windows:
→ Open the command prompt (cmd).
→ Paste the following commands and press ENTER to start the installation:
pip install Speech Recognition
pip install pyttsx3
pip install google-generativeai
pip install pyaudio
They automatically download all the necessary tools: for voice recognition, audio playback, and connection to the Google AI service.
Step 4: Create the Program
The easiest part! Simply:
→ Open Notepad.
→ Copy the code you will see below in the article.
import sys
import time
print("=" * 60)
print("🤖 ΦΩΝΗΤΙΚΟΣ ΒΟΗΘΟΣ ΜΕ GEMINI AI")
print("=" * 60)
print("\n🔍 Έλεγχος βιβλιοθηκών...")
# Έλεγχος βιβλιοθηκών
try:
import speech_recognition as sr
print("✅ SpeechRecognition - OK")
except ImportError:
print("❌ SpeechRecognition - ΛΕΙΠΕΙ")
print(" Τρέξε: pip install SpeechRecognition")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
try:
import pyttsx3
print("✅ pyttsx3 - OK")
except ImportError:
print("❌ pyttsx3 - ΛΕΙΠΕΙ")
print(" Τρέξε: pip install pyttsx3")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
try:
import google.generativeai as genai
print("✅ google-generativeai - OK")
except ImportError:
print("❌ google-generativeai - ΛΕΙΠΕΙ")
print(" Τρέξε: pip install google-generativeai")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
# Βάλε εδώ το API key σου από το Google AI Studio
GEMINI_API_KEY = "ΒΑΛΤΕ_ΕΔΩ_ΤΟ_ΚΛΕΙΔΙ_ΣΑΣ"
# Έλεγχος API Key
if GEMINI_API_KEY == "ΒΑΛΤΕ_ΕΔΩ_ΤΟ_ΚΛΕΙΔΙ_ΣΑΣ":
print("\n⚠️ ΠΡΟΣΟΧΗ: Πρέπει να βάλεις το Gemini API key σου!")
print("📍 Πήγαινε στο: https://makersuite.google.com/app/apikey")
print("🔑 Δημιούργησε ένα κλειδί και βάλτο στη μεταβλητή GEMINI_API_KEY")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
print("\n🔧 Αρχικοποίηση συστημάτων...")
# Ρύθμιση του Gemini
try:
genai.configure(api_key=GEMINI_API_KEY)
# Δοκιμή διαφορετικών μοντέλων (τα πιο πρόσφατα πρώτα)
model_names = [
'models/gemini-2.0-flash-001',
'models/gemini-2.0-flash-lite-001',
'models/gemini-2.0-flash-thinking-exp',
'models/gemini-2.0-flash-lite',
'gemini-2.0-flash-exp',
'gemini-1.5-flash-002',
'gemini-1.5-pro-002'
]
model = None
for model_name in model_names:
try:
print(f"🔄 Δοκιμή μοντέλου: {model_name}")
test_model = genai.GenerativeModel(model_name)
# Δοκιμαστική κλήση
test_response = test_model.generate_content("Hi")
model = test_model
print(f"✅ Gemini AI - Συνδέθηκε με μοντέλο: {model_name}")
break
except Exception as e:
print(f" ❌ Αποτυχία: {str(e)[:50]}...")
continue
if model is None:
print("\n❌ Κανένα μοντέλο δεν δούλεψε!")
print("💡 Πιθανές λύσεις:")
print(" 1. Το API key σου μπορεί να μην είναι έγκυρο")
print(" 2. Δημιούργησε νέο API key από: https://aistudio.google.com/app/apikey")
print(" 3. Βεβαιώσου ότι το αντέγραψες σωστά (όλο το κλειδί)")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
except Exception as e:
print(f"❌ Gemini AI - ΚΡΙΣΙΜΟ ΣΦΑΛΜΑ: {e}")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
# Αρχικοποίηση του text-to-speech
try:
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 0.9)
print("✅ Text-to-Speech - OK")
except Exception as e:
print(f"❌ Text-to-Speech - ΣΦΑΛΜΑ: {e}")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
# Αρχικοποίηση του speech recognition
recognizer = sr.Recognizer()
# Έλεγχος μικροφώνου
try:
with sr.Microphone() as source:
print("✅ Μικρόφωνο - Βρέθηκε")
except Exception as e:
print(f"❌ Μικρόφωνο - ΣΦΑΛΜΑ: {e}")
print("\n💡 Λύσεις:")
print(" 1. Βεβαιώσου ότι έχεις μικρόφωνο συνδεδεμένο")
print(" 2. Τρέξε: pip install pyaudio")
print(" 3. Αν δεν δουλεύει, τρέξε: pip install pipwin")
print(" μετά: pipwin install pyaudio")
input("\nΠάτησε Enter για έξοδο...")
sys.exit(1)
def speak(text):
"""Μετατρέπει κείμενο σε ομιλία"""
print(f"\n🤖 Βοηθός: {text}")
try:
engine.say(text)
engine.runAndWait()
except Exception as e:
print(f"⚠️ Σφάλμα ομιλίας: {e}")
def listen():
"""Ακούει και αναγνωρίζει φωνητική εντολή"""
with sr.Microphone() as source:
print("\n🎤 Ακούω... (Μίλα τώρα!)")
recognizer.adjust_for_ambient_noise(source, duration=1)
try:
audio = recognizer.listen(source, timeout=10, phrase_time_limit=10)
print("⏳ Επεξεργασία...")
# Αναγνώριση ομιλίας (Ελληνικά)
text = recognizer.recognize_google(audio, language="el-GR")
print(f"👤 Εσύ: {text}")
return text
except sr.WaitTimeoutError:
print("⏱️ Timeout - Δεν άκουσα τίποτα")
return None
except sr.UnknownValueError:
print("❓ Δεν κατάλαβα τι είπες")
return None
except sr.RequestError as e:
print(f"❌ Πρόβλημα με την υπηρεσία: {e}")
return None
except Exception as e:
print(f"❌ Απρόσμενο σφάλμα: {e}")
return None
def get_gemini_response(prompt):
"""Παίρνει απάντηση από το Gemini AI"""
try:
response = model.generate_content(prompt)
return response.text
except Exception as e:
return f"Συγγνώμη, υπήρξε πρόβλημα με το AI: {str(e)}"
def main():
"""Κύρια συνάρτηση του βοηθού"""
print("\n" + "=" * 60)
print("✅ ΟΛΑ ΕΤΟΙΜΑ! Ο βοηθός ξεκινάει...")
print("=" * 60)
speak("Γεια σου! Είμαι ο φωνητικός σου βοηθός. Πώς μπορώ να σε βοηθήσω;")
while True:
try:
# Άκου την εντολή του χρήστη
user_input = listen()
if user_input is None:
continue
# Έλεγχος για εντολές εξόδου
exit_words = ['σταμάτα', 'τέλος', 'έξοδος', 'αντίο', 'τερματισμός']
if any(word in user_input.lower() for word in exit_words):
speak("Αντίο! Καλή συνέχεια!")
break
# Στείλε την ερώτηση στο Gemini
print("🤔 Σκέφτομαι...")
response = get_gemini_response(user_input)
# Πες την απάντηση
speak(response)
except KeyboardInterrupt:
print("\n\n⚠️ Διακοπή από χρήστη (Ctrl+C)")
speak("Τερματίζω...")
break
except Exception as e:
print(f"\n❌ Σφάλμα: {e}")
speak("Υπήρξε ένα πρόβλημα. Προσπάθησε ξανά.")
if __name__ == "__main__":
try:
main()
except Exception as e:
print(f"\n💥 ΚΡΙΣΙΜΟ ΣΦΑΛΜΑ: {e}")
import traceback
traceback.print_exc()
finally:
print("\n👋 Τερματισμός προγράμματος...")
input("Πάτησε Enter για έξοδο...")
→ On the line that says GEMINI_API_KEY = "PUT_YOUR_KEY_HERE", paste your key.
→ Save the file as voice_assistant.py.
Step 5: Start your Assistant!
Run the file voice_assistant.py as you would run a program.
Press Enter and when you hear "Listening... Speak now!", try phrases like: "Tell me the weather today."
🎉 Congratulations!
You now have your own voice assistant with artificial intelligence! Speak to it freely and listen to its responses.
Remember that your API key is personal and acts like a "bank account" for accessing Google AI Studio. Never share it publicly. and keep it safe. This way you can use your voice assistant with peace of mind and security.
Loading comments...