UNPKG

snips-sam

Version:

The Snips Assistant Manager

40 lines (34 loc) 1.43 kB
import chalk from 'chalk'; import * as yargs from 'yargs'; import { cli } from '../../cli'; import { SSHService } from '../../session/ssh'; export const command = 'microphone'; export const desc = 'Test a microphone'; export const handler = async (argv: yargs.Argv) => { const ssh = new SSHService(); await ssh.connect().catch(e => cli.stream.error(e)); cli.stream.hint('Plug in your microphone and turn on your speaker'); await cli.prompt.waitForKeypress(`Press a key when you're ready...`, () => { cli.stream.stopAndClear(); }); try { const recordingFile = 'sam_recording'; ssh.recordAudio(recordingFile).catch((e) => {}); await cli.prompt.waitForKeypress('Say something in the microphone, then press a key to continue...', () => { cli.stream.success(); }); await ssh.stopRecording(); cli.stream.loading('Playing the recording'); await ssh.playAudio(recordingFile); cli.stream.success(); } catch (e) { cli.stream.stopAndClear(); cli.stream.error('Error testing the microphone: ' + e.message); ssh.disconnect(); process.exit(); } cli.stream.hint(`Didn't hear anything? Check the recording level of your microphone & the volume of the speaker.`); cli.stream.hint(`Alternatively you can run ` + chalk.blue('sam status')); ssh.disconnect(); process.exit(); };