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-05-25 17:54:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
66c1aa5d143cf217e6570d54a490e2027709b9ba
66c1aa5d
1 parent
16c37e8b
add Voice Transcription
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
voicoding.js
voicoding.js
View file @
66c1aa5
const
recorder
=
require
(
'node-record-lpcm16'
);
// Imports the Google Cloud client library
const
speech
=
require
(
'@google-cloud/speech'
);
// Creates a client
const
client
=
new
speech
.
SpeechClient
();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
const
encoding
=
'LINEAR16'
;
const
sampleRateHertz
=
16000
;
const
languageCode
=
'ko-KR'
;
const
request
=
{
config
:
{
encoding
:
encoding
,
sampleRateHertz
:
sampleRateHertz
,
languageCode
:
languageCode
},
interimResults
:
false
,
// If you want interim results, set this to true
};
// Create a recognize stream
const
recognizeStream
=
client
.
streamingRecognize
(
request
)
.
on
(
'error'
,
console
.
error
)
.
on
(
'data'
,
data
=>
process
.
stdout
.
write
(
data
.
results
[
0
]
&&
data
.
results
[
0
].
alternatives
[
0
]
?
`Transcription:
${
data
.
results
[
0
].
alternatives
[
0
].
transcript
}
\n`
:
'\n\nReached transcription time limit, press Ctrl+C\n'
)
);
// Start recording and send the microphone input to the Speech API.
// Ensure SoX is installed, see https://www.npmjs.com/package/node-record-lpcm16#dependencies
recorder
.
record
({
sampleRateHertz
:
sampleRateHertz
,
threshold
:
0
,
// Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
verbose
:
false
,
recordProgram
:
'sox'
,
// Try also "arecord" or "sox"
silence
:
'1.0'
,
})
.
stream
()
.
on
(
'error'
,
console
.
error
)
.
pipe
(
recognizeStream
);
console
.
log
(
'Listening, press Ctrl+C to stop.'
);
...
...
Please
register
or
login
to post a comment