Merge branch 'TTP-manual' into 'main'
Ttp manual See merge request !10
Showing
3 changed files
with
213 additions
and
14 deletions
1 | -1. | ||
2 | -2. | ||
3 | -3. | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +'기본 함수 사용', | ||
2 | + '인풋', -> input() | ||
3 | + '프린트', -> print( | ||
4 | + '섬', -> sum( | ||
5 | + '맥스', -> max( | ||
6 | + '민' -> min( | ||
7 | + '렌' -> len( | ||
8 | + '수식' -> +, -, *, /, 몫, 나머지 | ||
9 | + => 뒤에 나오는걸 parameter로 넣어야 함 | ||
10 | + | ||
11 | +'변수 선언' -> 문자, 숫자, 리스트, 함수 | ||
12 | + 는 -> = | ||
13 | + 첫번째 - -> = | ||
14 | + 리스트 -> c는 빈 리스트-> c = [] | ||
15 | + c는 숫자 리스트 1 2 3 4 5 6 -> c = [1, 2, 3, 4, 5, 6] | ||
16 | + c는 문자 리스트 a b c d -> c = ['a', 'b', 'c', 'd'] | ||
17 | + | ||
18 | +'반복문 선언' | ||
19 | + for a in range -> for a in range( | ||
20 | + for i in (li): | ||
21 | + while -> while( | ||
22 | + | ||
23 | +'조건문 선언' | ||
24 | + if -> if( | ||
25 | + else if -> elif( | ||
26 | + else -> else: | ||
27 | + | ||
28 | +'함수 선언' | ||
29 | + aaa -> def aaa( | ||
30 | + | ||
31 | +'완료' -> tab 빼기 | ||
32 | + | ||
33 | +'파라미터 선언' | ||
34 | + a b c -> a, b, c): | ||
35 | + | ||
36 | +'논리 식 선언' | ||
37 | + 1: A는 B 와 같다 -> A == B): | ||
38 | + 2: A는 B 보다 크다 -> A > B): | ||
39 | + 5: A는 B 보다 크거나 같다 -> A >= B): | ||
40 | + 6: A는 B 보다 작거나 같다 -> A <= B): | ||
41 | + 7: A는 B 보다 작다 -> A < B): | ... | ... |
... | @@ -1368,15 +1368,23 @@ function transcribeText() { | ... | @@ -1368,15 +1368,23 @@ function transcribeText() { |
1368 | } | 1368 | } |
1369 | 1369 | ||
1370 | let input_line = "" | 1370 | let input_line = "" |
1371 | -function uploadSoundData(blob) { | 1371 | +let tab = ''; |
1372 | +let before_val = ''; | ||
1373 | +let chk = 1; | ||
1374 | +let tmp = []; | ||
1375 | +async function uploadSoundData(blob) { | ||
1372 | let filename = new Date().toISOString(); | 1376 | let filename = new Date().toISOString(); |
1373 | let xhr = new XMLHttpRequest(); | 1377 | let xhr = new XMLHttpRequest(); |
1374 | let formData = new FormData(); | 1378 | let formData = new FormData(); |
1375 | xhr.onload = function(e) { | 1379 | xhr.onload = function(e) { |
1376 | if(this.readyState === 4) { | 1380 | if(this.readyState === 4) { |
1377 | - let transcript = JSON.parse(e.target.responseText) | 1381 | + let transcript = JSON.parse(e.target.responseText) + ''; |
1378 | document.getElementById("output").innerHTML += `${cnt++}: ${transcript}<br><br>`; | 1382 | document.getElementById("output").innerHTML += `${cnt++}: ${transcript}<br><br>`; |
1379 | - uploadTranscriptData(transcript); | 1383 | + tmp = transcript.split(' '); |
1384 | + if (tmp[0] == '종료') tab = tab.slice(1); | ||
1385 | + else{ | ||
1386 | + uploadTranscriptData(tab, transcript); | ||
1387 | + } | ||
1380 | } | 1388 | } |
1381 | }; | 1389 | }; |
1382 | formData.append("audio_data", blob, filename); | 1390 | formData.append("audio_data", blob, filename); |
... | @@ -1384,18 +1392,21 @@ function uploadSoundData(blob) { | ... | @@ -1384,18 +1392,21 @@ function uploadSoundData(blob) { |
1384 | xhr.send(formData); | 1392 | xhr.send(formData); |
1385 | } | 1393 | } |
1386 | 1394 | ||
1387 | -function uploadTranscriptData(txt) { | 1395 | +async function uploadTranscriptData(tabs, txt) { |
1388 | let request = new XMLHttpRequest(); | 1396 | let request = new XMLHttpRequest(); |
1389 | let form = new FormData(); | 1397 | let form = new FormData(); |
1390 | request.onload = function(e) { | 1398 | request.onload = function(e) { |
1391 | if(this.readyState === 4) { | 1399 | if(this.readyState === 4) { |
1392 | console.log(e.target.responseText) | 1400 | console.log(e.target.responseText) |
1393 | - input_line += e.target.responseText + '\n'; | 1401 | + input_line += e.target.responseText; |
1394 | - console.log(input_line) | ||
1395 | sourceEditor.setValue(input_line); | 1402 | sourceEditor.setValue(input_line); |
1403 | + if ((tmp[0] == '함수' || tmp[0] == '반복문' || tmp[0] == '조건문') && e.target.responseText != '') { | ||
1404 | + tab += '\t'; | ||
1405 | + } | ||
1396 | } | 1406 | } |
1397 | }; | 1407 | }; |
1398 | form.append("transcript_data", txt); | 1408 | form.append("transcript_data", txt); |
1409 | + form.append("tabs", tabs); | ||
1399 | request.open("POST", "/ttp", true); | 1410 | request.open("POST", "/ttp", true); |
1400 | request.send(form); | 1411 | request.send(form); |
1401 | } | 1412 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -20,7 +20,14 @@ async function testGoogleTextToSpeech(audioBuffer) { | ... | @@ -20,7 +20,14 @@ async function testGoogleTextToSpeech(audioBuffer) { |
20 | '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE', | 20 | '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE', |
21 | '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크다', | 21 | '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크다', |
22 | '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작다', | 22 | '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작다', |
23 | - 'for OOV_CLASS_ALPHA_SEQUENCE in range $OOV_CLASS_ALPHANUMERIC_SEQUENCE', | 23 | + '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 와 같다', |
24 | + '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작거나 같다', | ||
25 | + '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크거나 같다', | ||
26 | + '반복문 선언 for $OOV_CLASS_ALPHA_SEQUENCE in range', | ||
27 | + '반복문 선언 for $OOV_CLASS_ALPHA_SEQUENCE in', | ||
28 | + '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 빈 리스트', | ||
29 | + '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 숫자 리스트 $OOV_CLASS_ALPHANUMERIC_SEQUENCE', | ||
30 | + '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 문자 리스트 $OOV_CLASS_ALPHANUMERIC_SEQUENCE', | ||
24 | 'if', | 31 | 'if', |
25 | '이프', | 32 | '이프', |
26 | 'else if', | 33 | 'else if', |
... | @@ -30,12 +37,24 @@ async function testGoogleTextToSpeech(audioBuffer) { | ... | @@ -30,12 +37,24 @@ async function testGoogleTextToSpeech(audioBuffer) { |
30 | 'while', | 37 | 'while', |
31 | '와일', | 38 | '와일', |
32 | '함수', | 39 | '함수', |
33 | - '파라미터', | 40 | + '파라미터 선언', |
34 | 'parameter', | 41 | 'parameter', |
35 | '변수 선언', | 42 | '변수 선언', |
36 | '함수 선언', | 43 | '함수 선언', |
37 | - '반복문 선언', | 44 | + '반복문 선언 while', |
38 | - '조건문 선언' | 45 | + '반복문 선언 와일', |
46 | + '조건문 선언', | ||
47 | + '논리 식 선언', | ||
48 | + '기본 함수 사용', | ||
49 | + '인풋', | ||
50 | + '스플릿', | ||
51 | + '프린트', | ||
52 | + '섬', | ||
53 | + '맥스', | ||
54 | + '민', | ||
55 | + '렌', | ||
56 | + '리턴', | ||
57 | + '리스트' | ||
39 | ], | 58 | ], |
40 | boost: 20 | 59 | boost: 20 |
41 | }] | 60 | }] |
... | @@ -56,6 +75,137 @@ async function testGoogleTextToSpeech(audioBuffer) { | ... | @@ -56,6 +75,137 @@ async function testGoogleTextToSpeech(audioBuffer) { |
56 | .map(result => result.alternatives[0].transcript); | 75 | .map(result => result.alternatives[0].transcript); |
57 | return transcription; | 76 | return transcription; |
58 | } | 77 | } |
78 | + | ||
79 | +let before_val = ''; | ||
80 | +async function TextToPython(trans_data, tab) { | ||
81 | + let text_list = trans_data.split(' '); | ||
82 | + console.log(text_list); | ||
83 | + switch (text_list[0]){ | ||
84 | + case '기본': | ||
85 | + before_val = '기본'; | ||
86 | + switch (text_list[3]){ | ||
87 | + case '프린트': | ||
88 | + return tab + 'print('; | ||
89 | + case '인풋': | ||
90 | + return 'input()\n'; | ||
91 | + case '섬': | ||
92 | + return 'sum('; | ||
93 | + case '맥스': | ||
94 | + return 'max('; | ||
95 | + case '민': | ||
96 | + return 'min('; | ||
97 | + case '렌': | ||
98 | + return 'len('; | ||
99 | + case '수식': | ||
100 | + return text_list.slice(4).join(' ') + '\n'; | ||
101 | + default: return ''; | ||
102 | + } | ||
103 | + case '파라미터': | ||
104 | + if (text_list.length < 3) return ''; | ||
105 | + if (before_val == '기본'){ | ||
106 | + before_val = '파라미터'; | ||
107 | + return text_list.slice(2).join() + ')\n'; | ||
108 | + } | ||
109 | + else{ | ||
110 | + before_val = '파라미터'; | ||
111 | + return text_list.slice(2).join() + '):\n'; | ||
112 | + } | ||
113 | + break; | ||
114 | + case '변수': | ||
115 | + if (text_list.length < 4) return ''; | ||
116 | + before_val = '변수'; | ||
117 | + if (text_list[2] == '문자'){ | ||
118 | + if (text_list[3][text_list[3].length-1] == '는'){ | ||
119 | + return tab + text_list[3].slice(0, text_list[3].length-1) + ' = "' + text_list.slice(4).join(' ') + '"\n'; | ||
120 | + } | ||
121 | + else{ | ||
122 | + text_list[4] = '= "'; | ||
123 | + return tab + text_list.slice(3).join(' ') + '"\n'; | ||
124 | + } | ||
125 | + } | ||
126 | + else if (text_list[2] == '숫자'){ | ||
127 | + if (text_list[3][text_list[3].length-1] == '는'){ | ||
128 | + return tab + text_list[3].slice(0, text_list[3].length-1) + ' = ' + text_list.slice(4).join(' ') + '\n'; | ||
129 | + } | ||
130 | + else if (text_list[4] == '-'){ | ||
131 | + text_list[4] = '='; | ||
132 | + return tab + text_list.slice(3).join(' ') + '\n'; | ||
133 | + } | ||
134 | + } | ||
135 | + else if (text_list[2] == '함수'){ | ||
136 | + if (text_list[3][text_list[3].length-1] == '는'){ | ||
137 | + return tab + text_list[3].slice(0, text_list[3].length-1) + ' = '; | ||
138 | + } | ||
139 | + else{ | ||
140 | + text_list[4] = '='; | ||
141 | + return tab + text_list.slice(3).join(' '); | ||
142 | + } | ||
143 | + } | ||
144 | + else if (text_list[2] == '리스트'){ | ||
145 | + if (text_list[3][text_list[3].length-1] == '는'){ | ||
146 | + if (text_list[4] == '빈') return tab + text_list[3].slice(0, text_list[3].length-1) + ' = []\n'; | ||
147 | + else if (text_list[4] == '숫자') return tab + text_list[3].slice(0, text_list[3].length-1) + ' = [' + text_list.slice(6).join(',') + ']\n'; | ||
148 | + else return tab + text_list[3].slice(0, text_list[3].length-1) + ' = ["' + text_list.slice(6).join('","') + '"]\n'; | ||
149 | + } | ||
150 | + } | ||
151 | + else return ''; | ||
152 | + break; | ||
153 | + case '반복문': | ||
154 | + before_val = '반복문'; | ||
155 | + if (text_list[2] == 'for'){ | ||
156 | + return tab + text_list.slice(2).join(' ') + ' (' | ||
157 | + } | ||
158 | + else if (text_list[2] == 'while' || text_list[2] == '와일'){ | ||
159 | + return tab + 'while ('; | ||
160 | + } | ||
161 | + else return ''; | ||
162 | + break; | ||
163 | + case '함수': | ||
164 | + if (text_list.length >= 3){ | ||
165 | + before_val = '함수' | ||
166 | + return tab + 'def ' + text_list.slice(2).join('') + '('; | ||
167 | + } | ||
168 | + else return ''; | ||
169 | + case '조건문': | ||
170 | + if (text_list.length >= 3){ | ||
171 | + before_val = '조건문'; | ||
172 | + if (text_list[2] == 'if' || text_list[2] == '이프'){ | ||
173 | + return tab + 'if ('; | ||
174 | + } | ||
175 | + else if ((text_list[2] == 'else' || text_list[2] == '엘스')){ | ||
176 | + return tab + 'else:\n' | ||
177 | + } | ||
178 | + else if((text_list[2] == 'else' || text_list[2] == '엘스') && (text_list[3] == 'if' || text_list[3] == '이프')){ | ||
179 | + return tab + 'elif ('; | ||
180 | + } | ||
181 | + } | ||
182 | + else return ''; | ||
183 | + break; | ||
184 | + case '논리': | ||
185 | + if (text_list.length >= 7){ | ||
186 | + if (text_list[6] == '같다'){ | ||
187 | + return text_list[3].slice(0, text_list[3].length-1) + ' == ' + text_list[4] + '):\n'; | ||
188 | + } | ||
189 | + else if(text_list[6] == '크다'){ | ||
190 | + return text_list[3].slice(0, text_list[3].length-1) + ' > ' + text_list[4] + '):\n'; | ||
191 | + } | ||
192 | + else if(text_list[6] == '작다'){ | ||
193 | + return text_list[3].slice(0, text_list[3].length-1) + ' < ' + text_list[4] + '):\n'; | ||
194 | + } | ||
195 | + else if(text_list[6] == '크거나'){ | ||
196 | + return text_list[3].slice(0, text_list[3].length-1) + ' >= ' + text_list[4] + '):\n'; | ||
197 | + } | ||
198 | + else if(text_list[6] == '작거나'){ | ||
199 | + return text_list[3].slice(0, text_list[3].length-1) + ' <= ' + text_list[4] + '):\n'; | ||
200 | + } | ||
201 | + } | ||
202 | + else return ''; | ||
203 | + break; | ||
204 | + default: return '' | ||
205 | + } | ||
206 | + | ||
207 | +} | ||
208 | + | ||
59 | app.post('/upload_sound', upload.any(), async (req, res) => { | 209 | app.post('/upload_sound', upload.any(), async (req, res) => { |
60 | console.log("Getting text transcription.."); | 210 | console.log("Getting text transcription.."); |
61 | let transcription = await testGoogleTextToSpeech(req.files[0].buffer); | 211 | let transcription = await testGoogleTextToSpeech(req.files[0].buffer); |
... | @@ -64,7 +214,7 @@ app.post('/upload_sound', upload.any(), async (req, res) => { | ... | @@ -64,7 +214,7 @@ app.post('/upload_sound', upload.any(), async (req, res) => { |
64 | }); | 214 | }); |
65 | app.post('/ttp', upload.any(), async (req, res) => { | 215 | app.post('/ttp', upload.any(), async (req, res) => { |
66 | console.log("Getting python code.."); | 216 | console.log("Getting python code.."); |
67 | - let python_code = req.body.transcript_data; | 217 | + let python_code = await TextToPython(req.body.transcript_data, req.body.tabs); |
68 | console.log("Pyton code: " + python_code); | 218 | console.log("Pyton code: " + python_code); |
69 | res.status(200).send(python_code); | 219 | res.status(200).send(python_code); |
70 | }); | 220 | }); | ... | ... |
-
Please register or login to post a comment