Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #8 #28

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ exports.start = function (options) {
thresholdEnd: null,
silence: '1.0',
verbose: false,
recordProgram: 'rec'
asRaw: false,
recordProgram: 'rec',
useSilence: true
}

options = Object.assign(defaults, options)
Expand All @@ -32,25 +34,32 @@ exports.start = function (options) {
cmd = options.recordProgram
cmdArgs = [
'-q', // show no progress
'-r', options.sampleRate, // sample rate
'-t', 'waveaudio',
'-d',
'-r', options.sampleRate.toString(), // sample rate
'-c', '1', // channels
'-e', 'signed-integer', // sample encoding
'-b', '16', // precision (bits)
'-t', 'wav', // audio type
'-', // pipe
// end on silence
'silence', '1', '0.1', options.thresholdStart || options.threshold + '%',
'1', options.silence, options.thresholdEnd || options.threshold + '%'
'-t', (options.asRaw ? 'raw' : 'wav'), // audio type
'-' // pipe
]

if(options.useSilence) {
cmdArgs = cmdArgs.concat([
'silence', '1', '0.1', options.thresholdStart || options.threshold + '%',
'1', options.silence, options.thresholdEnd || options.threshold + '%'
]);
}

break
// On some systems (RasPi), arecord is the prefered recording binary
case 'arecord':
cmd = 'arecord'
cmdArgs = [
'-q', // show no progress
'-r', options.sampleRate, // sample rate
'-r', options.sampleRate.toString(), // sample rate
'-c', '1', // channels
'-t', 'wav', // audio type
'-t', (options.asRaw ? 'raw' : 'wav'), // audio type
'-f', 'S16_LE', // Sample format
'-' // pipe
]
Expand All @@ -67,6 +76,7 @@ exports.start = function (options) {
}
cp = spawn(cmd, cmdArgs, cmdOptions)
var rec = cp.stdout
rec.setEncoding('binary');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gave me an encoding error. I removed this line and it worked for me.


if (options.verbose) {
console.log('Recording with sample rate', options.sampleRate + '...')
Expand Down