Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,9 @@ from gtts import gTTS
|
|
5 |
import os
|
6 |
import sqlite3
|
7 |
from sklearn.ensemble import IsolationForest
|
|
|
|
|
|
|
8 |
|
9 |
# Initialize Database
|
10 |
conn = sqlite3.connect('preferences.db')
|
@@ -13,6 +16,23 @@ cursor.execute('''CREATE TABLE IF NOT EXISTS preferences (id INTEGER PRIMARY KEY
|
|
13 |
cursor.execute('''CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY, command TEXT, response TEXT)''')
|
14 |
conn.commit()
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Anomaly Detection Model
|
17 |
anomaly_model = IsolationForest(contamination=0.1)
|
18 |
data = []
|
|
|
5 |
import os
|
6 |
import sqlite3
|
7 |
from sklearn.ensemble import IsolationForest
|
8 |
+
import sounddevice as sd
|
9 |
+
import numpy as np
|
10 |
+
import speech_recognition as sr
|
11 |
|
12 |
# Initialize Database
|
13 |
conn = sqlite3.connect('preferences.db')
|
|
|
16 |
cursor.execute('''CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY, command TEXT, response TEXT)''')
|
17 |
conn.commit()
|
18 |
|
19 |
+
def record_audio():
|
20 |
+
samplerate = 16000
|
21 |
+
duration = 5 # seconds
|
22 |
+
recording = sd.rec(int(samplerate * duration), samplerate=samplerate, channels=1, dtype='float64')
|
23 |
+
sd.wait() # Wait until recording is finished
|
24 |
+
return np.squeeze(recording)
|
25 |
+
|
26 |
+
def recognize_audio():
|
27 |
+
r = sr.Recognizer()
|
28 |
+
audio = record_audio()
|
29 |
+
with sr.AudioData(audio.tobytes(), 16000, 2) as source:
|
30 |
+
try:
|
31 |
+
command = r.recognize_google(source)
|
32 |
+
return command
|
33 |
+
except sr.UnknownValueError:
|
34 |
+
return "Sorry, I could not understand the audio."
|
35 |
+
|
36 |
# Anomaly Detection Model
|
37 |
anomaly_model = IsolationForest(contamination=0.1)
|
38 |
data = []
|