MCPcopy Create free account
hub / github.com/NsLearning/LangHelper / RequestHandler

Class RequestHandler

LangHelper/main.py:121–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119 return False
120
121class RequestHandler(BaseHTTPRequestHandler):
122 def do_OPTIONS(self):
123 self.send_response(200, "ok")
124 self.send_header('Access-Control-Allow-Credentials', 'true')
125 self.send_header('Access-Control-Allow-Origin', 'https://chat.openai.com')
126 self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
127 self.send_header("Access-Control-Allow-Headers", "X-Requested-With, Content-type")
128 self.send_header("Access-Control-Max-Age","86400")
129
130 def do_POST(self):
131 global playlist,pendinglist,SkipSpeaking,RecWorking,recorder,SttText,client,region_cnt,seaker_cnt,Specify_One_message,Specify_Speaker
132 global subprocess_number,iflytek_rec_appid,iflytek_rec_apikey,iflytek_assess_appid,iflytek_assess_appsecret,iflytek_assess_apikey,ss_assess_appkey,ss_assess_secretkey
133 global complete_init
134 if self.path == "/init":
135 content_length = int(self.headers['Content-Length'])
136 body = self.rfile.read(content_length)
137 data = json.loads(body.decode('utf-8'))
138 subprocess_number = int(data['subprocess_number'])
139
140 iflytek_rec_appid = data['iflytek_rec_appid']
141 iflytek_rec_apikey = data['iflytek_rec_apikey']
142 if client:
143 client.app_id = data['iflytek_rec_appid']
144 client.api_key= data['iflytek_rec_apikey']
145
146 iflytek_assess_appid = data['iflytek_assess_appid']
147 iflytek_assess_appsecret = data['iflytek_assess_appsecret']
148 iflytek_assess_apikey = data['iflytek_assess_apikey']
149 if assess:
150 assess.APPID = data['iflytek_assess_appid']
151 assess.APISecret = data['iflytek_assess_appsecret']
152 assess.APIKey = data['iflytek_assess_apikey']
153
154 ss_assess_appkey = data['ss_assess_appkey']
155 ss_assess_secretkey = data['ss_assess_secretkey']
156 if assess2:
157 assess2.appKey = data['ss_assess_appkey']
158 assess2.secretKey = data['ss_assess_secretkey']
159
160 response = {'message': 'setting init sucessfully',"data":""}
161 complete_init = True
162 elif self.path == "/play":
163 content_length = int(self.headers['Content-Length'])
164 body = self.rfile.read(content_length)
165 data = json.loads(body.decode('utf-8'))
166 text = data['text']
167 speaker = data['speaker']
168 response = {'message': 'ChatGPT said: '+text,"data":""}
169 text = TextIsSuitable(text)
170
171 now = datetime.datetime.now()
172 time_str = now.strftime("%H_%M_%S_%f")
173 file_path = "./Resource/read/"+ time_str +".wav"
174
175 if (len(playlist)) <=15 and (text.strip() != ''):
176 playlist.append([text,file_path,speaker])
177
178 elif self.path == "/Skip":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected