천현우

ttp: ready to TTP

...@@ -1366,7 +1366,7 @@ function transcribeText() { ...@@ -1366,7 +1366,7 @@ function transcribeText() {
1366 audioStream.getAudioTracks()[0].stop(); 1366 audioStream.getAudioTracks()[0].stop();
1367 rec.exportWAV(uploadSoundData); 1367 rec.exportWAV(uploadSoundData);
1368 } 1368 }
1369 -let px = 0; 1369 +
1370 let input_line = "" 1370 let input_line = ""
1371 function uploadSoundData(blob) { 1371 function uploadSoundData(blob) {
1372 let filename = new Date().toISOString(); 1372 let filename = new Date().toISOString();
...@@ -1374,13 +1374,28 @@ function uploadSoundData(blob) { ...@@ -1374,13 +1374,28 @@ function uploadSoundData(blob) {
1374 let formData = new FormData(); 1374 let formData = new FormData();
1375 xhr.onload = function(e) { 1375 xhr.onload = function(e) {
1376 if(this.readyState === 4) { 1376 if(this.readyState === 4) {
1377 - 1377 + let transcript = JSON.parse(e.target.responseText)
1378 - document.getElementById("output").innerHTML += `${cnt++}: ${JSON.parse(e.target.responseText)}<br><br>`; 1378 + document.getElementById("output").innerHTML += `${cnt++}: ${transcript}<br><br>`;
1379 - input_line += 'print("hello")\n'; 1379 + uploadTranscriptData(transcript);
1380 - sourceEditor.setValue(input_line);
1381 } 1380 }
1382 }; 1381 };
1383 formData.append("audio_data", blob, filename); 1382 formData.append("audio_data", blob, filename);
1384 xhr.open("POST", "/upload_sound", true); 1383 xhr.open("POST", "/upload_sound", true);
1385 xhr.send(formData); 1384 xhr.send(formData);
1385 +}
1386 +
1387 +function uploadTranscriptData(txt) {
1388 + let request = new XMLHttpRequest();
1389 + let form = new FormData();
1390 + request.onload = function(e) {
1391 + if(this.readyState === 4) {
1392 + console.log(e.target.responseText)
1393 + input_line += e.target.responseText + '\n';
1394 + console.log(input_line)
1395 + sourceEditor.setValue(input_line);
1396 + }
1397 + };
1398 + form.append("transcript_data", txt);
1399 + request.open("POST", "/ttp", true);
1400 + request.send(form);
1386 } 1401 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -62,6 +62,12 @@ app.post('/upload_sound', upload.any(), async (req, res) => { ...@@ -62,6 +62,12 @@ app.post('/upload_sound', upload.any(), async (req, res) => {
62 console.log("Text transcription: " + transcription); 62 console.log("Text transcription: " + transcription);
63 res.status(200).send(transcription); 63 res.status(200).send(transcription);
64 }); 64 });
65 +app.post('/ttp', upload.any(), async (req, res) => {
66 + console.log("Getting python code..");
67 + let python_code = req.body.transcript_data;
68 + console.log("Pyton code: " + python_code);
69 + res.status(200).send(python_code);
70 +});
65 app.listen(port, () => { 71 app.listen(port, () => {
66 console.log(`Express server listening on port: ${port}...`); 72 console.log(`Express server listening on port: ${port}...`);
67 }); 73 });
...\ No newline at end of file ...\ No newline at end of file
......