How make Something like alexa

import os
import time
import webbrowser
from datetime import date
import playsound
import speech_recognition as sr
from gtts import gTTS
import wikipedia
from datetime import datetime

WAKE = 'Sam'


def speak111(text):
    tts = gTTS(text=text, lang="en")
    filename = "b.mp3"
    playsound.playsound(filename)


def speak1000(text):
    tts = gTTS(text=text, lang="en")
    filename = "bbvhdzdzhuif.mp3"
    tts.save(filename)
    playsound.playsound(filename)


def speak100(text):
    tts = gTTS(text=text, lang="en")
    filename = "bumakdg.mp3"
    playsound.playsound(filename)


def speak12(text):
    tts = gTTS(text=text, lang="en")
    filename = "dck.mp3"
    playsound.playsound(filename)


def speak2(text):
    tts = gTTS(text=text, lang="en")
    filenam = "vo.mp3"
    playsound.playsound(filenam)


def speak3(text):
    tts = gTTS(text=text, lang="en")
    filenam = "voi.mp3"
    playsound.playsound(filenam)


def speak4(text):
    tts = gTTS(text=text, lang="en")
    filenam = "voic.mp3"
    playsound.playsound(filenam)


def speak5(text):
    tts = gTTS(text=text, lang="en")
    filename = "voic.mp3"
    playsound.playsound(filename)


def speak1(text):
    tts = gTTS(text=text, lang="en")
    filename = "voice1.mp3"
    playsound.playsound(filename)


def get_audio():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source)
        said = ""

        try:
            said = r.recognize_google(audio)
            print(said)
        except Exception as e:
            said = None
    return said


def speak(text):
    tts = gTTS(text=text, lang="en")
    filename = "v.mp3"
    tts.save(filename)
    playsound.playsound(filename)


while True:
    text = get_audio()
    if text is not None:
        if "hello" == text:
            speak("hello, how are you?")
            print("hello, how are you?")
        elif "what is your name" == text:
            speak2("My name is Sam")
            print("My name is Sam")
        elif 'open YouTube' == text:
            webbrowser.open_new_tab('https://www.youtube.com/')
        elif 'tell me the news' == text:
            webbrowser.open_new_tab('https://www.bbc.co.uk/newsround')
        elif 'open my maps' == text:
            webbrowser.open_new_tab('https://www.mymaths.co.uk/')
        elif 'open HW' == text:
            webbrowser.open_new_tab('https://www.satchelone.com/todos/issued')
        elif 'open mail' == text:
            webbrowser.open_new_tab('https://outlook.office365.com/mail/inbox')
        elif 'what is the weather' == text or 'tell me the weather' == text or 'tell me the weather in barkingside' == text:
            webbrowser.open_new_tab(
                'https://www.google.com/search?q=weather&oq=weather&aqs=chrome..69i57j0j69i59l2j0l4.2886j1j7&sourceid=chrome&ie=UTF-8')
        elif 'open' == text:
            webbrowser.open('https://www.google.com/search?q=gmail')
        elif 'tell me the time' == text:
            now = datetime.now()
            current_time = now.strftime("%H:%M")
            print("Current Time =", current_time)
            speak('the time is' + current_time)
        elif 'tell me the date' == text or 'what is the time' == text:
            today = date.today()
            print("Today's date:", today)
        elif 'Google' in text:
            speak12('searching Google')
            print('searching Google')
            text = text.replace(' on Google', '')
            webbrowser.open_new_tab('https://www.google.com/search?q={}'.format(text))
        elif 'YouTube' in text:
            speak111('searching Youtube')
            print('searching Youtube')
            text = text.replace('on YouTube', '')
            webbrowser.open_new_tab('https://www.Youtube.com/search?q={}'.format(text))
        elif 'play' in text:
            speak111('searching Youtube')
            print('searching Youtube')
            text = text.replace('play', '')
            webbrowser.open_new_tab('https://www.Youtube.com/search?q={}'.format(text))
        elif 'Wikipedia' in text:
            speak3('searching wikipedia')
            print('searching wikipedia')
            text = text.replace('wikipedia', '')
            results = wikipedia.summary(text, sentences=2)
            speak4(results)
            print(results)

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source