From ec3aef0f2db386a009f90d95c83d8159239d213f Mon Sep 17 00:00:00 2001 From: Varun Saran Date: Sat, 26 Oct 2019 22:33:59 -0700 Subject: [PATCH 1/4] updated recorder.py with Wolfram Alpha API --- recorder.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/recorder.py b/recorder.py index 3ea088e..7232eff 100644 --- a/recorder.py +++ b/recorder.py @@ -1,6 +1,11 @@ +import requests import speech_recognition as sr -r = sr.Recognizer() +import wolframalpha + +appId = "E6A599-295PX2RKJE" +client = wolframalpha.Client(appId) +r = sr.Recognizer() mic = sr.Microphone() with mic as source: @@ -9,3 +14,10 @@ a = r.recognize_google(audio) print(a) +#a= 'e^x/x^2 = 15' +res = client.query(a) +#for pod in res.pods: + #print("**********************pod:", pod.keys() ) +#print("**********res:", res) +#print("**********res.results:", res.results) +print("**********res.results:", next(res.results).text) From 866ae1a321b7969bdf00323ceba12c71add6695a Mon Sep 17 00:00:00 2001 From: Steven Christopher Date: Sat, 26 Oct 2019 22:48:20 -0700 Subject: [PATCH 2/4] "Added checks for finding 'quantity' and 'all' for ()" --- Textalk.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Textalk.py b/Textalk.py index 8491200..db681d1 100644 --- a/Textalk.py +++ b/Textalk.py @@ -59,6 +59,40 @@ def parsestr(s): s = s.replace(key, d[key](s)) return s +# Returns a lst of indices containing +def quantity(s): + lst = [] + + def helper(s, index_lst): + if 'quantity' in s: + # Remember to add index by 1 more for end index because second l in all will not be included \ + # in range() if not inclusive + start_index, end_index = s.find('quantity'), s.find('all') + 2 + index_lst.append([start_index, end_index]) + return helper(s[end_index:], index_lst) + return lst + return helper(s, lst) + + +# Returns a list of the string segments containing +def quantity_checker(s, lst_of_indices): + str_lst = [] + + def checker(s, lst): + if lst: + start_index, end_index = lst[0][0], lst[0][1] + str_lst.append(s[start_index:end_index + 1]) + lst.pop(0) + return checker(s[end_index:], lst) + return str_lst + return checker(s, lst_of_indices) + +# Check before printing final latex string +def check(latex): + for word in l_d.keys(): + if word in latex: + latex = latex.replace(word, l_d[word]) + return latex # s = 'seventy one plus three' # new_s = parsestr(s) @@ -67,3 +101,4 @@ def parsestr(s): print(parsestr_numeric('Your total is four thousand two hundred ninety one dollars sixty seven cents and one hundred seventeen unborn fetuses')) print(parsestr_numeric(parsestr_substitute('one plus two minus three times four equals zero'))) print(parsestr_numeric(parsestr_substitute('I hate epsilon delta proofs'))) + From 3e3aca351390a08e5cc3a568df744ac690c2d00b Mon Sep 17 00:00:00 2001 From: Varun Saran Date: Sat, 26 Oct 2019 23:13:11 -0700 Subject: [PATCH 3/4] made calculate function --- recorder.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/recorder.py b/recorder.py index 7232eff..0c2f415 100644 --- a/recorder.py +++ b/recorder.py @@ -8,16 +8,18 @@ r = sr.Recognizer() mic = sr.Microphone() -with mic as source: +'''uncomment for mic functionality + with mic as source: r.adjust_for_ambient_noise(source) audio = r.listen(source) - -a = r.recognize_google(audio) -print(a) +''' +#a = r.recognize_google(audio) +#print(a) #a= 'e^x/x^2 = 15' -res = client.query(a) -#for pod in res.pods: - #print("**********************pod:", pod.keys() ) -#print("**********res:", res) -#print("**********res.results:", res.results) -print("**********res.results:", next(res.results).text) +def calculate(str): + res = client.query(str) + return next(res.results).text + + +a = 'integrate x squared' +print(calculate(a)) From ec3160bf644bc5c0cb98c7bf3c0fd3dab4b773a0 Mon Sep 17 00:00:00 2001 From: CalvinYan Date: Sat, 26 Oct 2019 23:21:10 -0700 Subject: [PATCH 4/4] Integrate Textalk.py with recorder.py and app.py --- Textalk.py | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/Textalk.py b/Textalk.py index db681d1..536d353 100644 --- a/Textalk.py +++ b/Textalk.py @@ -1,4 +1,5 @@ from word2number import w2n +from recorder import calculate import csv words_numeric = set() words_substituted = {} @@ -14,13 +15,15 @@ words_substituted[row[0]] = row[1] def parsestr(s): - for key in d.keys(): - if key in s: - if type(d[key]) == str: - s = s.replace(key, d[key]) - else: - s = s.replace(key, d[key](s)) - return s + # for key in d.keys(): + # if key in s: + # if type(d[key]) == str: + # s = s.replace(key, d[key]) + # else: + # s = s.replace(key, d[key](s)) + # return s + calculate(s) + return parsestr_numeric(parsestr_substitute(s)) def parsestr_numeric(s): words = s.split() @@ -35,30 +38,12 @@ def parsestr_numeric(s): return s def parsestr_substitute(s): - print(words_substituted) words = s.split() for i in range(len(words)): if words[i] in words_substituted: - print('HIT') words[i] = words_substituted[words[i]] return ' '.join(words) -# d ={'equals' : '=','equal': '=', 'plus':'+', 'minus':'-', 'over' : '/', 'divided by':'/', 'greater than' : '>','less than':'<', 'percentage':'%', 'percent':'%', \ -# 'multiplied' :'*', 'multiply':'*', 'multiplied by' :'*', 'multiply by':'*', 'sum of' : sum_of} - -# s = 'seventy one plus three' -# new_s = parsestr(s) -# print(new_s) - -def parsestr(s): - for key in d.keys(): - if key in s: - if type(d[key]) == str: - s = s.replace(key, d[key]) - else: - s = s.replace(key, d[key](s)) - return s - # Returns a lst of indices containing def quantity(s): lst = [] @@ -94,11 +79,7 @@ def check(latex): latex = latex.replace(word, l_d[word]) return latex -# s = 'seventy one plus three' -# new_s = parsestr(s) -# print(new_s) - -print(parsestr_numeric('Your total is four thousand two hundred ninety one dollars sixty seven cents and one hundred seventeen unborn fetuses')) -print(parsestr_numeric(parsestr_substitute('one plus two minus three times four equals zero'))) -print(parsestr_numeric(parsestr_substitute('I hate epsilon delta proofs'))) - +# print(parsestr('Your total is four thousand two hundred ninety one dollars sixty seven cents and one hundred seventeen unborn fetuses')) +# print(parsestr('one plus two minus three times four equals zero')) +# print(parsestr('I just did three hundred and sixty five epsilon delta proofs')) +print(parsestr('The integral from zero to x times 5 of x plus x to the power of two'))