-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (78 loc) · 2.97 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import speech_recognition as sr
import numpy as np
import matplotlib.pyplot as plt
import cv2
from easygui import *
import os
from PIL import Image, ImageTk
from itertools import count
import tkinter as tk
import string
import pickle
import pandas as pd
from nltk.corpus import stopwords
from textblob import Word
def prog(inp):
data = pd.DataFrame(inp)
# Doing some preprocessing on these tweets as done before
data[0] = data[0].str.replace('[^\w\s]',' ')
# From nltk.corpus import stopwords
stop = stopwords.words('english')
data[0] = data[0].apply(lambda x: " ".join(x for x in x.split() if x not in stop))
# From textblob import Word
data[0] = data[0].apply(lambda x: " ".join([Word(word).lemmatize() for word in x.split()]))
# Extracting Count Vectors Parameters using the vector pickel generated in Text-Emotion-Detection
vectorizer = pickle.load(open("vector.pickel", "rb"))
model_count = vectorizer.transform(data[0])
#Predicting the emotion of the tweet using our already trained linear SVM
model = pickle.load(open('model.pickel', 'rb'))
model_pred = model.predict(model_count)
if(model_pred[0] == 0):
print("Emotion: Happiness")
else:
print("Emotion: Sadness")
# obtain audio from the microphone
def func():
r = sr.Recognizer()
arr=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z']
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
i=0
while True:
print('Say something')
# recognize speech using Uberi
try:
audio = r.record(source, duration = 5)
a = r.recognize_google(audio)
for c in string.punctuation:
a = a.replace(c,"")
print("you said " + a.lower())
inp = []
text = a.lower()
inp.append(text)
prog(inp)
for i in range(len(a)):
if(a[i] in arr):
ImageAddress = 'letters/'+a[i]+'.jpg'
ImageItself = Image.open(ImageAddress)
ImageNumpyFormat = np.asarray(ImageItself)
plt.imshow(ImageNumpyFormat)
plt.draw()
plt.pause(0.8) # pause how many seconds
else:
continue
plt.close()
break
except:
print('Exception Occurred')
#func()
while 1:
image = "signlang.png"
msg = "HEARING IMPAIRMENT ASSISTANT"
choices = ["Live Voice","All Done!"]
reply = buttonbox(msg,image=image,choices=choices)
if reply ==choices[0]:
func()
if reply == choices[1]:
quit()