-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (36 loc) · 1.07 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
import os
import time
import pickle
import librosa
import librosa.display
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
import telepot
token = "your_token" # telegram token
receiver_id = receiver_id # telegram receiver id
bot = telepot.Bot(token)
import warnings
warnings.filterwarnings('ignore')
start_time = time.time()
while True:
# Record the audio sample
os.system("arecord -d 5 -r 48000 -t wav test.wav")
file = "test.wav"
signal , sr = librosa.load(file)
# MFCC
mfccs = librosa.feature.mfcc(signal, n_mfcc=13, sr=sr)
# Scaling
scaler = StandardScaler()
X_scaled = scaler.fit_transform(mfccs)
# PCA
pca = PCA(n_components = 1)
X_pca = pca.fit_transform(X_scaled)
MFCCS = X_pca.transpose()
# Saving model
model = pickle.load(open('model.pkl', 'rb'))
result = model.predict(MFCCS)
print(result[0])
# Condition for sending message
if (result[0] == 0):
bot.sendMessage(receiver_id, "WATER LEAKAGE DETECTED!")
time.sleep(60.0 - ((time.time() - start_time) % 60.0))