snips-sam
Version:
The Snips Assistant Manager
118 lines • 4.99 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chalk_1 = require("chalk");
const cli_1 = require("../../cli");
const ssh_1 = require("../../session/ssh");
exports.command = 'aec';
exports.desc = 'Enable audio echo-cancellation (AEC) through PulseAudio';
exports.builder = {
verbose: {
demandOption: false,
describe: 'Include remote logs',
type: 'boolean',
alias: 'v',
},
};
exports.handler = (argv) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const verbose = JSON.parse(JSON.stringify(argv)).verbose;
const ssh = new ssh_1.SSHService();
try {
yield ssh.connect();
}
catch (e) {
cli_1.cli.stream.error(e);
process.exit();
}
const verbosePrinter = (output) => {
if (verbose) {
cli_1.cli.stream.print(output);
}
};
cli_1.cli.stream.warning('This is a beta feature');
cli_1.cli.stream.hint('Audio echo-cancellation will improve wake word detection and automatic speech recognition performances when music is played via the device.\nIt is a feature of PulseAudio, thus to activate it Sam will also install PulseAudio.');
const answers = yield cli_1.cli.prompt.promptQuestions([
{
name: 'echoCancel',
type: 'confirm',
message: 'Do you wish to proceed?',
},
]);
const hasEchoCancel = answers['echoCancel'];
if (hasEchoCancel) {
try {
try {
if (!verbose) {
cli_1.cli.stream.loading('Setup echo cancellation default');
}
else {
cli_1.cli.stream.println(chalk_1.default.green('Setup echo cancellation default'));
}
const mic = 'alsa_input.platform-soc_sound.analog-stereo';
const speaker = 'alsa_output.platform-soc_sound.analog-stereo';
yield ssh.setupEchoCancel(mic, speaker, verbosePrinter);
if (!verbose)
cli_1.cli.stream.success();
}
catch (e) {
throw new Error('Failed to setup default echo cancellation config');
}
yield new Promise(resolve => setTimeout(resolve, 5000));
let source;
try {
const sources = yield ssh.listPulseSources();
if (sources.length === 1) {
cli_1.cli.stream.success(`Found only 1 capture device named: ${sources[0].description}`);
source = sources[0];
}
else {
const response = yield cli_1.cli.prompt.promptList('device', `Found ${sources.length} interfaces to record sound.\n Choose the one you want to use`, sources.map(device => device.description));
source = sources.find(device => device.description === response['device']);
}
}
catch (e) {
throw new Error('Failed to pick a pulseaudio source');
}
let sink;
try {
const sinks = yield ssh.listPulseSinks();
if (sinks.length === 1) {
cli_1.cli.stream.success(`Found only 1 playback device named: ${sinks[0].description}`);
sink = sinks[0];
}
else {
const response = yield cli_1.cli.prompt.promptList('device', `Found ${sinks.length} interfaces to play sound.\n Choose the one you want to use`, sinks.map(device => device.description));
sink = sinks.find(device => device.description === response['device']);
}
}
catch (e) {
throw new Error('Failed to pick a pulseaudio sink');
}
try {
if (!verbose) {
cli_1.cli.stream.loading('Change PulseAudio settings');
}
else {
cli_1.cli.stream.println(chalk_1.default.green('Change PulseAudio settings'));
}
yield ssh.tuneEchoCancel(source.name, sink.name, verbosePrinter);
if (!verbose)
cli_1.cli.stream.success();
}
catch (e) {
throw new Error('Failed to configure pulseaudio source/sink');
}
}
catch (e) {
cli_1.cli.stream.error(e.message);
ssh.disconnect();
process.exit();
}
cli_1.cli.stream.loading('Restarting snips-audio-server service');
yield ssh.relaunchService(ssh_1.SnipsServices.audioServer).catch(_ => { });
cli_1.cli.stream.done();
cli_1.cli.stream.hint(chalk_1.default `You can test your microphone & speaker with {blue sam test microphone / speaker}`);
}
ssh.disconnect();
});
//# sourceMappingURL=aec.js.map
;