-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
97 lines (81 loc) · 2.45 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
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
# importing the libraries
import os
from this import d
import psycopg2
import PySimpleGUI as sg
import time
import pyaudio
import cohere
from cohere.classify import Example
import ai.process as pr
from db.env import auth_key
FRAMES_PER_BUFFER = 3200
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000
api_key = 'KZyl9VEB48EaDmsfJFOA4mMS53AsYrsBCZTSK7vg'
p_obj = pyaudio.PyAudio()
co = cohere.Client(f'{api_key}')
conn = psycopg2.connect(auth_key)
# layout code for the GUI itself
layout = [
[
sg.Text('words',
font=('Helvetica', 20),
justification='center',
key='text'
)
],
[
sg.Text("Choose a folder: "),
sg.Input(key="-IN2-" ,change_submits=True),
sg.FileBrowse(key="-IN-")
],
[ sg.Button("Submit") ],
[
sg.Button('Start', button_color=('white', '#007339')),
sg.Exit('Close', button_color=('white', '#001480')),
],
]
# creating the window object
window = sg.Window('Window Title', layout, auto_size_buttons=False, grab_anywhere=True)
# variables for the event loop
current_time = 0
start_time = int(round(time.time() * 100))
running = False
# event loop
while True:
# window reading values
event, values = window.read(timeout=100)
# breaking the loop
if event in (sg.WIN_CLOSED, 'Exit') or event == sg.WIN_CLOSED or event == 'Exit' or event == 'Close': # ALWAYS give a way out of program
break
# variables inside the loop
if not running and event == 'Start':
running = True
start_time = int(round(time.time() * 100))
# live processing started
if running:
t = int(round(time.time() * 100))
current_time = t - start_time
fname = pr.record_segment(20, p=p_obj, idx=0)
dict_result = pr.transcribe_segment(fname)
dict_classifciation = pr.predict_danger(dict_result['phrases'], co)
if os.path.exists(fname):
os.remove(fname)
pr.enter_into_db(conn, dict_result, dict_classifciation)
print(dict_classifciation)
# submitting a .wav file
if event == "Submit":
print(values["-IN-"])
running = False
current_time = 0
# add the mp3 processing code below
pass
# updating the values interface
window['text'].update(
'{:02d}:{:02d}.{:02d}'.format((current_time // 100) // 60,
(current_time // 100) % 60,
current_time % 100)
)
window.close()