Toggle navigation
Toggle navigation
This project
Loading...
Sign in
천현우
/
Voicoding
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
천현우
2021-06-08 00:00:58 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
14a6ce7586a3ecc760c8c712d32f0bcd61ac1401
14a6ce75
1 parent
8452b897
TTP: update TTP functions, insert/delete tab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
72 deletions
Manual.txt
Voicoding_web/js/ide.js
voicoding.js
Manual.txt
View file @
14a6ce7
'기본 함수 사용',
'인풋', -> input()
'스플릿', -> .split()
'프린트', -> print(
'섬', -> sum(
'맥스', -> max(
...
...
Voicoding_web/js/ide.js
View file @
14a6ce7
...
...
@@ -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,7 +1392,7 @@ 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
)
{
...
...
@@ -1392,9 +1400,13 @@ function uploadTranscriptData(txt) {
console
.
log
(
e
.
target
.
responseText
)
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
...
...
voicoding.js
View file @
14a6ce7
...
...
@@ -23,8 +23,8 @@ 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
'
,
'for $OOV_CLASS_ALPHA_SEQUENCE in'
,
'
반복문 선언 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'
,
...
...
@@ -41,8 +41,10 @@ async function testGoogleTextToSpeech(audioBuffer) {
'parameter'
,
'변수 선언'
,
'함수 선언'
,
'반복문 선언'
,
'반복문 선언 while'
,
'반복문 선언 와일'
,
'조건문 선언'
,
'논리 식 선언'
,
'기본 함수 사용'
,
'인풋'
,
'스플릿'
,
...
...
@@ -73,22 +75,19 @@ async function testGoogleTextToSpeech(audioBuffer) {
.
map
(
result
=>
result
.
alternatives
[
0
].
transcript
);
return
transcription
;
}
let
before_val
=
''
;
let
tab
=
''
;
let
ent
=
''
;
async
function
TextToPython
(
trans_data
)
{
async
function
TextToPython
(
trans_data
,
tab
)
{
let
text_list
=
trans_data
.
split
(
' '
);
console
.
log
(
text_list
);
switch
(
text_list
[
0
]){
case
'기본'
:
before_val
=
text_list
[
0
]
;
before_val
=
'기본'
;
switch
(
text_list
[
3
]){
case
'프린트'
:
return
tab
+
'print('
;
case
'인풋'
:
return
tab
+
'input()'
;
case
'스플릿'
:
return
'.split()'
;
return
'input()\n'
;
case
'섬'
:
return
'sum('
;
case
'맥스'
:
...
...
@@ -97,8 +96,10 @@ async function TextToPython(trans_data) {
return
'min('
;
case
'렌'
:
return
'len('
;
case
'수식'
:
return
text_list
.
slice
(
4
).
join
(
' '
)
+
'\n'
;
default
:
return
''
;
}
break
;
case
'파라미터'
:
if
(
text_list
.
length
<
3
)
return
''
;
if
(
before_val
==
'기본'
){
...
...
@@ -107,99 +108,74 @@ async function TextToPython(trans_data) {
}
else
{
before_val
=
'파라미터'
;
tab
+=
'\t'
;
return
text_list
.
slice
(
2
).
join
()
+
'):\n'
;
}
break
;
case
'변수'
:
if
(
before_val
==
'기본'
){
ent
=
'\n'
;
}
else
{
ent
=
''
;
}
before_val
=
'변수'
;
if
(
text_list
.
length
<
4
)
return
''
;
before_val
=
'변수'
;
if
(
text_list
[
2
]
==
'문자'
){
if
(
text_list
[
3
][
text_list
[
3
].
length
-
1
]
==
'는'
){
return
ent
+
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = "'
+
text_list
.
slice
(
4
).
join
(
' '
)
+
'"\n'
;
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = "'
+
text_list
.
slice
(
4
).
join
(
' '
)
+
'"\n'
;
}
else
{
text_list
[
4
]
=
'= "'
;
return
ent
+
tab
+
text_list
.
slice
(
3
).
join
(
' '
)
+
'"\n'
;
return
tab
+
text_list
.
slice
(
3
).
join
(
' '
)
+
'"\n'
;
}
}
else
if
(
text_list
[
2
]
==
'숫자'
){
if
(
text_list
[
3
][
text_list
[
3
].
length
-
1
]
==
'는'
){
return
ent
+
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = '
+
text_list
.
slice
(
4
).
join
(
' '
)
+
'\n'
;
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
ent
+
tab
+
text_list
.
slice
(
3
).
join
(
' '
)
+
'\n'
;
return
tab
+
text_list
.
slice
(
3
).
join
(
' '
)
+
'\n'
;
}
}
else
if
(
text_list
[
2
]
==
'함수'
){
if
(
text_list
[
3
][
text_list
[
3
].
length
-
1
]
==
'는'
){
return
ent
+
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = '
;
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = '
;
}
else
{
text_list
[
4
]
=
'='
;
return
ent
+
tab
+
text_list
.
slice
(
3
)
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
ent
+
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = []\n'
;
else
if
(
text_list
[
4
]
==
'숫자'
)
ent
+
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = ['
+
text_list
.
slice
(
6
).
join
(
','
)
+
']\n'
;
else
return
ent
+
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' = ["'
+
text_list
.
slice
(
6
).
join
(
'","'
)
+
'"]\n'
;
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
'반복문'
:
if
(
before_val
==
'기본'
){
ent
=
'\n'
;
}
else
{
ent
=
''
;
before_val
=
'반복문'
;
if
(
text_list
[
2
]
==
'for'
){
return
tab
+
text_list
.
slice
(
2
).
join
(
' '
)
+
' ('
}
if
(
text_list
[
3
]
==
'for'
){
return
ent
+
tab
+
text_list
.
slice
(
3
).
join
(
' '
)
+
' ('
}
else
if
(
text_list
[
3
]
==
'while'
||
text_list
[
3
]
==
'와일'
){
return
ent
+
tab
+
'while ('
;
else
if
(
text_list
[
2
]
==
'while'
||
text_list
[
2
]
==
'와일'
){
return
tab
+
'while ('
;
}
else
return
''
;
break
;
case
'완료'
:
tab
.
slice
(
1
);
return
''
;
break
;
case
'함수'
:
if
(
before_val
==
'기본'
){
ent
=
'\n'
;
}
else
{
ent
=
''
;
if
(
text_list
.
length
>=
3
){
before_val
=
'함수'
return
tab
+
'def '
+
text_list
.
slice
(
2
).
join
(
''
)
+
'('
;
}
if
(
text_list
.
length
>=
3
)
return
'def '
+
text_list
.
slice
(
2
).
join
(
''
)
+
'('
;
else
return
''
;
case
'조건문'
:
if
(
before_val
==
'기본'
){
ent
=
'\n'
;
}
else
{
ent
=
''
;
}
if
(
text_list
.
length
>=
3
){
if
(
text_list
[
3
]
==
'if'
||
text_list
[
3
]
==
'이프'
){
before_val
=
'조건문'
;
if
(
text_list
[
2
]
==
'if'
||
text_list
[
2
]
==
'이프'
){
return
tab
+
'if ('
;
}
else
if
((
text_list
[
3
]
==
'else'
||
text_list
[
3
]
==
'엘스'
)){
tab
+=
1
;
return
'\t'
*
(
tab
-
1
)
+
'else:\n'
else
if
((
text_list
[
2
]
==
'else'
||
text_list
[
2
]
==
'엘스'
)){
return
tab
+
'else:\n'
}
else
if
((
text_list
[
3
]
==
'else'
||
text_list
[
3
]
==
'엘스'
)
&&
(
text_list
[
4
]
==
'if'
||
text_list
[
4
]
==
'이프'
)){
else
if
((
text_list
[
2
]
==
'else'
||
text_list
[
2
]
==
'엘스'
)
&&
(
text_list
[
3
]
==
'if'
||
text_list
[
3
]
==
'이프'
)){
return
tab
+
'elif ('
;
}
}
...
...
@@ -207,21 +183,20 @@ async function TextToPython(trans_data) {
break
;
case
'논리'
:
if
(
text_list
.
length
>=
7
){
tab
+=
1
;
if
(
text_list
[
6
]
==
'같다'
){
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' == '
+
text_list
[
4
]
+
'):\n'
;
return
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' == '
+
text_list
[
4
]
+
'):\n'
;
}
else
if
(
text_list
[
6
]
==
'크다'
){
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' > '
+
text_list
[
4
]
+
'):\n'
;
return
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' > '
+
text_list
[
4
]
+
'):\n'
;
}
else
if
(
text_list
[
6
]
==
'작다'
){
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' < '
+
text_list
[
4
]
+
'):\n'
;
return
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' < '
+
text_list
[
4
]
+
'):\n'
;
}
else
if
(
text_list
[
6
]
==
'크거나'
){
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' >= '
+
text_list
[
4
]
+
'):\n'
;
return
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' >= '
+
text_list
[
4
]
+
'):\n'
;
}
else
if
(
text_list
[
6
]
==
'작거나'
){
return
tab
+
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' <= '
+
text_list
[
4
]
+
'):\n'
;
return
text_list
[
3
].
slice
(
0
,
text_list
[
3
].
length
-
1
)
+
' <= '
+
text_list
[
4
]
+
'):\n'
;
}
}
else
return
''
;
...
...
@@ -239,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
=
await
TextToPython
(
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
);
});
...
...
Please
register
or
login
to post a comment