천현우

Merge branch 'TTP-manual' into 'main'

Ttp manual



See merge request !10
1.
2.
3.
\ No newline at end of file
'기본 함수 사용',
'인풋', -> input()
'프린트', -> print(
'섬', -> sum(
'맥스', -> max(
'민' -> min(
'렌' -> len(
'수식' -> +, -, *, /, 몫, 나머지
=> 뒤에 나오는걸 parameter로 넣어야 함
'변수 선언' -> 문자, 숫자, 리스트, 함수
는 -> =
첫번째 - -> =
리스트 -> c는 빈 리스트-> c = []
c는 숫자 리스트 1 2 3 4 5 6 -> c = [1, 2, 3, 4, 5, 6]
c는 문자 리스트 a b c d -> c = ['a', 'b', 'c', 'd']
'반복문 선언'
for a in range -> for a in range(
for i in (li):
while -> while(
'조건문 선언'
if -> if(
else if -> elif(
else -> else:
'함수 선언'
aaa -> def aaa(
'완료' -> tab 빼기
'파라미터 선언'
a b c -> a, b, c):
'논리 식 선언'
1: A는 B 와 같다 -> A == B):
2: A는 B 보다 크다 -> A > B):
5: A는 B 보다 크거나 같다 -> A >= B):
6: A는 B 보다 작거나 같다 -> A <= B):
7: A는 B 보다 작다 -> A < B):
......
......@@ -1368,15 +1368,23 @@ function transcribeText() {
}
let input_line = ""
function uploadSoundData(blob) {
let tab = '';
let before_val = '';
let chk = 1;
let tmp = [];
async function uploadSoundData(blob) {
let filename = new Date().toISOString();
let xhr = new XMLHttpRequest();
let formData = new FormData();
xhr.onload = function(e) {
if(this.readyState === 4) {
let transcript = JSON.parse(e.target.responseText)
let transcript = JSON.parse(e.target.responseText) + '';
document.getElementById("output").innerHTML += `${cnt++}: ${transcript}<br><br>`;
uploadTranscriptData(transcript);
tmp = transcript.split(' ');
if (tmp[0] == '종료') tab = tab.slice(1);
else{
uploadTranscriptData(tab, transcript);
}
}
};
formData.append("audio_data", blob, filename);
......@@ -1384,18 +1392,21 @@ function uploadSoundData(blob) {
xhr.send(formData);
}
function uploadTranscriptData(txt) {
async function uploadTranscriptData(tabs, 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)
input_line += e.target.responseText;
sourceEditor.setValue(input_line);
if ((tmp[0] == '함수' || tmp[0] == '반복문' || tmp[0] == '조건문') && e.target.responseText != '') {
tab += '\t';
}
}
};
form.append("transcript_data", txt);
form.append("tabs", tabs);
request.open("POST", "/ttp", true);
request.send(form);
}
\ No newline at end of file
......
......@@ -20,7 +20,14 @@ async function testGoogleTextToSpeech(audioBuffer) {
'$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
'$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크다',
'$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작다',
'for OOV_CLASS_ALPHA_SEQUENCE in range $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
'$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 와 같다',
'$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작거나 같다',
'$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크거나 같다',
'반복문 선언 for $OOV_CLASS_ALPHA_SEQUENCE in range',
'반복문 선언 for $OOV_CLASS_ALPHA_SEQUENCE in',
'$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 빈 리스트',
'$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 숫자 리스트 $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
'$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 문자 리스트 $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
'if',
'이프',
'else if',
......@@ -30,12 +37,24 @@ async function testGoogleTextToSpeech(audioBuffer) {
'while',
'와일',
'함수',
'파라미터',
'파라미터 선언',
'parameter',
'변수 선언',
'함수 선언',
'반복문 선언',
'조건문 선언'
'반복문 선언 while',
'반복문 선언 와일',
'조건문 선언',
'논리 식 선언',
'기본 함수 사용',
'인풋',
'스플릿',
'프린트',
'섬',
'맥스',
'민',
'렌',
'리턴',
'리스트'
],
boost: 20
}]
......@@ -56,6 +75,137 @@ async function testGoogleTextToSpeech(audioBuffer) {
.map(result => result.alternatives[0].transcript);
return transcription;
}
let before_val = '';
async function TextToPython(trans_data, tab) {
let text_list = trans_data.split(' ');
console.log(text_list);
switch (text_list[0]){
case '기본':
before_val = '기본';
switch (text_list[3]){
case '프린트':
return tab + 'print(';
case '인풋':
return 'input()\n';
case '섬':
return 'sum(';
case '맥스':
return 'max(';
case '민':
return 'min(';
case '렌':
return 'len(';
case '수식':
return text_list.slice(4).join(' ') + '\n';
default: return '';
}
case '파라미터':
if (text_list.length < 3) return '';
if (before_val == '기본'){
before_val = '파라미터';
return text_list.slice(2).join() + ')\n';
}
else{
before_val = '파라미터';
return text_list.slice(2).join() + '):\n';
}
break;
case '변수':
if (text_list.length < 4) return '';
before_val = '변수';
if (text_list[2] == '문자'){
if (text_list[3][text_list[3].length-1] == '는'){
return tab + text_list[3].slice(0, text_list[3].length-1) + ' = "' + text_list.slice(4).join(' ') + '"\n';
}
else{
text_list[4] = '= "';
return tab + text_list.slice(3).join(' ') + '"\n';
}
}
else if (text_list[2] == '숫자'){
if (text_list[3][text_list[3].length-1] == '는'){
return tab + text_list[3].slice(0, text_list[3].length-1) + ' = ' + text_list.slice(4).join(' ') + '\n';
}
else if (text_list[4] == '-'){
text_list[4] = '=';
return tab + text_list.slice(3).join(' ') + '\n';
}
}
else if (text_list[2] == '함수'){
if (text_list[3][text_list[3].length-1] == '는'){
return tab + text_list[3].slice(0, text_list[3].length-1) + ' = ';
}
else{
text_list[4] = '=';
return tab + text_list.slice(3).join(' ');
}
}
else if (text_list[2] == '리스트'){
if (text_list[3][text_list[3].length-1] == '는'){
if (text_list[4] == '빈') return tab + text_list[3].slice(0, text_list[3].length-1) + ' = []\n';
else if (text_list[4] == '숫자') return tab + text_list[3].slice(0, text_list[3].length-1) + ' = [' + text_list.slice(6).join(',') + ']\n';
else return tab + text_list[3].slice(0, text_list[3].length-1) + ' = ["' + text_list.slice(6).join('","') + '"]\n';
}
}
else return '';
break;
case '반복문':
before_val = '반복문';
if (text_list[2] == 'for'){
return tab + text_list.slice(2).join(' ') + ' ('
}
else if (text_list[2] == 'while' || text_list[2] == '와일'){
return tab + 'while (';
}
else return '';
break;
case '함수':
if (text_list.length >= 3){
before_val = '함수'
return tab + 'def ' + text_list.slice(2).join('') + '(';
}
else return '';
case '조건문':
if (text_list.length >= 3){
before_val = '조건문';
if (text_list[2] == 'if' || text_list[2] == '이프'){
return tab + 'if (';
}
else if ((text_list[2] == 'else' || text_list[2] == '엘스')){
return tab + 'else:\n'
}
else if((text_list[2] == 'else' || text_list[2] == '엘스') && (text_list[3] == 'if' || text_list[3] == '이프')){
return tab + 'elif (';
}
}
else return '';
break;
case '논리':
if (text_list.length >= 7){
if (text_list[6] == '같다'){
return text_list[3].slice(0, text_list[3].length-1) + ' == ' + text_list[4] + '):\n';
}
else if(text_list[6] == '크다'){
return text_list[3].slice(0, text_list[3].length-1) + ' > ' + text_list[4] + '):\n';
}
else if(text_list[6] == '작다'){
return text_list[3].slice(0, text_list[3].length-1) + ' < ' + text_list[4] + '):\n';
}
else if(text_list[6] == '크거나'){
return text_list[3].slice(0, text_list[3].length-1) + ' >= ' + text_list[4] + '):\n';
}
else if(text_list[6] == '작거나'){
return text_list[3].slice(0, text_list[3].length-1) + ' <= ' + text_list[4] + '):\n';
}
}
else return '';
break;
default: return ''
}
}
app.post('/upload_sound', upload.any(), async (req, res) => {
console.log("Getting text transcription..");
let transcription = await testGoogleTextToSpeech(req.files[0].buffer);
......@@ -64,7 +214,7 @@ app.post('/upload_sound', upload.any(), async (req, res) => {
});
app.post('/ttp', upload.any(), async (req, res) => {
console.log("Getting python code..");
let python_code = req.body.transcript_data;
let python_code = await TextToPython(req.body.transcript_data, req.body.tabs);
console.log("Pyton code: " + python_code);
res.status(200).send(python_code);
});
......