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

Fixed sox recording #46

Closed
wants to merge 2 commits 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
42 changes: 25 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,48 @@ exports.start = function (options) {
thresholdEnd: null,
silence: '1.0',
verbose: false,
recordProgram: 'rec'
recordProgram: 'sox'
}

options = Object.assign(defaults, options)

// Capture audio stream
var cmd, cmdArgs, cmdOptions
var cmd, cmdArgs, cmdOptions, audioType
switch (options.recordProgram) {
// On some Windows machines, sox is installed using the "sox" binary
// instead of "rec"
case 'sox':
var cmd = 'sox';
var cmdArgs = [
'-q', // show no progress
'-t', 'waveaudio', // audio type
'-d', // use default recording device
'-r', options.sampleRate, // sample rate
'-c', options.channels, // channels
'-e', 'signed-integer', // sample encoding
'-b', '16', // precision (bits)
'-', // pipe
// end on silence
cmd = "sox"
audioType = "wav"
if (options.audioType) audioType = options.audioType
if (options.asRaw) audioType = "raw"
cmdArgs = [
'-q', // show no progress
'-t', 'waveaudio',
'-d',
'-r', options.sampleRate.toString(), // sample rate
'-c', '1', // channels
'-e', 'signed-integer', // sample encoding
'-b', '16', // precision (bits)
'-t', audioType, // audio type
'-'
// end on silence
'silence', '1', '0.1', options.thresholdStart || options.threshold + '%',
'1', options.silence, options.thresholdEnd || options.threshold + '%'
];
]
break
case 'rec':
default:
cmd = options.recordProgram
cmd = "rec"
audioType = "wav"
if (options.audioType) audioType = options.audioType
cmdArgs = [
'-q', // show no progress
'-r', options.sampleRate, // sample rate
'-c', options.channels, // channels
'-e', 'signed-integer', // sample encoding
'-b', '16', // precision (bits)
'-t', 'wav', // audio type
'-t', audioType, // audio type
'-', // pipe
// end on silence
'silence', '1', '0.1', options.thresholdStart || options.threshold + '%',
Expand All @@ -62,11 +68,13 @@ exports.start = function (options) {
// On some systems (RasPi), arecord is the prefered recording binary
case 'arecord':
cmd = 'arecord'
audioType = "wav"
if (options.audioType) audioType = options.audioType
cmdArgs = [
'-q', // show no progress
'-r', options.sampleRate, // sample rate
'-c', options.channels, // channels
'-t', 'wav', // audio type
'-t', audioType, // audio type
'-f', 'S16_LE', // Sample format
'-' // pipe
]
Expand Down