-
Notifications
You must be signed in to change notification settings - Fork 2
/
gui1.py
202 lines (159 loc) · 7.9 KB
/
gui1.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import tkinter as tk
from tkinter import ttk
from tkVideoPlayer import TkinterVideo
from pathlib import Path
import keywords
from translate import Translator
import speech_recognition as sr
import threading
import pandas as pd
import google.generativeai as genai
from IPython.display import Markdown
class VideoPlayerApp:
def __init__(self, root):
self.root = root
self.root.title("Sign Language Interpreter")
self.root.geometry("800x600") # Set the initial window size
# Placeholder image
self.placeholder_image = tk.PhotoImage(
file="F:\Automatic-Indian-Sign-Language-Translator-ISL-master\SIGN LANGUAGE INTERPRETER\capa-blogpost-cultura-surda.png"
) # Replace with your placeholder image path
self.image_label = tk.Label(root, image=self.placeholder_image)
self.image_label.pack(pady=10)
# Video player frame
self.video_frame = ttk.Frame(root)
self.video_frame.pack(expand=True, fill="both")
# Text box
self.entry_var = tk.StringVar()
self.text_entry = ttk.Entry(root, textvariable=self.entry_var,width=50)
self.text_entry.pack(pady=10)
# Text widget to display the entered text
self.text_display = tk.Text(root, state="disabled", wrap="word", height=3, font=("Helvetica", 14, "bold"))
self.text_display.pack(pady=5)
self.text_display.tag_config('available', foreground='green')
self.text_display.tag_config('unavailable', foreground='red')
# Create a frame for buttons
self.button_frame = ttk.Frame(root)
self.button_frame.pack(pady=10)
# Button to play video
play_button = ttk.Button(self.button_frame, text="Give Sign Language", command=self.play_video)
play_button.pack(side="left", padx=5)
# Button to translate from Hindi to English
translate_button = ttk.Button(self.button_frame, text="give Hindi Input", command=self.translate_to_english)
translate_button.pack(side="left", padx=5)
# Button to input voice in English
voice_button = ttk.Button(self.button_frame, text="Input Voice in English", command=self.input_voice)
voice_button.pack(side="left", padx=5)
self.video_queue = []
self.current_player = None
def play_video(self):
# Get the video filename based on the entered text
text = self.entry_var.get()
GOOGLE_API_KEY = "AIzaSyCTOwhmkEKKDjLvDO6uogNuaBfOUWdiANI"
genai.configure(api_key=GOOGLE_API_KEY)
input_text = f"""Give an abridged version of the given text'''{text} ''' """
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(input_text)
text = response.text.lower()
text=keywords.remove_punctuation(text)
input_words = text.split(' ')
video_list = keywords.find_keywords(text)
self.video_queue.clear()
for video in video_list:
video_filename = self.get_video_filename(video)
if video_filename:
self.video_queue.append((video_filename, video))
self.text_display.config(state='normal')
self.text_display.delete(1.0, tk.END)
for word in input_words:
if word in video_list:
self.text_display.insert(tk.END, f"{word} ", 'available')
else:
self.text_display.insert(tk.END, f"{word} ", 'unavailable')
self.text_display.config(state='disabled')
self.play_next_video()
def get_video_filename(self, text):
# Replace this function with your logic to get the video filename based on the entered text
# For example, you might query a database to get the filename
# Here, we'll assume the videos are stored in the "videos" folder with the same name as the entered text
video_folder = Path(
"F:\Automatic-Indian-Sign-Language-Translator-ISL-master\SIGN LANGUAGE INTERPRETER\mp4_dataset")
video_filename = video_folder / (text + ".mp4")
if video_filename.is_file():
return str(video_filename)
else:
print(f"Video not found for text: {text}")
return None
def play_next_video(self):
if self.video_queue:
# Get the next video filename and associated text from the queue
video_filename, video_text = self.video_queue.pop(0)
# Destroy the existing video player if it exists
if self.current_player:
self.current_player.destroy()
# Load and play the video using tkVideoPlayer
self.image_label.pack_forget()
# Load and play the video using tkVideoPlayer in the video frame
player = TkinterVideo(master=self.video_frame, scaled=True, width=800, height=600)
player.load(r"{}".format(video_filename))
player.pack(expand=True, fill="both")
# Set a callback for when the video finishes
player.bind('<<Ended>>', lambda event: self.play_next_video())
player.play()
# Update the text widget with the entered text
# self.text_display.delete(1.0, tk.END)
# self.text_display.insert(tk.END, f"Text: {video_text}", "green")
self.current_player = player
# Decrease the delay between videos (adjust the value in milliseconds)
self.root.after(2000, self.play_next_video) # Set the delay here (in milliseconds)
else:
print("No more videos in the queue.")
def translate_to_english(self):
# Translate the entered Hindi text to English
hindi_text = self.entry_var.get()
translator = Translator(to_lang="en", from_lang="hi")
english_text = translator.translate(hindi_text)
# Update the entry field with the translated text
self.entry_var.set(english_text)
# Play the sign language video for the translated text
self.play_video_for_text(english_text)
def play_translated_video(self):
# Play sign language video based on translated English text
english_text = self.entry_var.get()
self.play_video_for_text(english_text)
def input_voice(self):
# Define a separate thread for voice recognition
voice_thread = threading.Thread(target=self.perform_voice_recognition)
# Start the thread
voice_thread.start()
def perform_voice_recognition(self):
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Speak something...")
audio = recognizer.listen(source)
try:
# Recognize the voice input
english_text = recognizer.recognize_google(audio)
print(f"You said: {english_text}")
# Set the recognized text in the entry field
self.entry_var.set(english_text)
# Play the sign language video for the recognized English text
self.play_video_for_text(english_text)
except sr.UnknownValueError:
print("Sorry, could not understand audio.")
except sr.RequestError as e:
print(f"Error with the speech recognition service; {e}")
def play_video_for_text(self, text):
# Play the sign language video for the given English text
video_list = keywords.find_keywords(text)
self.video_queue.clear()
for video in video_list:
video_filename = self.get_video_filename(video)
if video_filename:
self.video_queue.append((video_filename, video))
# Highlight words in the text widget based on their presence in the video_list
self.play_next_video()
if __name__ == "__main__":
root = tk.Tk()
app = VideoPlayerApp(root)
root.mainloop()