the speech recognition is not working
here is my code :
import speech_recognition
robot_ear = speech_recognition.Recognizer()
with speech_recognition.Microphone() as mic:
print ("Robot: I'm listening")
audio = robot_ear.listen(mic)
you = robot_ear.recognize_google(audio)
print(you)
but the computer does not response to what I spoke
> Traceback (most recent call last): File "nghe1.py", line 6, in
> <module>
> audio = robot_ear.listen(mic) File "C:\Users\Jean\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py",
> line 652, in listen
> buffer = source.stream.read(source.CHUNK) File "C:\Users\Jean\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py",
> line 161, in read
> return self.pyaudio_stream.read(size, exception_on_overflow=False) File
> "C:\Users\Jean\AppData\Local\Programs\Python\Python38\lib\site-packages\pyaudio.py",
> line 608, in read
> return pa.read_stream(self._stream, num_frames, exception_on_overflow)
please show me how can I fix this
I have done speech recognition in python the code is very simple:
import speech_recognition as sr
rObject = sr.Recognizer()
audio = ''
with sr.Microphone() as source:
print("Speak...")
audio = rObject.listen(source, phrase_time_limit = 0)
print("Stop.")
try:
text = rObject.recognize_google(audio, language ='en-US')
print("You : "+ text)
except:
speak("Could not understand your audio...PLease try again !")
Try it , hope it will work according to your desired output .
Related
I'm trying to convert pdf file to txt.
`
import re
import PyPDF2
with open('123.pdf', 'rb') as pdfFileObj:
pdfreader = PyPDF2.PdfFileReader(pdfFileObj)
x = pdfreader.numPages
pageObj = pdfreader.getPage(x + 1)
text = pageObj.extractText()
file1 = open(f"C:\\Users\\honorr\\Desktop\\ssssssss\{re.sub('pdf$','txt',pdfFileObj)}", "a")
file1.writelines(text)
file1.close()
Errors:
Traceback (most recent call last):
File "C:\Users\honorr\Desktop\ssssssss\main.py", line 5, in <module>
pageobj = pdfreader.getPage(x + 1)
File "C:\Users\honorr\Desktop\ssssssss\venv\lib\site-packages\PyPDF2\_reader.py", line 477, in getPage
return self._get_page(pageNumber)
File "C:\Users\honorr\Desktop\ssssssss\venv\lib\site-packages\PyPDF2\_reader.py", line 492, in _get_page
return self.flattened_pages[page_number]
IndexError: list index out of range
`
How to fix it?
So i don't know why i have this errors. Maybe somebody tell me another way to convert from PDF to TXT?
You're setting x to the number of pages, but then trying to get page x + 1, which doesn't exist. Depending on how the library is implemented (I'm not familiar with PyPDF2), you may need to try pdfreader.getPage(x) or pdfreader.getPage(x - 1) to get it to work. This will only get the last page in the document though.
This is the code for opencv2 Takeimage button.
It doesn't work properly, only the cam light on, but camera interface doesn't show:
def TakeImage():
Id=(txt.get())
name=(txt2.get())
if(is_number(Id) and name.isalpha()):
Video= cv2.VideoCapture(0)
harcascadePath = "haarcascade_frontalfacedafults_.xml"
detector=cv2.CascadeClassifier(harcascadePath)
sampleNum=0
while(True):
ret,img=Video.read();
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=detector.DetectMultiScale(gray,1.2,5);
for(x,y,w,h) in faces:
cv2.recatangle(img,(x,y),(x+w,y+h),(255,0,0),2)
sampleNum=sampleNum+1
cv2.imwrite("TrainImages\ "+name +"."+Id +'.'+str(samlpeNum)+".jpg",gray[y:y+h,x:x+h])
cv2.imshow('Frame',img)
if cv2.waitKey(100) &0XFF == ord('s'):
break
elif sample>60:
break
Video.release()
cv2.destroyAllWindows()
res = "Images Saved for ID: "+ Id + " Name : "+ name
row = [Id, Name]
with open ('studentDetails\studentDetails.csv','a+') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
message.configure(text=res)
else:
if(is_number(Id)):
res ="Enter Alphabetical Name"
message.configure(text= res)
if (name.isalpha()):
res="Enter Numberic Id"
message.configure(text=res)
Error showing:
Exception in Tkinter callback Traceback (most recent call last):
File
"C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py",
line 1705, in call
return self.func(*args) File "C:\Users\Lenovo\Desktop\face reconiger system.py", line 87, in TakeImage
faces=detector.DetectMultiScale(gray,1.2,5); AttributeError: 'cv2.CascadeClassifier' object has no attribute 'DetectMultiScale'
The path to the .xml file looks incorrect. You need to replace the following line:
harcascadePath = "haarcascade_frontalfacedafults_.xml"
with
harcascadePath = cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
I am new to phraseMatcher and want to extract some keyword from my emails.
Everything is working well except that I can't get a name of added matcher.
This is my code below:
def main():
patterns_months = 'phraseMatcher/months.txt'
text_loc = 'phraseMatcher/text.txt'
nlp = spacy.blank('en')
nlp.vocab.lex_attr_getters ={}
phrases_months = read_gazetter(patterns_months)
txts = read_text(text_loc, n=n)
months = [nlp(text) for text in phrases_months]
matcher = PhraseMatcher(nlp.vocab)
matcher.add('MONTHS', None, *months)
print(nlp.vocab.strings['MONTHS'])
for txt in txts:
doc = nlp(txt)
matches = matcher(doc)
for match_id ,start, end in matches:
span = doc[start: end]
label = nlp.vocab.strings[match_id]
print(label, span.text, start, end)
The result:
12298211501233906429 <--- this is from print(nlp.vocab.strings['MONTHS'])
Traceback (most recent call last):
File "D:/workspace/phraseMatcher/venv/phraseMatcher.py", line 71, in <module>
plac.call(main)
File "D:\workspace\phraseMatcher\venv\lib\site-packages\plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "D:\workspace\phraseMatcher\venv\lib\site-packages\plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "D:/workspace/phraseMatcher/venv/phraseMatcher.py", line 47, in main
label = nlp.vocab.strings[match_id]
File "strings.pyx", line 117, in spacy.strings.StringStore.__getitem__
KeyError: "[E018] Can't retrieve string for hash '18446744072093410045'."
spaCy version:** 2.0.12
Platform:** Windows-7-6.1.7601-SP1
Python version:** 3.7.0
I can't find what I did wrong. It is simple and I read these already:
Using PhraseMatcher in SpaCy to find multiple match types
Help me, thanks in advance.
Omxplayer crashes after pushbuttons
I like to change movies with pushbuttons and this is code that I have so far but Omxplayer crashes after few pushbutton are push!
I am new to raspberry pi and python been looking for a fix but cannot find any. Any help is welcome.
The error I get is:
Traceback (most recent call last):
File "mygpio.py", line 34, in <module>
player.load(vida)
File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 162, in load
File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 88, in _load_source
File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 134, in _setup_dbus_connection
SystemError: DBus cannot connect to the OMXPlayer process
#!/usr/bin/env python2
import os.path
from time import sleep
import subprocess
import os
from omxplayer import OMXPlayer
vida = '/home/pi/Videos/testvids/6.mov'
vidb = '/home/pi/Videos/testvids/3.mov'
vidc = '/home/pi/Videos/testvids/t2.mp4'
default = '/home/pi/Videos/testvids/t1.mp4'
import RPi.GPIO as GPIO
#set up GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)
#All Gpio's as input and pull up
GPIO.setup(2, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_UP)
player = OMXPlayer(default,args=['--no-osd','--blank'],)
while True:
if GPIO.input(2) ==0:
player.load(vida)
print("gpio 2")
player.play()
#sleep(5)
if (GPIO.input(3) == 0):
player.load(vidb)
print("gpio 3")
player.play()
# sleep(5)
if (GPIO.input(4) == 0):
player.load(vidc)
print("gpio 4")
player.play()
#sleep(5)
GPIO.cleanup()
looks like this was a bug in the wrapper
https://github.com/willprice/python-omxplayer-wrapper/issues/85
Has anyone experienced this error before when trying to connect to hive.
Sample code used (https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-ngsi/resources/hiveclients/python/hiveserver2-client.py):
import sys
import pyhs2
from pyhs2.error import Pyhs2Exception
# get the input parameters
if len(sys.argv) != 6:
print 'Usage: python hiveserver2-client.py <hive_host> <hive_port> <db_name> <hadoop_user> <hadoop_password>'
sys.exit()
hiveHost = sys.argv[1]
hivePort = sys.argv[2]
dbName = sys.argv[3]
hadoopUser = sys.argv[4]
hadoopPassword = sys.argv[5]
# do the connection
with pyhs2.connect(host=hiveHost,
port=hivePort,
authMechanism="PLAIN",
user=hadoopUser,
password=hadoopPassword,
database=dbName) as conn:
# get a client
with conn.cursor() as client:
# create a loop attending HiveQL queries
while (1):
query = raw_input('remotehive> ')
try:
if not query:
continue
if query == 'exit':
sys.exit()
# execute the query
client.execute(query)
# get the content
for row in client.fetch():
print row
except Pyhs2Exception, ex:
print ex.errorMessage
Error displayed:
[centos#test]$ sudo python hiveserver2-client.py computing.cosmos.lab.fiware.org 10000 default USERNAME TOKEN
Traceback (most recent call last):
File "hiveserver2-client.py", line 42, in <module>
database=dbName) as conn:
File "/usr/lib/python2.7/site-packages/pyhs2/__init__.py", line 7, in connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/pyhs2/connections.py", line 46, in __init__
transport.open()
File "/usr/lib/python2.7/site-packages/pyhs2/cloudera/thrift_sasl.py", line 74, in open
status, payload = self._recv_sasl_message()
File "/usr/lib/python2.7/site-packages/pyhs2/cloudera/thrift_sasl.py", line 92, in _recv_sasl_message
header = self._trans.readAll(5)
File "/usr/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 60, in readAll
chunk = self.read(sz - have)
File "/usr/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 132, in read
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
can you post your piece of code ? This looks like some auth mechanism or credentials sent are not Valid.
authMechanism= can be "PLAIN" or "KERBEROS" as per your setup .