천현우

ttp: ready to TTP

......@@ -1366,7 +1366,7 @@ function transcribeText() {
audioStream.getAudioTracks()[0].stop();
rec.exportWAV(uploadSoundData);
}
let px = 0;
let input_line = ""
function uploadSoundData(blob) {
let filename = new Date().toISOString();
......@@ -1374,13 +1374,28 @@ function uploadSoundData(blob) {
let formData = new FormData();
xhr.onload = function(e) {
if(this.readyState === 4) {
document.getElementById("output").innerHTML += `${cnt++}: ${JSON.parse(e.target.responseText)}<br><br>`;
input_line += 'print("hello")\n';
sourceEditor.setValue(input_line);
let transcript = JSON.parse(e.target.responseText)
document.getElementById("output").innerHTML += `${cnt++}: ${transcript}<br><br>`;
uploadTranscriptData(transcript);
}
};
formData.append("audio_data", blob, filename);
xhr.open("POST", "/upload_sound", true);
xhr.send(formData);
}
function uploadTranscriptData(txt) {
let request = new XMLHttpRequest();
let form = new FormData();
request.onload = function(e) {
if(this.readyState === 4) {
console.log(e.target.responseText)
input_line += e.target.responseText + '\n';
console.log(input_line)
sourceEditor.setValue(input_line);
}
};
form.append("transcript_data", txt);
request.open("POST", "/ttp", true);
request.send(form);
}
\ No newline at end of file
......
......@@ -62,6 +62,12 @@ app.post('/upload_sound', upload.any(), async (req, res) => {
console.log("Text transcription: " + transcription);
res.status(200).send(transcription);
});
app.post('/ttp', upload.any(), async (req, res) => {
console.log("Getting python code..");
let python_code = req.body.transcript_data;
console.log("Pyton code: " + python_code);
res.status(200).send(python_code);
});
app.listen(port, () => {
console.log(`Express server listening on port: ${port}...`);
});
\ No newline at end of file
......