-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoiceRecruit-Pro.py
143 lines (111 loc) · 6.21 KB
/
VoiceRecruit-Pro.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""------------------------------ VoiceRecruit Pro --------------------------- """
"""------------------this code is when interviewer ask any question, this program using chatgpt, retrieve answer and
display in a transparent tkinter window. with that this program, record the applicants answer and review it---------"""
import azure.cognitiveservices.speech as speechsdk
from tkinter import *
from threading import Thread
import requests
exit_flag = False
def on_close():
global exit_flag
exit_flag = True
root.destroy()
root = Tk()
root.wm_attributes('-transparentcolor', '#abcdef')
root.protocol("WM_DELETE_WINDOW", on_close)
root.config(bg='#abcdef')
# Set the window size and position
window_width = 500
window_height = root.winfo_screenheight() # Set the height to match the screen height
x_coordinate = root.winfo_screenwidth() - window_width # Set the x-coordinate to place it on the right
root.geometry(f'{window_width}x{window_height}+{x_coordinate}+0')
# due to this line, the "root" window will stay on top of all other opened applicaation
root.wm_attributes('-topmost', 1)
# Function to create a label with its own background color and a delete button
def messages(text,places,bg_color):
#bg_color="lightblue"
label_frame = Frame(root, bg=bg_color)
label_frame.pack(pady=5, padx=10, anchor=places)
label = Label(label_frame, text=text, bg=bg_color,wraplength=450,justify="left",font=("Times New Roman", 13) )
label.pack(side=LEFT, padx=5)
def generate_completion(prompt):
try:
response = requests.post(
url="https://api.binjie.fun/api/generateStream",
headers={
"origin": "https://chat.jinshutuan.com",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36",
},
json={
"prompt": prompt,
"system": "Always talk in English.",
"withoutContext": True,
"stream": False,
},
)
return response.text
except:
return "check your connection"
def is_question(s):
interrogatives = ["Am", "How", "Were","Weren’t","Are", "How Come", "What","How Far","Aren’t", "How Long",
"Can", "How Many", "What Kind","How Much", "What Time","Can’t", "How Often", "When","Could", "How Old",
"Couldn’t", "Huh", "Where","Did", "Is", "Which","Didn’t", "Isn’t","Do", "May", "Who","Mayn’t","Might", "Whom",
"Mightn’t", "Whose","Mustn’t","Neither", "Why","Needn’t","Oughtn’t", "Why Don’t","Will","Should", "Won’t",
"Shouldn’t", "Would","Was","Wasn’t", "Wouldn’t", "tell us", "tell me","introduce"]
return s.endswith('?') or any(s.lower().startswith(i) for i in interrogatives)
def recognize_from_microphone():
sk="5c8a7b93496949df9bd149b9af6a566b"
sr="centralindia"
# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
speech_config = speechsdk.SpeechConfig(subscription=sk, region=sr)
speech_config.speech_recognition_language="en-US"
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
print("Speak into your microphone.")
while not exit_flag:
speech_recognition_result = speech_recognizer.recognize_once_async().get()
try:
if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
if is_question(speech_recognition_result.text): #if it is a question or not
question1=speech_recognition_result.text
messages(question1,"e","lightgreen")
with open("history_and_review_of_interview.txt","a") as file :
file.write("__________________INTERVIEWER ASKED: __________________\n ")
file.write(speech_recognition_result.text)
file.write("\n \n")
file.close()
question = "interviewer is asking me " + speech_recognition_result.text + ". answer this question as if you are applicant"
interview_answer= generate_completion(question)
print("\n")
print(interview_answer)
messages(interview_answer,"w","lightblue")
print("\n")
# to register chatgpt answer
with open("history_and_review_of_interview.txt","a") as file :
file.write("__________________CHATGPT ANSWER: __________________ \n ")
file.writelines(interview_answer)
file.write("\n \n")
file.close()
else: # to register applicant answer
with open("history_and_review_of_interview.txt","a") as file :
file.write("__________________YOU ANSWERED: __________________\n ")
file.write(speech_recognition_result.text)
file.write("\n \n")
file.close()
if(interview_answer != speech_recognition_result.text):
commenting = "interviewer asked me '" +question1+ "' \n and i answered it as '" + speech_recognition_result.text + "'\n review my answer"
comments = generate_completion(commenting)
with open("history_and_review_of_interview.txt","a") as file :
file.write("__________________COMMENT ON IT: __________________\n ")
file.write(comments)
file.write("\n \n \n \n ")
file.close()
except:
pass
def start_recognition_thread():
global recognition_thread
recognition_thread = Thread(target=recognize_from_microphone)
recognition_thread.start()
# Start the recognition thread
start_recognition_thread()
root.mainloop()