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-02 21:43:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
17904b68cdbae3b8970eeae0eff58bd23853dcac
17904b68
1 parent
6d3e00d9
client demo
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
client.js
client.js
0 → 100644
View file @
17904b6
let
rec
=
null
;
let
audioStream
=
null
;
const
recordButton
=
document
.
getElementById
(
"recordButton"
);
const
transcribeButton
=
document
.
getElementById
(
"transcribeButton"
);
recordButton
.
addEventListener
(
"click"
,
startRecording
);
transcribeButton
.
addEventListener
(
"click"
,
transcribeText
);
function
startRecording
()
{
let
constraints
=
{
audio
:
true
,
video
:
false
}
recordButton
.
disabled
=
true
;
transcribeButton
.
disabled
=
false
;
navigator
.
mediaDevices
.
getUserMedia
(
constraints
).
then
(
function
(
stream
)
{
const
audioContext
=
new
window
.
AudioContext
();
audioStream
=
stream
;
const
input
=
audioContext
.
createMediaStreamSource
(
stream
);
rec
=
new
Recorder
(
input
,
{
numChannels
:
1
})
rec
.
record
()
}).
catch
(
function
(
err
)
{
recordButton
.
disabled
=
false
;
transcribeButton
.
disabled
=
true
;
});
}
function
transcribeText
()
{
transcribeButton
.
disabled
=
true
;
recordButton
.
disabled
=
false
;
rec
.
stop
();
audioStream
.
getAudioTracks
()[
0
].
stop
();
rec
.
exportWAV
(
uploadSoundData
);
}
function
uploadSoundData
(
blob
)
{
let
filename
=
new
Date
().
toISOString
();
let
xhr
=
new
XMLHttpRequest
();
let
formData
=
new
FormData
();
xhr
.
onload
=
function
(
e
)
{
if
(
this
.
readyState
===
4
)
{
document
.
getElementById
(
"output"
).
innerHTML
+=
`<br><br><strong>Result: </strong>
${
e
.
target
.
responseText
}
`
}
};
formData
.
append
(
"audio_data"
,
blob
,
filename
);
xhr
.
open
(
"POST"
,
"/upload_sound"
,
true
);
xhr
.
send
(
formData
);
}
\ No newline at end of file
Please
register
or
login
to post a comment