From 237b7a617dbd9e5c7b4377dab3c5f42f092043e1 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Fri, 13 Sep 2019 12:24:54 -0400 Subject: [PATCH] initial commit --- .gitignore | 91 ++++++++++++++++++++++++++++++++++++++++ command-line/main.js | 31 ++++++++++++++ logger/logger.js | 81 +++++++++++++++++++++++++++++++++++ logger/package-lock.json | 18 ++++++++ logger/package.json | 15 +++++++ 5 files changed, 236 insertions(+) create mode 100644 .gitignore create mode 100644 command-line/main.js create mode 100755 logger/logger.js create mode 100644 logger/package-lock.json create mode 100755 logger/package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84a422f --- /dev/null +++ b/.gitignore @@ -0,0 +1,91 @@ +# Audio Files +audio + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ diff --git a/command-line/main.js b/command-line/main.js new file mode 100644 index 0000000..ba31c12 --- /dev/null +++ b/command-line/main.js @@ -0,0 +1,31 @@ +const child_process = require('child_process'); + +// Requirements: +// gstreamer: gst-launch-1.0 +// ffmpeg: ffmpeg + +// gstreamer = audio recording +// see `pacmd list` for audio sources +// -v for verbose output +// $ gst-launch-1.0 -v pulsesrc device = "alsa_output.pci-0000_00_1f.3.analog-stereo.monitor" ! wavenc ! filesink location="output.wav" +function start_recording() { + let device = 'alsa_output.pci-0000_00_1f.3.analog-stereo.monitor'; + let output = 'output.wav'; + let recording_process = child_process.spawn( + 'gst-launch-1.0', [ '-v', 'pulsesrc', 'device', '=', device, '!', 'wavenc', '!', 'filesink', 'location', '=', output ] + ); + return recording_process; +} + +async function stop_recording() { + +} + +// ffmpeg = file conversion (wav -> mp3) +// $ ffmpeg -i output.wav -b:a 192k output.mp3 +// metadata can be added as follows +// $ ffmpeg -i output.wav \ +// -metadata title="Song Name" \ +// -metadata author="Song Artist" \ +// -metadata album="Song Album" \ +// -b:a 192k output.mp3 diff --git a/logger/logger.js b/logger/logger.js new file mode 100755 index 0000000..2c150f6 --- /dev/null +++ b/logger/logger.js @@ -0,0 +1,81 @@ +const moment = require('moment'); +const colors = require('colors/safe'); +const util = require('util'); + +function padCenter(x, p, n) { + x = '' + x; + let z = false; + while (x.length < n) { + if (z) { + z = false; + x = p + x; + } else { + z = true; + x = x + p; + } + } + return x; +} + +function createLogger(name) { + let logger = {}; + function colorize(level, text) { + let map = { + 'error': colors.red, + 'warn': colors.yellow, + 'info': colors.green, + 'debug': colors.blue, + 'silly': colors.magenta, + }; + if (level in map) { + return map[level](text); + } else { + return colors.bgWhite(text); + } + } + logger.log = function(level, message, data) { + let prefix = `[ ${colorize(level, padCenter(level, ' ', 5))} | ${padCenter(name, ' ', 6)} | ${moment().format('HH:mm:ss.SSS')} ]`; + let out = ''; + if (message !== undefined && typeof message !== 'string') { + data = message; + message = null; + } + if (message) { + out += `${prefix}: ${message}`; + } + function handleData(data) { + if (data) { + if (typeof message === 'string') { + out += '\n'; + } + if (data instanceof Error) { + if (data.stack) { + out += `${prefix}# ${data.stack.split('\n').join(`\n${prefix}# `)}`; + } else { + out += `${prefix}# ${data.name}: ${data.message}`; + } + } else { + let s = util.inspect(data, { colors: true }); + s = s.split('\n').map(o => `${prefix}$ ${o}`).join('\n'); + out += s; + //let s = `{${prettyjson.render(data).split('\n').map(o => ' ' + o).join('\n').substring(1)} }`; + //out += `${prefix}$ ${s.split('\n').map(o => colors.italic(o)).join(`\n${prefix}$ `)}`; + } + } + } + if (Array.isArray(data)) { + data.forEach(handleData); + } else { + handleData(data); + } + console.log(out); + } + logger.error = (message, data) => { logger.log('error', message, data); }; + logger.warn = (message, data) => { logger.log('warn', message, data); }; + logger.info = (message, data) => { logger.log('info', message, data); }; + logger.debug = (message, data) => { logger.log('debug', message, data); }; + logger.silly = (message, data) => { logger.log('silly', message, data); }; + return logger; +} + +module.exports = createLogger; \ No newline at end of file diff --git a/logger/package-lock.json b/logger/package-lock.json new file mode 100644 index 0000000..b8cf3ec --- /dev/null +++ b/logger/package-lock.json @@ -0,0 +1,18 @@ +{ + "name": "logger", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "colors": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", + "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==" + }, + "moment": { + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + } + } +} diff --git a/logger/package.json b/logger/package.json new file mode 100755 index 0000000..35e13bd --- /dev/null +++ b/logger/package.json @@ -0,0 +1,15 @@ +{ + "name": "logger", + "version": "1.0.0", + "description": "", + "main": "logger.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "colors": "^1.3.3", + "moment": "^2.24.0" + } +}