-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
170 lines (151 loc) · 9.87 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from threading import Thread
# import pygame
# import speake3
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 platform
def play_music():
os.system("gnome-terminal -e 'play bg.mp3'")
#import selecting for recorded voice
# obtain audio from the microphone
def func():
r = sr.Recognizer()
taslc_gif=['all the best', 'any questions', 'are you angry', 'are you busy', 'are you hungry', 'are you sick', 'be careful',
'can we meet tomorrow', 'did you book tickets', 'did you finish homework', 'do you go to office', 'do you have money',
'do you want something to drink', 'do you want tea or coffee', 'do you watch TV', 'dont worry', 'flower is beautiful',
'good afternoon', 'good evening', 'good morning', 'good night', 'good question', 'had your lunch', 'happy journey',
'hello what is your name', 'how many people are there in your family', 'i am a clerk', 'i am bore doing nothing',
'i am fine', 'i am sorry', 'i am thinking', 'i am tired', 'i dont understand anything', 'i go to a theatre', 'i love to shop',
'i had to say something but i forgot', 'i have headache', 'i like pink colour', 'i live in nagpur', 'lets go for lunch', 'my mother is a homemaker',
'my name is john', 'nice to meet you', 'no smoking please', 'open the door', 'please call an ambulance', 'please call me later',
'please clean the room', 'please give me your pen', 'please use dustbin dont throw garbage', 'please wait for sometime', 'shall I help you',
'shall we go together tommorow', 'sign language interpreter', 'sit down', 'stand up', 'take care', 'there was traffic jam', 'wait I am thinking',
'what are you doing', 'what is the problem', 'what is todays date', 'what is your age', 'what is your father do', 'what is your job',
'what is your mobile number', 'what is your name', 'whats up', 'when is your interview', 'when we will go', 'where do you stay',
'where is the bathroom', 'where is the police station', 'you are wrong','address','agra','how are you','ahemdabad', 'all', 'april', 'assam', 'august', 'australia', 'badoda', 'banana', 'banaras', 'banglore',
'bihar','bihar','bridge','cat', 'chandigarh', 'chennai', 'christmas', 'church', 'clinic', 'coconut', 'crocodile','dasara',
'deaf', 'december', 'deer', 'delhi', 'dollar', 'duck', 'febuary', 'friday', 'fruits', 'glass', 'grapes', 'gujrat', 'hello',
'hindu', 'hyderabad', 'india', 'january', 'jesus', 'job', 'july', 'july', 'karnataka', 'kerala', 'krishna', 'litre', 'mango',
'may', 'mile', 'monday', 'mumbai', 'museum', 'muslim', 'nagpur', 'october', 'orange', 'pakistan', 'pass', 'police station',
'post office', 'pune', 'punjab', 'rajasthan', 'ram', 'restaurant', 'saturday', 'september', 'shop', 'sleep', 'southafrica',
'story', 'sunday', 'tamil nadu', 'temperature', 'temple', 'thursday', 'toilet', 'tomato', 'town', 'tuesday', 'usa', 'village',
'voice', 'wednesday', 'weight','water','are you all right']
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
# thread = Thread(target = play_music)
# thread.start()
# thread.join()
while True:
print('Listening...')
audio = r.listen(source)
# recognize speech using Sphinx
try:
a=r.recognize_google(audio)
# mixer.init()
# mixer.music.load("bg.mp3")
# mixer.music.play()
print("You said: " + a.lower())
for c in string.punctuation:
a = a.replace(c,"")
if(a.lower()=='goodbye'):
print("Good bye!")
break
elif(a.lower() in taslc_gif):
class ImageLabel(tk.Label):
"""a label that displays images, and plays them if they are gifs"""
def load(self, im):
if isinstance(im, str):
im = Image.open(im)
self.loc = 0
self.frames = []
try:
for i in count(1):
self.frames.append(ImageTk.PhotoImage(im.copy()))
im.seek(i)
except EOFError:
pass
try:
self.delay = im.info['duration']
except:
self.delay = 100
if len(self.frames) == 1:
self.config(image=self.frames[0])
else:
self.next_frame()
def unload(self):
self.config(image=None)
self.frames = None
def next_frame(self):
if self.frames:
self.loc += 1
self.loc %= len(self.frames)
self.config(image=self.frames[self.loc])
self.after(self.delay, self.next_frame)
root = tk.Tk()
lbl = ImageLabel(root)
lbl.pack()
lbl.load(r'/home/psp/Desktop/projects/S-TASLC-Python/TASLC_GIFS/{0}.gif'.format(a.lower()))
root.mainloop()
else:
# os.system("espeak "+a)
# print(a)
# print(len(a))
# break
for i in range(len(a)):
#a[i]=a[i].lower()
if(a[i] in arr):
# print(a[i])
if(a[i] == ' '):
ImageAddress = 'letters_asl/ .jpg'
ImageItself = Image.open(ImageAddress)
ImageNumpyFormat = np.asarray(ImageItself)
plt.imshow(ImageNumpyFormat)
plt.draw()
plt.pause(0.8) # pause how many seconds
#plt.close()
else:
ImageAddress = 'letters_asl/'+a[i]+'.jpg'
ImageItself = Image.open(ImageAddress)
ImageNumpyFormat = np.asarray(ImageItself)
plt.imshow(ImageNumpyFormat)
plt.draw()
plt.pause(0.8) # pause how many seconds
#plt.close()
else:
continue
except:
print("Could not listen probably audio is too low to listen")
plt.close()
#func()
while 1:
image = "logo.jpg"
msg="S - TASLC - Speech to American Sign Language Converter"
choices = ["Laptop Live Conversation mode","Close","Convert Recorded Voice", "RAS-PI Live Conversation mode"]
reply = buttonbox(msg,image=image,choices=choices)
if reply ==choices[0]:
func()
if reply == choices[1]:
quit()
if reply==choices[2]:
if(platform.system() == 'Windows'):
os.system("python recorded.py")
else:
os.system("python3 recorded.py")
break
if reply==choices[3]:
if(platform.system() == 'Windows'):
os.system("python rasp_main.py")
else:
os.system("python3 rasp_main.py")
quit()