188 lines
6.5 KiB
Python
188 lines
6.5 KiB
Python
import tkinter as tk
|
|
from tkinter import Menu, messagebox, filedialog
|
|
import cv2
|
|
from PIL import Image, ImageTk
|
|
import os
|
|
import speech_recognition as sr
|
|
import pygame # Importando o pygame para reprodução de áudio
|
|
|
|
def validar_login():
|
|
user = userdig.get()
|
|
password = passdig.get()
|
|
if user == "admin" and password == "12345":
|
|
login.destroy()
|
|
abre_janela_principal()
|
|
else:
|
|
messagebox.showerror("Erro", "Usuário ou senha incorretos!")
|
|
|
|
is_playing = False
|
|
video_position = 0
|
|
cap = None
|
|
audio_recognizer = sr.Recognizer() # Instância do reconhecedor de áudio
|
|
|
|
def abre_janela_principal():
|
|
janela_principal = tk.Tk()
|
|
janela_principal.title("Kl3z - PJ- AI")
|
|
janela_principal.geometry('800x600') # Aumentando a altura para acomodar o campo de texto
|
|
|
|
menu_bar = Menu(janela_principal)
|
|
carregar_menu = Menu(menu_bar, tearoff=0)
|
|
carregar_menu.add_command(label="Carregar vídeo", command=carregar_video)
|
|
carregar_menu.add_command(label="Carregar áudio", command=carregar_audio)
|
|
carregar_menu.add_separator()
|
|
carregar_menu.add_command(label="Sair", command=janela_principal.destroy)
|
|
menu_bar.add_cascade(label="Carregar informação", menu=carregar_menu)
|
|
|
|
Relatorios = Menu(menu_bar, tearoff=0)
|
|
Relatorios.add_command(label="Inserir")
|
|
menu_bar.add_cascade(label="Relatórios", menu=Relatorios)
|
|
|
|
Opcoes = Menu(menu_bar, tearoff=0)
|
|
Opcoes.add_command(label="Definições")
|
|
Opcoes.add_command(label="Definições2")
|
|
menu_bar.add_cascade(label="Opções", menu=Opcoes)
|
|
|
|
janela_principal.config(menu=menu_bar)
|
|
|
|
global video
|
|
video = tk.Label(janela_principal, bg='black')
|
|
video.pack(expand=True, fill=tk.BOTH)
|
|
video.place(x=50, y=50, width=500, height=300)
|
|
|
|
control_frame = tk.Frame(janela_principal)
|
|
control_frame.pack(pady=20)
|
|
|
|
play_button = tk.Button(control_frame, text="Play", command=play_video)
|
|
play_button.grid(row=0, column=0, padx=5)
|
|
|
|
pause_button = tk.Button(control_frame, text="Pause", command=pause_video)
|
|
pause_button.grid(row=0, column=1, padx=5)
|
|
|
|
stop_button = tk.Button(control_frame, text="Stop", command=stop_video)
|
|
stop_button.grid(row=0, column=2, padx=5)
|
|
|
|
forward_button = tk.Button(control_frame, text="Forward", command=forward_video)
|
|
forward_button.grid(row=0, column=3, padx=5)
|
|
|
|
backward_button = tk.Button(control_frame, text="Backward", command=backward_video)
|
|
backward_button.grid(row=0, column=4, padx=5)
|
|
|
|
var1 = tk.BooleanVar()
|
|
var2 = tk.BooleanVar()
|
|
var3 = tk.BooleanVar()
|
|
|
|
check_button1 = tk.Checkbutton(control_frame, text="Análises de expressões", variable=var1)
|
|
check_button1.grid(row=0, column=5, padx=10)
|
|
|
|
check_button2 = tk.Checkbutton(control_frame, text="Análises de texto", variable=var2)
|
|
check_button2.grid(row=0, column=6, padx=10)
|
|
|
|
check_button3 = tk.Checkbutton(control_frame, text="Conversão de áudio para texto", variable=var3)
|
|
check_button3.grid(row=0, column=7, padx=10)
|
|
|
|
# Campo de texto para exibir o texto reconhecido
|
|
global text_box
|
|
text_box = tk.Text(janela_principal, wrap=tk.WORD, height=10)
|
|
text_box.pack(expand=True, fill=tk.BOTH, padx=10, pady=10)
|
|
|
|
janela_principal.mainloop()
|
|
|
|
def carregar_video():
|
|
global video_caminho, cap, is_playing
|
|
video_caminho = filedialog.askopenfilename(title="Selecione um vídeo", filetypes=[("Vídeos", "*.mp4;*.avi;*.mov")])
|
|
if video_caminho:
|
|
cap = cv2.VideoCapture(video_caminho)
|
|
is_playing = True
|
|
update_frame()
|
|
# Iniciar reprodução do áudio
|
|
tocar_audio(video_caminho) # Tocar áudio aqui
|
|
# Iniciar reconhecimento de áudio
|
|
processar_audio(video_caminho)
|
|
|
|
def update_frame():
|
|
global is_playing, cap
|
|
if cap is not None and is_playing:
|
|
ret, frame = cap.read()
|
|
if ret:
|
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
frame = cv2.resize(frame, (500, 300))
|
|
img = Image.fromarray(frame)
|
|
imgtk = ImageTk.PhotoImage(image=img)
|
|
video.imgtk = imgtk
|
|
video.configure(image=imgtk)
|
|
video.after(20, update_frame)
|
|
else:
|
|
cap.release()
|
|
|
|
def play_video():
|
|
global is_playing
|
|
is_playing = True
|
|
update_frame()
|
|
|
|
def pause_video():
|
|
global is_playing
|
|
is_playing = False
|
|
|
|
def stop_video():
|
|
global is_playing, cap
|
|
is_playing = False
|
|
cap.release()
|
|
video.configure(image='')
|
|
text_box.delete('1.0', tk.END) # Limpa o campo de texto
|
|
pygame.mixer.stop() # Para a reprodução do áudio
|
|
|
|
def forward_video():
|
|
global cap
|
|
if cap is not None:
|
|
current_position = cap.get(cv2.CAP_PROP_POS_MSEC)
|
|
cap.set(cv2.CAP_PROP_POS_MSEC, current_position + 5000)
|
|
|
|
def backward_video():
|
|
global cap
|
|
if cap is not None:
|
|
current_position = cap.get(cv2.CAP_PROP_POS_MSEC)
|
|
cap.set(cv2.CAP_PROP_POS_MSEC, max(0, current_position - 5000))
|
|
|
|
def tocar_audio(video_caminho):
|
|
# Inicializar o pygame mixer
|
|
pygame.mixer.init()
|
|
pygame.mixer.music.load(video_caminho)
|
|
pygame.mixer.music.play() # Reproduzir o áudio do vídeo
|
|
|
|
def processar_audio(video_caminho):
|
|
# Extrair áudio do vídeo
|
|
audio_file = "temp_audio.wav"
|
|
os.system(f"ffmpeg -i {video_caminho} -ac 1 -ar 16000 {audio_file}") # Extraindo áudio usando ffmpeg
|
|
|
|
# Reconhecimento de fala
|
|
with sr.AudioFile(audio_file) as source:
|
|
audio_data = audio_recognizer.record(source)
|
|
try:
|
|
texto = audio_recognizer.recognize_google(audio_data, language='pt-BR') # Reconhecendo o áudio
|
|
text_box.insert(tk.END, texto + "\n") # Adiciona o texto reconhecido ao campo de texto
|
|
except sr.UnknownValueError:
|
|
messagebox.showerror("Erro", "Não consegui entender o áudio.")
|
|
except sr.RequestError as e:
|
|
messagebox.showerror("Erro", f"Erro na requisição: {e}")
|
|
|
|
def carregar_audio():
|
|
audio = filedialog.askopenfilename(title="Selecione um ficheiro áudio", filetypes=[("Áudios", "*.mp3;*.wav;*.ogg")])
|
|
if audio:
|
|
os.startfile(audio)
|
|
|
|
login = tk.Tk()
|
|
login.title("Login")
|
|
login.geometry("300x200")
|
|
label_usuario = tk.Label(login, text="Usuário:")
|
|
label_usuario.pack(pady=5)
|
|
userdig = tk.Entry(login)
|
|
userdig.pack(pady=5)
|
|
label_senha = tk.Label(login, text="Senha:")
|
|
label_senha.pack(pady=5)
|
|
passdig = tk.Entry(login, show="*")
|
|
passdig.pack(pady=5)
|
|
botao_login = tk.Button(login, text="Login", command=validar_login)
|
|
botao_login.pack(pady=20)
|
|
login.mainloop()
|
|
|