File size: 1,711 Bytes
47d6504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import tkinter as tk
from tkinter import messagebox
import asyncio
from ai_system.ai_core import AICore
import speech_recognition as sr
import pyttsx3

class AIApplication(tk.Tk):
    def __init__(self):
        super().__init__()
        self.ai = AICore()
        self.speech_recognizer = sr.Recognizer()
        self.title("Falcondette")
        self.geometry("1200x700")
        self._init_ui()

    def _init_ui(self):
        self.query_entry = tk.Entry(self, width=100)
        self.query_entry.pack(pady=10)
        tk.Button(self, text="Submit", command=self._submit_query).pack()
        self.response_area = tk.Text(self, width=120, height=30)
        self.response_area.pack(pady=10)
        tk.Button(self, text="Voice Input", command=self._listen_voice_command).pack()

    def _submit_query(self):
        query = self.query_entry.get()
        if not query:
            return
        async def process():
            result = await self.ai.generate_response(query, 1)
            self.response_area.insert(tk.END, f"Response: {result['response']}
")
        asyncio.run_coroutine_threadsafe(process(), asyncio.get_event_loop())

    def _listen_voice_command(self):
        with sr.Microphone() as source:
            print("Listening for voice command...")
            audio = self.speech_recognizer.listen(source)
            try:
                command = self.speech_recognizer.recognize_google(audio)
                self.query_entry.delete(0, tk.END)
                self.query_entry.insert(0, command)
                self._submit_query()
            except:
                print("Voice command not recognized.")

if __name__ == "__main__":
    app = AIApplication()
    app.mainloop()