Giter VIP home page Giter VIP logo

romantic-alexa's Introduction

romantic-alexa

Build an Artificial Assistant

Full tutorial (video)

To watch the tutorial, click on the image below

Watch the video-- Build your own Alexa

Installation

For windows users

(run those in command prompt/cmt/terminal) For the robot to listen to our voice/speech pip install speechRecognition

To speak out, or text to speech pip install pyttsx3

For advance control on browser pip install pywhatkit

To get wikipedia data pip install wikipedia

To get funny jokes pip install pyjokes

For linux users

Learn all the above commands on terminal. Make sure to use pip3, because in linux pip refers for python2 and pip3 refers to python3. Install these too - pip3 install pyAudio

In case any error pops up install this - pip3 install portAudio

Issues

If you encounter any problems feel free to open a new issue. Before that check other closed issues and check if your issue matches with any older issues.

romantic-alexa's People

Contributors

ashraf-minhaj avatar programminghero1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

romantic-alexa's Issues

I am a little new to programming and I wrote the same code in vs code and installed everything with pip but still I am getting an error

I am a little new to programming and I wrote the same code in vs code and installed everything with pip but still I am getting an error -

PS C:\Users\HP\OneDrive\Documents\GitHub\romantic-alexa> & C:/Users/HP/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/HP/OneDrive/Documents/GitHub/romantic-alexa/main.py
Traceback (most recent call last):
File "c:/Users/HP/OneDrive/Documents/GitHub/romantic-alexa/main.py", line 60, in
run_alexa()
File "c:/Users/HP/OneDrive/Documents/GitHub/romantic-alexa/main.py", line 35, in run_alexa
command = take_command()
File "c:/Users/HP/OneDrive/Documents/GitHub/romantic-alexa/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment
PS C:\Users\HP\OneDrive\Documents\GitHub\romantic-alexa>

Please help me @ashraf-minhaj or @ProgrammingHero1

Code not being executed !

Hello, i am on Ubuntu, python3.7
Got everything installed, typed the first part of te code just to test but it seems it's not entering the loop. Actually nothing happened when I run the code.

I'll be thankful if you answer my request

Facing below errors after running the program in pychram

"C:\Users\ANKIT KENE\PycharmProjects\Mybot\venv\Scripts\python.exe" "C:/Users/ANKIT KENE/PycharmProjects/Mybot/main.py"
Traceback (most recent call last):
File "C:/Users/ANKIT KENE/PycharmProjects/Mybot/main.py", line 60, in
run_alexa()
File "C:/Users/ANKIT KENE/PycharmProjects/Mybot/main.py", line 35, in run_alexa
command = take_command()
File "C:/Users/ANKIT KENE/PycharmProjects/Mybot/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Some Issue if any one could help!!!

Traceback (most recent call last):
File "C:/Users/KIIT/PycharmProjects/alexa/main.py", line 60, in
run_alexa()
File "C:/Users/KIIT/PycharmProjects/alexa/main.py", line 35, in run_alexa
command = take_command()
File "C:/Users/KIIT/PycharmProjects/alexa/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

This error are encountered

"C:\Users\Krishna Purohit\PycharmProjects\Snaya\venv\Scripts\python.exe" "C:/Users/Krishna Purohit/PycharmProjects/Snaya/main.py"
Traceback (most recent call last):
File "C:/Users/Krishna Purohit/PycharmProjects/Snaya/main.py", line 62, in
run_alexa()
File "C:/Users/Krishna Purohit/PycharmProjects/Snaya/main.py", line 37, in run_alexa
command = take_command()
File "C:/Users/Krishna Purohit/PycharmProjects/Snaya/main.py", line 32, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Process finished with exit code 1

please reply sir

Traceback (most recent call last):
File "C:/Users/Aadi/Downloads/MEmu Download/Free_Fire_com.dts.freefireth/ALEXA/main.py", line 60, in
run_alexa()
File "C:/Users/Aadi/Downloads/MEmu Download/Free_Fire_com.dts.freefireth/ALEXA/main.py", line 35, in run_alexa
command = take_command()
File "C:/Users/Aadi/Downloads/MEmu Download/Free_Fire_com.dts.freefireth/ALEXA/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Error Help!!!

Traceback (most recent call last):
line 11, in
engine.setProperty('voice', voices[1].id)
IndexError: list index out of range

UnboundLocalError

I just copied and pasted it. but the error has occurred.

UnboundLocalError: local variable 'command' referenced before assignment

Program Ends Without Any Voice Detection

I was just trying the part of the video where the voice recognition was being tested.
But the program just ends without any error.
Does not take in any voice input.

Process finished with exit code 0

Here is my code:

import speech_recognition as sr
listener = sr.Recognizer()
try:
with sr.Microphone() as source:
print("listening...")
voice = listener.listen(source)
command = listener.recognize_google(voice)
print(command)
except:
pass

I have downloaded and installed all of the required packages using:

pip install speechRecognition pyttsx3 pywhatkit wikipedia pyjokes

with voice

line 11, in
engine.setProperty('voice', voices[1].id)
IndexError: list index out of range

it doesnt work

listening...
Traceback (most recent call last):
File "c:\Users\Egehan\Desktop\alexa\E.py", line 58, in
run_alexa()
File "c:\Users\Egehan\Desktop\alexa\E.py", line 34, in run_alexa
command = take_command()
File "c:\Users\Egehan\Desktop\alexa\E.py", line 30, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

error while compiling

C:\Users\vasuk\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/vasuk/PycharmProjects/pythonProject/main.py
Hello from the creator of pywhatkit, Ankit Raj Mahapatra.
Kindly do report bugs if any
What's new:

  1. Fixed text_to_handwriting() function.
  2. Added pywhatkit.help. for ease of use.
  3. Added feature to schedule message in a group.
    listening...
    Traceback (most recent call last):
    File "C:\Users\vasuk\PycharmProjects\pythonProject\main.py", line 60, in
    run_alexa()
    File "C:\Users\vasuk\PycharmProjects\pythonProject\main.py", line 35, in run_alexa
    command = take_command()
    File "C:\Users\vasuk\PycharmProjects\pythonProject\main.py", line 31, in take_command
    return command
    UnboundLocalError: local variable 'command' referenced before assignment

Process finished with exit code 1

UnboundLocalError: local variable 'command' referenced before assignment

I am using this code in rasberry pi and it shows following error

Traceback (most recent call last):
File "/home/pi/Project/alexa.py", line 60, in
run_alexa()
File "/home/pi/Project/alexa.py", line 35, in run_alexa
command = take_command()
File "/home/pi/Project/alexa.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

I am getting an error whenever i run the program:

See My Code? scroll a bit
Error:
Traceback (most recent call last):
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 70, in
run_python()
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 35, in run_python
command = take_command()
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before `assignment```

And my Code is:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

def talk(text):
engine.say(text)
engine.runAndWait()

def take_command():
try:
with sr.Microphone() as source:
print("Listening....")
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'python' in command:
command = command.replace('python', '')
print(command)
except:
pass
return command

def run_python():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
print(time)
talk('The time is' + time)
elif 'what is' in command:
query = command.replace('what is', '')
info = wikipedia.summary(query, 1)
print(info)
talk(info)
elif 'who is' in command:
person = command.replace('who is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'your name' in command:
talk("Hi My Name Is Python")
elif 'created you' in command:
talk('Tanush has created me')
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'shut up' in command:
talk('quitting')
exit()
else:
print("Could you repeat it again?")
talk('Could you repeat it again')

while True:
run_python()

I don't know what the problem with my code , please help!

I Hello, I had the same error described in the previous issue I fixed what was but it does not work properly. I say for example "jarvis play all of fame" so it works but after that it starts to get stuck quite a bit and just keeps saying "I feel great, thanks".
In addition he suddenly decides he wants to say the same sentence I said before regardless of anything, I mean I mean even if I said nothing.
One last thing if someone will be able to also explain to me how to control apps like Word or Excel in the same way because I didn't success...
Another thing i also tried to run the original code that found here and i couldn't play nothing except from arianda grande's songs...

that's the code:

import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import os
import subprocess

listener = sr.Recognizer()
engine = pyttsx3.init()


def talk(text):
    engine.say("hello sir ")
    engine.say(text)
    engine.runAndWait()


def take_commands():
    command = ''
    try:
        with sr.Microphone() as source:
            print("listening...")
            voice = listener.listen(source)
            command = listener.recognize_google(voice)
            command = command.lower()
            if "hi jarvis" or "hey jarvis" in command:
                # command = command.replace("hi jarvis", "")
                # command = command.replace("hey jarvis", "")
                command = command.replace(" jarvis", "")
                engine.runAndWait()
                print(command)
    except:
        pass
    return command


def run_jarvis():
    command = take_commands()
    print(command)
    if "play" in command:
        song = command.replace("play", "")
        talk("playing" + song)
        pywhatkit.playonyt(song)
    elif "time" in command:
        time = datetime.datetime.now().strftime("%H:%M")
        print(time)
        talk("the time now is" + time)
    elif "who is" in command:
        person = command.replace("hi who is", "")
        info = wikipedia.summary(person, 1)
        print(info)
        talk(  info)
    elif "joke" in command:
        d = pyjokes.get_joke()
        print(d)
        talk(d)
    elif "how are you" or "how do you feel" in command:
        feeling = "I'm feeling great, thank you"
        talk(feeling)
    elif "open" and "file" in command:
        command = command.replace("open the file")
        file = os.popen(command)
        talk("Opens the file")
        if "close" and " the file" in command:
            file = os.close(command)
    elif "open" and " new file" in command:
        command = command.replace("open a new file , that to be called")
        file = os.popen(command)
        talk("Opens a file")
        if "close" and " the file" in command:
            file = os.close(command)
    elif "open" and " new folder" in command:
        command = command.replace("open a new folder , that to be called")
        folder = os.popen(command)
        talk("Opens a folder")
        if "close" and " the folder" in command:
            folder = os.close(command)
    elif "open word" in command:
        open("python11.docx", "w+")
        # subprocess.call("C:\\Program Files\\Microsoft Office\\root\Office16\\WINWORD.EXE")
        talk("Opens Word")
    elif "open excel" in command:
        subprocess.call("C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE")
        talk("Opens Excel")
    elif "open premiere" or "open adobe premiere pro" in command:
        subprocess.call("C:\Program Files\Adobe\Adobe Premiere Pro 2020\Adobe Premiere Pro.exe")
        talk("Opens Adobe Premiere Pro 2020")
    elif "open outlook" in command:
        subprocess.call("C:\\Program Files\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE")
        talk("Opens Outlook")
    elif "open notepad++" in command:
        subprocess.call("C:\\Program Files\\Notepad++\\notepad++.exe")
        talk("Opens Notepad++")
    elif "open chrome" in command:
        subprocess.call("C:\Program Files\Google\Chrome\Application\chrome.exe")
        talk("Opens Chrome")
    elif "open notepad" in command:
        subprocess.Popen(["C:\\WINDOWS\\system32\\notepad.exe"])
        talk("Opens Notepad")
    else:
        talk("Please say that's again")


while True:
    run_jarvis()

I can't run the code

I havea problem and I installed all the packages completely
this is problem that shows after running the code
Traceback (most recent call last):
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 70, in
run_python()
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 35, in run_python
command = take_command()
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before `assignment```

unbound error

Exception has occurred: UnboundLocalError
local variable 'command' referenced before assignment
File "D:\programs\python awesome\funcode\alexa.py", line 32, in take_command
return command
File "D:\programs\python awesome\funcode\alexa.py", line 36, in run_alexa
command = take_command()
File "D:\programs\python awesome\funcode\alexa.py", line 61, in
run_alexa()

this is what my error is, sir

I had an error installing the " PyAudio" and "portAudio ". I use zorinOs, venv and my python version is the 3.6

Error of the portAudio

Traceback (most recent call last):
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/commands/install.py", line 353, in run
wb.build(autobuilding=True)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages
page = self._get_page(location)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/lib/python3.6/site-packages/pip/index.py", line 795, in get_page
resp.raise_for_status()
File "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/portaudio/

##Error of the PyAudio

Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: PyAudio
Running setup.py bdist_wheel for PyAudio ... error
Complete output from command /media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-giuvzwfs/PyAudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmp00v680pipip-wheel- --python-tag cp36:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for PyAudio
Running setup.py clean for PyAudio
Failed to build PyAudio
Installing collected packages: PyAudio
Running setup.py install for PyAudio ... error
Complete output from command /media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-giuvzwfs/PyAudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-xewmto71-record/install-record.txt --single-version-externally-managed --compile --install-headers /media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/include/site/python3.6/PyAudio:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying src/pyaudio.py -> build/lib.linux-x86_64-3.6
running build_ext
building '_portaudio' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/include -I/usr/include/python3.6m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.6/src/_portaudiomodule.o
src/_portaudiomodule.c:28:10: fatal error: Python.h: Ficheiro ou directoria inexistente
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command "/media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-giuvzwfs/PyAudio/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-xewmto71-record/install-record.txt --single-version-externally-managed --compile --install-headers /media/dikenge/460C8FA50C8F8E9D/Aplications_exercice/Isabel_IA/.venv/include/site/python3.6/PyAudio" failed with error code 1 in /tmp/pip-build-giuvzwfs/PyAudio/

how to solve this errors?

Traceback (most recent call last):
File "c:\Users\users\Documents\Programming\Python\AI\Virtual Assistant.py", line 63, in
run_alexa()
File "c:\Users\users\Documents\Programming\Python\AI\Virtual Assistant.py", line 38, in run_alexa
command = take_command()
File "c:\Users\users\Documents\Programming\Python\AI\Virtual Assistant.py", line 34, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Windows 10
VS Code

thanks in advance

I'm having a issue

"C:\Users\Francisco Silva\Desktop\webscrapping_clubs\Alexa\Scripts\python.exe" "C:/Users/Francisco Silva/Desktop/Coding/Python/Alexa/Alexa.py"
listening...
Traceback (most recent call last):
File "C:/Users/Francisco Silva/Desktop/Coding/Python/Alexa/Alexa.py", line 60, in
run_alexa()
File "C:/Users/Francisco Silva/Desktop/Coding/Python/Alexa/Alexa.py", line 35, in run_alexa
command = take_command()
File "C:/Users/Francisco Silva/Desktop/Coding/Python/Alexa/Alexa.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Process finished with exit code 1

UnboundLocalError: local variable 'command' referenced before assignment

I've spent some time in the issues section, and found issue #5. I fixed the problem with it running, however after a certain period of time it times out and gives me "UnboundLocalError: local variable 'command' referenced before assignment", which I read happens if you listener returns none.

How do I prevent this from happening? For example, if I want it to always run in the backround so that whenever I use the wake word and then "play" and a song name, it pulls it up? I find it annoying to have to run it every time.

Thanks for any help!

Getting error when run the program

getting error-

Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), main.dict)
File "", line 3, in
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pywhatkit/init.py", line 4, in
from pywhatkit.mainfunctions import sendwhatmsg_to_group, watch_tutorial_in_English, watch_tutorial_in_Hindi, developer_contact, showHistory, shutdown, cancelShutdown, prnt_sleeptm, check_window, sendwhatmsg, info, playonyt, image_to_ascii_art, search
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pywhatkit/mainfunctions.py", line 3, in
import pyautogui as pg
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pyautogui/init.py", line 241, in
import mouseinfo
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/mouseinfo/init.py", line 223, in
_display = Display(os.environ['DISPLAY'])
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/os.py", line 675, in getitem
raise KeyError(key) from None
KeyError: 'DISPLAY'

my program was-

import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)

def talk(text):
engine.say(text)
engine.runAndWait()

def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except:
pass
return command

def run_alexa():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('Current time is ' + time)
elif 'who the heck is' in command:
person = command.replace('who the heck is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'date' in command:
talk('sorry, I have a headache')
elif 'are you single' in command:
talk('I am in a relationship with wifi')
elif 'joke' in command:
talk(pyjokes.get_joke())
else:
talk('Please say the command again.')

while True:
run_alexa()

getting this error

Traceback (most recent call last):
File "C:/Users/usre/PycharmProjects/pythonProject1/main.py", line 59, in
run_alexa()
File "C:/Users/usre/PycharmProjects/pythonProject1/main.py", line 36, in run_alexa
if 'play' in command:
NameError: name 'command' is not defined
None

Error in program

Traceback (most recent call last):
File "C:\Users\Home\PycharmProjects\pythonProject\alexa.py", line 60, in
run_alexa()
File "C:\Users\Home\PycharmProjects\pythonProject\alexa.py", line 35, in run_alexa
command = take_command()
File "C:\Users\Home\PycharmProjects\pythonProject\alexa.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Can you please tell what to do ?

Getting error in this part

try:
    _with sr.Microphone() as source:_
        print('listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        command = command.lower()
        if 'alexa' in command:
            command = command.replace('alexa', '')
            print(command)
except:
    print("failed")

Error is in this line :with sr.Microphone() as source:
hence only except part is running 👎

Please Help It was all working fine and now it isn't working

Please Help It was working and I made my own and that was also working then it showed error
PS C:\Users\user> & C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe c:/Users/user/g.py
Traceback (most recent call last):
File "c:\Users\user\g.py", line 60, in
run_alexa()
File "c:\Users\user\g.py", line 35, in run_alexa
command = take_command()
File "c:\Users\user\g.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

How to resolve this ?

how to set something in command variable by default because if we don't say anything then it is showing an error message, it requires to listen to something everything. after saying play something it goes to youtube but next time when I return to Pycharm then it is showing error message so we need to set something by default to the command so that if we don't say anything to it , it won't show any error.

Unable to get Female Voice

I tried Your code.
but It is giving the Male voice.
also i tried every voice but there is not a single female voice.
Can you Help?

UnboundLocalError: local variable 'command' referenced before assignment

Traceback (most recent call last):
File "C:\Users\Asad\Desktop\romantic-alexa-main\romantic-alexa-main\main.py", line 60, in
run_alexa()
File "C:\Users\Asad\Desktop\romantic-alexa-main\romantic-alexa-main\main.py", line 35, in run_alexa
command = take_command()
File "C:\Users\Asad\Desktop\romantic-alexa-main\romantic-alexa-main\main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

********************ABOVE IS THE ERROR THAT I AM FACING AND BELOW IS THE CODE

import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)

def talk(text):
engine.say(text)
engine.runAndWait()

def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except:
pass
return command

def run_alexa():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('Current time is ' + time)
elif 'who the heck is' in command:
person = command.replace('who the heck is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'date' in command:
talk('sorry, I have a headache')
elif 'are you single' in command:
talk('I am in a relationship with wifi')
elif 'joke' in command:
talk(pyjokes.get_joke())
else:
talk('Please say the command again.')

while True:
run_alexa()

I don't know what type error is this

python3 assistent.py 1 ⨯
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
Traceback (most recent call last):
File "/home/Mr_3rr0r_501/.local/lib/python3.8/site-packages/pyttsx3/init.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.8/weakref.py", line 131, in getitem
o = self.datakey
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "assistent.py", line 9, in
engine = pyttsx3.init()
File "/home/Mr_3rr0r_501/.local/lib/python3.8/site-packages/pyttsx3/init.py", line 22, in init
eng = Engine(driverName, debug)
File "/home/Mr_3rr0r_501/.local/lib/python3.8/site-packages/pyttsx3/engine.py", line 30, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/home/Mr_3rr0r_501/.local/lib/python3.8/site-packages/pyttsx3/driver.py", line 50, in init
self._module = importlib.import_module(name)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/Mr_3rr0r_501/.local/lib/python3.8/site-packages/pyttsx3/drivers/espeak.py", line 9, in
from . import _espeak, toUtf8, fromUtf8
File "/home/Mr_3rr0r_501/.local/lib/python3.8/site-packages/pyttsx3/drivers/_espeak.py", line 18, in
dll = cdll.LoadLibrary('libespeak.so.1')
File "/usr/lib/python3.8/ctypes/init.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/init.py", line 373, in init
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory

What is the error is this??
i installed all the required packages.

Not able to run it without an error, even after following the whole process given in youtube

This input is the same thing given by Programming Hero:
Input:

`import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)

def talk(text):
engine.say(text)
engine.runAndWait()

def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except:
pass
return command

def run_alexa():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('Current time is ' + time)
elif 'who the heck is' in command:
person = command.replace('who the heck is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'date' in command:
talk('sorry, I have a headache')
elif 'are you single' in command:
talk('I am in a relationship with wifi')
elif 'joke' in command:
talk(pyjokes.get_joke())
else:
talk('Please say the command again.')

while True:
run_alexa()`

And the Output

`C:\Users\Admin\AppData\Local\Programs\Python\Python39\python.exe C:/Users/Admin/PycharmProjects1/main.py
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects1\main.py", line 60, in
run_alexa()
File "C:\Users\Admin\PycharmProjects1\main.py", line 35, in run_alexa
command = take_command()
File "C:\Users\Admin\PycharmProjects1\main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Process finished with exit code 1`

UnboundLocalError: local variable 'command' referenced before assignment

I don't know why this error is coming in my code . I am taking reference from your video . As I seen in your video you have repeated the word 'command' many times but no error has came . In my code this error is coming.

Traceback (most recent call last):
File "c:/Users/user/VS Code Projects/JAR.py", line 60, in
run_jarvis()
File "c:/Users/user/VS Code Projects/JAR.py", line 35, in run_jarvis
command = take_Command()
File "c:/Users/user/VS Code Projects/JAR.py", line 31, in take_Command
return command
UnboundLocalError: local variable 'command' referenced before assignment

I am writing this code in VS Code and I am using python 3.8.6 .

Hope you will help me.
Thanks
from @wiraj1
to @ProgrammingHero1

UnboundLocalError: local variable 'command' referenced before assignment

  • Error output:

D:\Python\Romantic-Alexa>main.py
Traceback (most recent call last):
File "D:\Python\Romantic-Alexa\main.py",
line 60, in
run_alexa()
File "D:\Python\Romantic-Alexa\main.py",
line 35, in run_alexa
command = take_command()
File "D:\Python\Romantic-Alexa\main.py",
line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.