@mastra/node-audio
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const main_1 = require("../../main"); | ||
| const stream = (0, main_1.pathUrlOrStreamToStream)("src/examples/playAudio/hello.wav"); | ||
| const outputPath = 'src/examples/createHuddle/output.mp3'; | ||
| const huddle = (0, main_1.createHuddle)({ | ||
| record: { | ||
| outputPath, | ||
| } | ||
| }); | ||
| huddle.on("recorder.start", () => { | ||
| console.log(`Recording to ${outputPath}`); | ||
| }); | ||
| huddle.start(); | ||
| huddle.play(stream); | ||
| huddle.on("start", () => { | ||
| console.log("Huddle started. Ctrl+C to stop."); | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/createHuddle/main.ts"],"names":[],"mappings":";;AAAA,qCAAmE;AAEnE,MAAM,MAAM,GAAG,IAAA,8BAAuB,EAAC,kCAAkC,CAAC,CAAC;AAE3E,MAAM,UAAU,GAAG,sCAAsC,CAAC;AAE1D,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC;IAC1B,MAAM,EAAE;QACN,UAAU;KACX;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,EAAE,CAAC;AAEf,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEpB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACtB,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const main_1 = require("../../main"); | ||
| const stream = (0, main_1.getMicrophoneStream)(); | ||
| const outputPath = 'src/examples/getMicrophoneStream/output.mp3'; | ||
| const recorder = (0, main_1.recordAudioToFile)(stream, { outputPath }); | ||
| recorder.on('start', () => { | ||
| console.log(`Recording to ${outputPath}... Ctrl+C to stop`); | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/getMicrophoneStream/main.ts"],"names":[],"mappings":";;AAAA,qCAAoE;AAEpE,MAAM,MAAM,GAAG,IAAA,0BAAmB,GAAE,CAAC;AAErC,MAAM,UAAU,GAAG,6CAA6C,CAAC;AAEjE,MAAM,QAAQ,GAAG,IAAA,wBAAiB,EAAC,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AAE3D,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,oBAAoB,CAAC,CAAC;AAC9D,CAAC,CAAC,CAAC"} |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const fs_1 = __importDefault(require("fs")); | ||
| const path_1 = __importDefault(require("path")); | ||
| const __dir = path_1.default.resolve(process.cwd(), 'src/examples'); | ||
| async function main() { | ||
| let executed = false; | ||
| const files = await fs_1.default.promises.readdir(__dir, { recursive: true }); | ||
| const example = process.argv[2]; | ||
| const examples = files.filter(file => file.includes('main.ts')).filter(file => file !== 'main.ts'); | ||
| const exampleNames = examples.map(example => path_1.default.basename(example.replace('main.ts', ''))); | ||
| if (!example) { | ||
| console.log('Please provide an example name to run'); | ||
| console.log(exampleNames); | ||
| return; | ||
| } | ||
| for (const file of files) { | ||
| if (file.includes(`${example}/main.ts`)) { | ||
| executed = true; | ||
| console.log(`Executing ${file}`); | ||
| if (typeof require !== 'undefined') { | ||
| // CommonJS | ||
| require(path_1.default.join(__dir, file)); | ||
| } | ||
| else { | ||
| // ESM | ||
| await Promise.resolve(`${path_1.default.join(__dir, file)}`).then(s => __importStar(require(s))); | ||
| } | ||
| } | ||
| } | ||
| if (!executed) { | ||
| console.log(`Example ${example} not found`); | ||
| } | ||
| } | ||
| main(); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/examples/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,MAAM,KAAK,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;AAE1D,KAAK,UAAU,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ACH,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,YAAY,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const main_1 = require("../../main"); | ||
| /** | ||
| * Play an audio file from the local filesystem. | ||
| */ | ||
| (0, main_1.playAudio)("src/examples/playAudio/hello.wav"); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/playAudio/main.ts"],"names":[],"mappings":";;AAAA,qCAAuC;AAEvC;;GAEG;AACH,IAAA,gBAAS,EAAC,kCAAkC,CAAC,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const main_1 = require("../../main"); | ||
| /** | ||
| * Play an audio file from the local filesystem. | ||
| */ | ||
| (0, main_1.playAudio)("https://github.com/mastra-ai/node-audio/raw/refs/heads/main/src/examples/playRemoteAudio/fire-2.wav", { | ||
| bitDepth: 16, | ||
| sampleRate: 48000, // 48kHz | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/playRemoteAudio/main.ts"],"names":[],"mappings":";;AAAA,qCAAuC;AAEvC;;GAEG;AACH,IAAA,gBAAS,EAAC,qGAAqG,EAAE;IAC/G,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,KAAK,EAAE,QAAQ;CAC5B,CAAC,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const utils_1 = require("../../lib/utils"); | ||
| const main_1 = require("../../main"); | ||
| /** | ||
| * Play an audio file from the local filesystem. | ||
| */ | ||
| const stream = (0, utils_1.pathUrlOrStreamToStream)("https://github.com/mastra-ai/node-audio/raw/refs/heads/main/src/examples/playRemoteAudio/fire-2.wav"); | ||
| (0, main_1.recordAudioToFile)(stream, { | ||
| outputPath: "src/examples/recordAudioToFile/output.wav", | ||
| ffmpeg: { | ||
| inputOptions: ["-f", "wav"], | ||
| outputOptions: ["-acodec", "pcm_s16le"], | ||
| }, | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/recordAudioToFile/main.ts"],"names":[],"mappings":";;AAAA,2CAA0D;AAC1D,qCAA+C;AAE/C;;GAEG;AAEH,MAAM,MAAM,GAAG,IAAA,+BAAuB,EAAC,qGAAqG,CAAC,CAAC;AAC9I,IAAA,wBAAiB,EAAC,MAAM,EAAE;IACxB,UAAU,EAAE,2CAA2C;IAEvD,MAAM,EAAE;QACN,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC;QAC3B,aAAa,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC;KACxC;CACF,CAAC,CAAC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createHuddle = createHuddle; | ||
| const node_speaker_1 = __importDefault(require("@mastra/node-speaker")); | ||
| const microphone_1 = require("./microphone"); | ||
| const speaker_1 = require("./speaker"); | ||
| const node_mic_1 = __importDefault(require("node-mic")); | ||
| const recorder_1 = require("./recorder"); | ||
| const events_1 = require("events"); | ||
| class Huddle extends events_1.EventEmitter { | ||
| options; | ||
| mic; | ||
| speaker; | ||
| recorder; | ||
| micStream; | ||
| constructor(options) { | ||
| super(); | ||
| this.options = options; | ||
| } | ||
| makeMic() { | ||
| return new node_mic_1.default({ | ||
| ...microphone_1.defaultMicOptions, | ||
| ...this.options.mic, | ||
| }); | ||
| } | ||
| makeSpeaker() { | ||
| return new node_speaker_1.default({ | ||
| ...speaker_1.defaultSpeakerOptions, | ||
| ...this.options.speaker, | ||
| }); | ||
| } | ||
| makeRecorder() { | ||
| if (this.options.record?.outputPath) { | ||
| return new recorder_1.Recorder({ | ||
| outputPath: this.options.record.outputPath, | ||
| }); | ||
| } | ||
| } | ||
| start() { | ||
| if (this.mic) { | ||
| throw new Error("Huddle already started"); | ||
| } | ||
| this.mic = this.makeMic(); | ||
| this.recorder = this.makeRecorder(); | ||
| if (this.recorder) { | ||
| this.recorder.on("error", (error) => { | ||
| this.emit("recorder.error", error); | ||
| this.emit("error", error); | ||
| }); | ||
| this.recorder?.on('start', () => { | ||
| this.emit('recorder.start'); | ||
| this.emit('start'); | ||
| }); | ||
| this.recorder?.on('end', () => { | ||
| this.emit('recorder.end'); | ||
| }); | ||
| } | ||
| else { | ||
| this.emit('start'); | ||
| } | ||
| this.mic.start(); | ||
| this.micStream = this.mic.getAudioStream(); | ||
| if (this.recorder) { | ||
| this.recorder.start(); | ||
| this.micStream.pipe(this.recorder.stream, { end: false }); | ||
| } | ||
| } | ||
| stop() { | ||
| this.mic?.stop(); | ||
| this.speaker?.close(true); | ||
| this.recorder?.stream.end(); | ||
| } | ||
| interrupt() { | ||
| if (this.speaker) { | ||
| this.speaker.close(true); | ||
| this.speaker = undefined; | ||
| } | ||
| } | ||
| play(stream) { | ||
| if (this.speaker) { | ||
| this.speaker.removeAllListeners(); | ||
| this.speaker.close(true); | ||
| } | ||
| this.emit("mic.pause"); | ||
| this.mic?.pause(); | ||
| this.speaker = this.makeSpeaker(); | ||
| stream.pipe(this.speaker); | ||
| stream.on("data", (chunk) => { | ||
| this.recorder?.write(chunk); | ||
| }); | ||
| this.speaker.on("error", (error) => { | ||
| this.emit("speaker.error", error); | ||
| this.emit("error", error); | ||
| }); | ||
| this.speaker.once("close", () => { | ||
| this.emit("mic.resume"); | ||
| this.mic?.resume(); | ||
| }); | ||
| } | ||
| getMicrophoneStream() { | ||
| if (!this.micStream) { | ||
| throw new Error("Huddle not started yet"); | ||
| } | ||
| return this.micStream; | ||
| } | ||
| } | ||
| function createHuddle(options) { | ||
| return new Huddle(options); | ||
| } | ||
| //# source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CAAC;CACF;AAED,SAAgB,YAAY,CAAC,OAAsB;IACjD,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.defaultMicOptions = void 0; | ||
| exports.getMicrophoneStream = getMicrophoneStream; | ||
| const node_mic_1 = __importDefault(require("node-mic")); | ||
| exports.defaultMicOptions = { | ||
| rate: 24100, | ||
| }; | ||
| function getMicrophoneStream(options = exports.defaultMicOptions) { | ||
| const mic = new node_mic_1.default(options); | ||
| mic.start(); | ||
| return mic.getAudioStream(); | ||
| } | ||
| //# sourceMappingURL=microphone.js.map |
| {"version":3,"file":"microphone.js","sourceRoot":"","sources":["../../../src/lib/microphone.ts"],"names":[],"mappings":";;;;;;AAMA,kDAMC;AAZD,wDAA+C;AAElC,QAAA,iBAAiB,GAAwB;IACpD,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF,SAAgB,mBAAmB,CAAC,UAA+B,yBAAiB;IAClF,MAAM,GAAG,GAAG,IAAI,kBAAO,CAAC,OAAO,CAAC,CAAC;IAEjC,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,OAAO,GAAG,CAAC,cAAc,EAAE,CAAC;AAC9B,CAAC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Recorder = exports.defaultFfmpegOptions = void 0; | ||
| exports.recordAudioToFile = recordAudioToFile; | ||
| const ffmpeg_1 = __importDefault(require("@ffmpeg-installer/ffmpeg")); | ||
| const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg")); | ||
| const fluent_ffmpeg_multistream_1 = require("fluent-ffmpeg-multistream"); | ||
| const stream_1 = require("stream"); | ||
| const events_1 = require("events"); | ||
| fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_1.default.path); | ||
| exports.defaultFfmpegOptions = { | ||
| inputOptions: ["-f s16le", "-ar 24k", "-ac 1"], | ||
| outputOptions: [], // ["-c:a libmp3lame", "-b:a 128k"] | ||
| }; | ||
| class Recorder extends events_1.EventEmitter { | ||
| options; | ||
| stream; | ||
| ffmpeg = exports.defaultFfmpegOptions; | ||
| constructor(options) { | ||
| super(); | ||
| this.options = options; | ||
| this.stream = new stream_1.PassThrough(); | ||
| if (options.ffmpeg?.inputOptions) { | ||
| this.ffmpeg.inputOptions = options.ffmpeg.inputOptions; | ||
| } | ||
| if (options.ffmpeg?.outputOptions) { | ||
| this.ffmpeg.outputOptions = options.ffmpeg.outputOptions; | ||
| } | ||
| } | ||
| start() { | ||
| const proc = (0, fluent_ffmpeg_1.default)() | ||
| .addInput(new fluent_ffmpeg_multistream_1.StreamInput(this.stream).url) | ||
| .addInputOptions(this.ffmpeg.inputOptions || []) | ||
| .outputOptions(this.ffmpeg.outputOptions || []) | ||
| .on('start', () => { | ||
| this.emit('start'); | ||
| }) | ||
| .on('progress', (progress) => { | ||
| this.emit('progress', progress); | ||
| }) | ||
| .on('end', () => { | ||
| this.emit('end'); | ||
| }) | ||
| .on('error', (err) => { | ||
| this.emit('error', err); | ||
| }) | ||
| .output(this.options.outputPath); // Specify the output file path | ||
| proc.run(); | ||
| } | ||
| write(data) { | ||
| this.stream.write(data); | ||
| } | ||
| } | ||
| exports.Recorder = Recorder; | ||
| function recordAudioToFile(stream, options) { | ||
| const recorder = new Recorder(options); | ||
| recorder.start(); | ||
| stream.pipe(recorder.stream); | ||
| return recorder; | ||
| } | ||
| //# sourceMappingURL=recorder.js.map |
| {"version":3,"file":"recorder.js","sourceRoot":"","sources":["../../../src/lib/recorder.ts"],"names":[],"mappings":";;;;;;AA+EA,8CAKC;AApFD,sEAAkD;AAClD,kEAAmC;AACnC,yEAAwD;AACxD,mCAAqC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AC,CAAC;QAClC,CAAC,CAAC;aACD,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,+BAA+B;QAEnE,IAAI,CAAC,GAAG,EAAE,CAAA;IACZ,CAAC;IAED,KAAK,CAAE,IAAY;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAzCD,4BAyCC;AAGD,SAAgB,iBAAiB,CAAC,MAA6B,EAAE,OAAwB;IACvF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,QAAQ,CAAC;AAClB,CAAC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.defaultSpeakerOptions = void 0; | ||
| exports.playAudio = playAudio; | ||
| const node_speaker_1 = __importDefault(require("@mastra/node-speaker")); | ||
| const utils_1 = require("./utils"); | ||
| exports.defaultSpeakerOptions = { | ||
| sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro | ||
| bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution) | ||
| channels: 1, // Mono audio output (as opposed to stereo which would be 2), | ||
| }; | ||
| function playAudio(pathUrlOrStream, options = exports.defaultSpeakerOptions) { | ||
| const stream = (0, utils_1.pathUrlOrStreamToStream)(pathUrlOrStream); | ||
| const speaker = new node_speaker_1.default(options); | ||
| stream.pipe(speaker); | ||
| return speaker; | ||
| } | ||
| //# sourceMappingURL=speaker.js.map |
| {"version":3,"file":"speaker.js","sourceRoot":"","sources":["../../../src/lib/speaker.ts"],"names":[],"mappings":";;;;;;AASA,8BAKC;AAdD,wEAA2C;AAC3C,mCAAkD;AAErC,QAAA,qBAAqB,GAAoB;IACpD,UAAU,EAAE,KAAK,EAAG,2EAA2E;IAC/F,QAAQ,EAAE,EAAE,EAAQ,wEAAwE;IAC5F,QAAQ,EAAE,CAAC,EAAS,6DAA6D;CAClF,CAAC;AAEF,SAAgB,SAAS,CAAC,eAA+C,EAAE,UAA2B,6BAAqB;IACzH,MAAM,MAAM,GAAG,IAAA,+BAAuB,EAAC,eAAe,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,IAAI,sBAAO,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isUrl = isUrl; | ||
| exports.isPath = isPath; | ||
| exports.isStream = isStream; | ||
| exports.pathUrlOrStreamToStream = pathUrlOrStreamToStream; | ||
| const stream_1 = require("stream"); | ||
| const promises_1 = require("stream/promises"); | ||
| const fs_1 = require("fs"); | ||
| function isUrl(pathUrlOrStream) { | ||
| return typeof pathUrlOrStream === "string" && pathUrlOrStream.startsWith("http"); | ||
| } | ||
| function isPath(pathUrlOrStream) { | ||
| return typeof pathUrlOrStream === "string"; | ||
| } | ||
| function isStream(pathUrlOrStream) { | ||
| return typeof pathUrlOrStream === "object" && pathUrlOrStream !== null && "pipe" in pathUrlOrStream; | ||
| } | ||
| function pathUrlOrStreamToStream(pathUrlOrStream) { | ||
| if (isUrl(pathUrlOrStream)) { | ||
| const stream = new stream_1.PassThrough(); | ||
| fetch(pathUrlOrStream).then(response => { | ||
| if (response.ok && response.body) { | ||
| (0, promises_1.pipeline)(response.body, stream); | ||
| } | ||
| else { | ||
| throw new Error("Failed to fetch audio file"); | ||
| } | ||
| }).catch(error => { | ||
| stream.emit("error", error); | ||
| }); | ||
| return stream; | ||
| } | ||
| else if (isPath(pathUrlOrStream)) { | ||
| return (0, fs_1.createReadStream)(pathUrlOrStream); | ||
| } | ||
| else if (isStream(pathUrlOrStream)) { | ||
| return pathUrlOrStream; | ||
| } | ||
| else { | ||
| throw new Error("Invalid path, url, or stream"); | ||
| } | ||
| } | ||
| //# sourceMappingURL=utils.js.map |
| {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":";;AAGA,sBAEC;AAED,wBAEC;AAED,4BAEC;AAED,0DAsBC;AArCD,mCAAqC;AACrC,8CAA2C;AAC3C,2BAAsC;AACtC,SAAgB,KAAK,CAAC,eAA+C;IACnE,OAAO,OAAO,eAAe,KAAK,QAAQ,IAAI,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACnF,CAAC;AAED,SAAgB,MAAM,CAAC,eAA+C;IACpE,OAAO,OAAO,eAAe,KAAK,QAAQ,CAAC;AAC7C,CAAC;AAED,SAAgB,QAAQ,CAAC,eAA+C;IACtE,OAAO,OAAO,eAAe,KAAK,QAAQ,IAAI,eAAe,KAAK,IAAI,IAAI,MAAM,IAAI,eAAe,CAAC;AACtG,CAAC;AAED,SAAgB,uBAAuB,CAAC,eAA+C;IACrF,IAAI,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,oBAAW,EAAE,CAAC;QAEjC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACrC,IAAI,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACjC,IAAA,mBAAQ,EAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAChD,CAAC;QACH,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACf,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;SAAM,IAAI,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC;QACnC,OAAO,IAAA,qBAAgB,EAAC,eAAe,CAAC,CAAC;IAC3C,CAAC;SAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QACrC,OAAO,eAAe,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.pathUrlOrStreamToStream = exports.createHuddle = exports.recordAudioToFile = exports.playAudio = exports.getMicrophoneStream = void 0; | ||
| var microphone_1 = require("./lib/microphone"); | ||
| Object.defineProperty(exports, "getMicrophoneStream", { enumerable: true, get: function () { return microphone_1.getMicrophoneStream; } }); | ||
| var speaker_1 = require("./lib/speaker"); | ||
| Object.defineProperty(exports, "playAudio", { enumerable: true, get: function () { return speaker_1.playAudio; } }); | ||
| var recorder_1 = require("./lib/recorder"); | ||
| Object.defineProperty(exports, "recordAudioToFile", { enumerable: true, get: function () { return recorder_1.recordAudioToFile; } }); | ||
| var huddle_1 = require("./lib/huddle"); | ||
| Object.defineProperty(exports, "createHuddle", { enumerable: true, get: function () { return huddle_1.createHuddle; } }); | ||
| var utils_1 = require("./lib/utils"); | ||
| Object.defineProperty(exports, "pathUrlOrStreamToStream", { enumerable: true, get: function () { return utils_1.pathUrlOrStreamToStream; } }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAA9C,iHAAA,mBAAmB,OAAA;AAC5B,yCAA0C;AAAjC,oGAAA,SAAS,OAAA;AAClB,2CAAmD;AAA1C,6GAAA,iBAAiB,OAAA;AAC1B,uCAA4C;AAAnC,sGAAA,YAAY,OAAA;AACrB,qCAAsD;AAA7C,gHAAA,uBAAuB,OAAA"} |
| import { createHuddle, pathUrlOrStreamToStream } from "../../main"; | ||
| const stream = pathUrlOrStreamToStream("src/examples/playAudio/hello.wav"); | ||
| const outputPath = 'src/examples/createHuddle/output.mp3'; | ||
| const huddle = createHuddle({ | ||
| record: { | ||
| outputPath, | ||
| } | ||
| }); | ||
| huddle.on("recorder.start", () => { | ||
| console.log(`Recording to ${outputPath}`); | ||
| }); | ||
| huddle.start(); | ||
| huddle.play(stream); | ||
| huddle.on("start", () => { | ||
| console.log("Huddle started. Ctrl+C to stop."); | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/createHuddle/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,MAAM,GAAG,uBAAuB,CAAC,kCAAkC,CAAC,CAAC;AAE3E,MAAM,UAAU,GAAG,sCAAsC,CAAC;AAE1D,MAAM,MAAM,GAAG,YAAY,CAAC;IAC1B,MAAM,EAAE;QACN,UAAU;KACX;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,EAAE,CAAC;AAEf,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEpB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACtB,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC"} |
| import { getMicrophoneStream, recordAudioToFile } from "../../main"; | ||
| const stream = getMicrophoneStream(); | ||
| const outputPath = 'src/examples/getMicrophoneStream/output.mp3'; | ||
| const recorder = recordAudioToFile(stream, { outputPath }); | ||
| recorder.on('start', () => { | ||
| console.log(`Recording to ${outputPath}... Ctrl+C to stop`); | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/getMicrophoneStream/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;AAErC,MAAM,UAAU,GAAG,6CAA6C,CAAC;AAEjE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AAE3D,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,gBAAgB,UAAU,oBAAoB,CAAC,CAAC;AAC9D,CAAC,CAAC,CAAC"} |
| import fs from "fs"; | ||
| import path from "path"; | ||
| const __dir = path.resolve(process.cwd(), 'src/examples'); | ||
| async function main() { | ||
| let executed = false; | ||
| const files = await fs.promises.readdir(__dir, { recursive: true }); | ||
| const example = process.argv[2]; | ||
| const examples = files.filter(file => file.includes('main.ts')).filter(file => file !== 'main.ts'); | ||
| const exampleNames = examples.map(example => path.basename(example.replace('main.ts', ''))); | ||
| if (!example) { | ||
| console.log('Please provide an example name to run'); | ||
| console.log(exampleNames); | ||
| return; | ||
| } | ||
| for (const file of files) { | ||
| if (file.includes(`${example}/main.ts`)) { | ||
| executed = true; | ||
| console.log(`Executing ${file}`); | ||
| if (typeof require !== 'undefined') { | ||
| // CommonJS | ||
| require(path.join(__dir, file)); | ||
| } | ||
| else { | ||
| // ESM | ||
| await import(path.join(__dir, file)); | ||
| } | ||
| } | ||
| } | ||
| if (!executed) { | ||
| console.log(`Example ${example} not found`); | ||
| } | ||
| } | ||
| main(); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/examples/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;AAE1D,KAAK,UAAU,IAAI;IACjB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEhC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACnG,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAE5F,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC1B,OAAO;IACT,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,OAAO,UAAU,CAAC,EAAE,CAAC;YACxC,QAAQ,GAAG,IAAI,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;YACjC,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;gBACnC,WAAW;gBACX,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,MAAM;gBACN,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,YAAY,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"} |
| import { playAudio } from "../../main"; | ||
| /** | ||
| * Play an audio file from the local filesystem. | ||
| */ | ||
| playAudio("src/examples/playAudio/hello.wav"); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/playAudio/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,SAAS,CAAC,kCAAkC,CAAC,CAAC"} |
| import { playAudio } from "../../main"; | ||
| /** | ||
| * Play an audio file from the local filesystem. | ||
| */ | ||
| playAudio("https://github.com/mastra-ai/node-audio/raw/refs/heads/main/src/examples/playRemoteAudio/fire-2.wav", { | ||
| bitDepth: 16, | ||
| sampleRate: 48000, // 48kHz | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/playRemoteAudio/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,SAAS,CAAC,qGAAqG,EAAE;IAC/G,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,KAAK,EAAE,QAAQ;CAC5B,CAAC,CAAC"} |
| import { pathUrlOrStreamToStream } from "../../lib/utils"; | ||
| import { recordAudioToFile } from "../../main"; | ||
| /** | ||
| * Play an audio file from the local filesystem. | ||
| */ | ||
| const stream = pathUrlOrStreamToStream("https://github.com/mastra-ai/node-audio/raw/refs/heads/main/src/examples/playRemoteAudio/fire-2.wav"); | ||
| recordAudioToFile(stream, { | ||
| outputPath: "src/examples/recordAudioToFile/output.wav", | ||
| ffmpeg: { | ||
| inputOptions: ["-f", "wav"], | ||
| outputOptions: ["-acodec", "pcm_s16le"], | ||
| }, | ||
| }); | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/examples/recordAudioToFile/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AAEH,MAAM,MAAM,GAAG,uBAAuB,CAAC,qGAAqG,CAAC,CAAC;AAC9I,iBAAiB,CAAC,MAAM,EAAE;IACxB,UAAU,EAAE,2CAA2C;IAEvD,MAAM,EAAE;QACN,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC;QAC3B,aAAa,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC;KACxC;CACF,CAAC,CAAC"} |
| import Speaker from "@mastra/node-speaker"; | ||
| import { defaultMicOptions } from "./microphone"; | ||
| import { defaultSpeakerOptions } from "./speaker"; | ||
| import NodeMic from "node-mic"; | ||
| import { Recorder } from "./recorder"; | ||
| import { EventEmitter } from "events"; | ||
| class Huddle extends EventEmitter { | ||
| options; | ||
| mic; | ||
| speaker; | ||
| recorder; | ||
| micStream; | ||
| constructor(options) { | ||
| super(); | ||
| this.options = options; | ||
| } | ||
| makeMic() { | ||
| return new NodeMic({ | ||
| ...defaultMicOptions, | ||
| ...this.options.mic, | ||
| }); | ||
| } | ||
| makeSpeaker() { | ||
| return new Speaker({ | ||
| ...defaultSpeakerOptions, | ||
| ...this.options.speaker, | ||
| }); | ||
| } | ||
| makeRecorder() { | ||
| if (this.options.record?.outputPath) { | ||
| return new Recorder({ | ||
| outputPath: this.options.record.outputPath, | ||
| }); | ||
| } | ||
| } | ||
| start() { | ||
| if (this.mic) { | ||
| throw new Error("Huddle already started"); | ||
| } | ||
| this.mic = this.makeMic(); | ||
| this.recorder = this.makeRecorder(); | ||
| if (this.recorder) { | ||
| this.recorder.on("error", (error) => { | ||
| this.emit("recorder.error", error); | ||
| this.emit("error", error); | ||
| }); | ||
| this.recorder?.on('start', () => { | ||
| this.emit('recorder.start'); | ||
| this.emit('start'); | ||
| }); | ||
| this.recorder?.on('end', () => { | ||
| this.emit('recorder.end'); | ||
| }); | ||
| } | ||
| else { | ||
| this.emit('start'); | ||
| } | ||
| this.mic.start(); | ||
| this.micStream = this.mic.getAudioStream(); | ||
| if (this.recorder) { | ||
| this.recorder.start(); | ||
| this.micStream.pipe(this.recorder.stream, { end: false }); | ||
| } | ||
| } | ||
| stop() { | ||
| this.mic?.stop(); | ||
| this.speaker?.close(true); | ||
| this.recorder?.stream.end(); | ||
| } | ||
| interrupt() { | ||
| if (this.speaker) { | ||
| this.speaker.close(true); | ||
| this.speaker = undefined; | ||
| } | ||
| } | ||
| play(stream) { | ||
| if (this.speaker) { | ||
| this.speaker.removeAllListeners(); | ||
| this.speaker.close(true); | ||
| } | ||
| this.emit("mic.pause"); | ||
| this.mic?.pause(); | ||
| this.speaker = this.makeSpeaker(); | ||
| stream.pipe(this.speaker); | ||
| stream.on("data", (chunk) => { | ||
| this.recorder?.write(chunk); | ||
| }); | ||
| this.speaker.on("error", (error) => { | ||
| this.emit("speaker.error", error); | ||
| this.emit("error", error); | ||
| }); | ||
| this.speaker.once("close", () => { | ||
| this.emit("mic.resume"); | ||
| this.mic?.resume(); | ||
| }); | ||
| } | ||
| getMicrophoneStream() { | ||
| if (!this.micStream) { | ||
| throw new Error("Huddle not started yet"); | ||
| } | ||
| return this.micStream; | ||
| } | ||
| } | ||
| export function createHuddle(options) { | ||
| return new Huddle(options); | ||
| } | ||
| //# sourceMappingURL=huddle.js.map |
| {"version":3,"file":"huddle.js","sourceRoot":"","sources":["../../../src/lib/huddle.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,OAAuB,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAqBtC,MAAM,MAAO,SAAQ,YAA0B;IAM1B;IALX,GAAG,CAAW;IACd,OAAO,CAAW;IAClB,QAAQ,CAAY;IACpB,SAAS,CAAyB;IAE1C,YAAmB,OAAsB;QACvC,KAAK,EAAE,CAAC;QADS,YAAO,GAAP,OAAO,CAAe;IAEzC,CAAC;IAEO,OAAO;QACb,OAAO,IAAI,OAAO,CAAC;YACjB,GAAG,iBAAiB;YACpB,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG;SACpB,CAAC,CAAC;IACL,CAAC;IAEO,WAAW;QACjB,OAAO,IAAI,OAAO,CAAC;YACjB,GAAG,qBAAqB;YACxB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO;SACxB,CAAC,CAAC;IACL,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;YACpC,OAAO,IAAI,QAAQ,CAAC;gBAClB,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU;aAC3C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CA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O,EAAE,GAAG,EAAE;YAC9B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACxB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,mBAAmB;QACxB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"} |
| import NodeMic from "node-mic"; | ||
| export const defaultMicOptions = { | ||
| rate: 24100, | ||
| }; | ||
| export function getMicrophoneStream(options = defaultMicOptions) { | ||
| const mic = new NodeMic(options); | ||
| mic.start(); | ||
| return mic.getAudioStream(); | ||
| } | ||
| //# sourceMappingURL=microphone.js.map |
| {"version":3,"file":"microphone.js","sourceRoot":"","sources":["../../../src/lib/microphone.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuB,MAAM,UAAU,CAAC;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAwB;IACpD,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,UAA+B,iBAAiB;IAClF,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjC,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,OAAO,GAAG,CAAC,cAAc,EAAE,CAAC;AAC9B,CAAC"} |
| import ffmpegPath from "@ffmpeg-installer/ffmpeg"; | ||
| import ffmpeg from "fluent-ffmpeg"; | ||
| import { StreamInput } from "fluent-ffmpeg-multistream"; | ||
| import { PassThrough } from "stream"; | ||
| import { EventEmitter } from "events"; | ||
| ffmpeg.setFfmpegPath(ffmpegPath.path); | ||
| export const defaultFfmpegOptions = { | ||
| inputOptions: ["-f s16le", "-ar 24k", "-ac 1"], | ||
| outputOptions: [], // ["-c:a libmp3lame", "-b:a 128k"] | ||
| }; | ||
| export class Recorder extends EventEmitter { | ||
| options; | ||
| stream; | ||
| ffmpeg = defaultFfmpegOptions; | ||
| constructor(options) { | ||
| super(); | ||
| this.options = options; | ||
| this.stream = new PassThrough(); | ||
| if (options.ffmpeg?.inputOptions) { | ||
| this.ffmpeg.inputOptions = options.ffmpeg.inputOptions; | ||
| } | ||
| if (options.ffmpeg?.outputOptions) { | ||
| this.ffmpeg.outputOptions = options.ffmpeg.outputOptions; | ||
| } | ||
| } | ||
| start() { | ||
| const proc = ffmpeg() | ||
| .addInput(new StreamInput(this.stream).url) | ||
| .addInputOptions(this.ffmpeg.inputOptions || []) | ||
| .outputOptions(this.ffmpeg.outputOptions || []) | ||
| .on('start', () => { | ||
| this.emit('start'); | ||
| }) | ||
| .on('progress', (progress) => { | ||
| this.emit('progress', progress); | ||
| }) | ||
| .on('end', () => { | ||
| this.emit('end'); | ||
| }) | ||
| .on('error', (err) => { | ||
| this.emit('error', err); | ||
| }) | ||
| .output(this.options.outputPath); // Specify the output file path | ||
| proc.run(); | ||
| } | ||
| write(data) { | ||
| this.stream.write(data); | ||
| } | ||
| } | ||
| export function recordAudioToFile(stream, options) { | ||
| const recorder = new Recorder(options); | ||
| recorder.start(); | ||
| stream.pipe(recorder.stream); | ||
| return recorder; | ||
| } | ||
| //# sourceMappingURL=recorder.js.map |
| {"version":3,"file":"recorder.js","sourceRoot":"","sources":["../../../src/lib/recorder.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,CAAC,aAAa,CAAC,UA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KAAK,EAAE,GAAG,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,+BAA+B;QAEnE,IAAI,CAAC,GAAG,EAAE,CAAA;IACZ,CAAC;IAED,KAAK,CAAE,IAAY;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAGD,MAAM,UAAU,iBAAiB,CAAC,MAA6B,EAAE,OAAwB;IACvF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,QAAQ,CAAC;AAClB,CAAC"} |
| import Speaker from "@mastra/node-speaker"; | ||
| import { pathUrlOrStreamToStream } from "./utils"; | ||
| export const defaultSpeakerOptions = { | ||
| sampleRate: 24100, // Audio sample rate in Hz - standard for high-quality audio on MacBook Pro | ||
| bitDepth: 16, // Bit depth for audio quality - CD quality standard (16-bit resolution) | ||
| channels: 1, // Mono audio output (as opposed to stereo which would be 2), | ||
| }; | ||
| export function playAudio(pathUrlOrStream, options = defaultSpeakerOptions) { | ||
| const stream = pathUrlOrStreamToStream(pathUrlOrStream); | ||
| const speaker = new Speaker(options); | ||
| stream.pipe(speaker); | ||
| return speaker; | ||
| } | ||
| //# sourceMappingURL=speaker.js.map |
| {"version":3,"file":"speaker.js","sourceRoot":"","sources":["../../../src/lib/speaker.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,CAAC,MAAM,qBAAqB,GAAoB;IACpD,UAAU,EAAE,KAAK,EAAG,2EAA2E;IAC/F,QAAQ,EAAE,EAAE,EAAQ,wEAAwE;IAC5F,QAAQ,EAAE,CAAC,EAAS,6DAA6D;CAClF,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,eAA+C,EAAE,UAA2B,qBAAqB;IACzH,MAAM,MAAM,GAAG,uBAAuB,CAAC,eAAe,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC"} |
| import { PassThrough } from "stream"; | ||
| import { pipeline } from "stream/promises"; | ||
| import { createReadStream } from "fs"; | ||
| export function isUrl(pathUrlOrStream) { | ||
| return typeof pathUrlOrStream === "string" && pathUrlOrStream.startsWith("http"); | ||
| } | ||
| export function isPath(pathUrlOrStream) { | ||
| return typeof pathUrlOrStream === "string"; | ||
| } | ||
| export function isStream(pathUrlOrStream) { | ||
| return typeof pathUrlOrStream === "object" && pathUrlOrStream !== null && "pipe" in pathUrlOrStream; | ||
| } | ||
| export function pathUrlOrStreamToStream(pathUrlOrStream) { | ||
| if (isUrl(pathUrlOrStream)) { | ||
| const stream = new PassThrough(); | ||
| fetch(pathUrlOrStream).then(response => { | ||
| if (response.ok && response.body) { | ||
| pipeline(response.body, stream); | ||
| } | ||
| else { | ||
| throw new Error("Failed to fetch audio file"); | ||
| } | ||
| }).catch(error => { | ||
| stream.emit("error", error); | ||
| }); | ||
| return stream; | ||
| } | ||
| else if (isPath(pathUrlOrStream)) { | ||
| return createReadStream(pathUrlOrStream); | ||
| } | ||
| else if (isStream(pathUrlOrStream)) { | ||
| return pathUrlOrStream; | ||
| } | ||
| else { | ||
| throw new Error("Invalid path, url, or stream"); | ||
| } | ||
| } | ||
| //# sourceM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AAC,EAAE,CAAC;QACnC,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC3C,CAAC;SAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QACrC,OAAO,eAAe,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"} |
| export { getMicrophoneStream } from "./lib/microphone"; | ||
| export { playAudio } from "./lib/speaker"; | ||
| export { recordAudioToFile } from "./lib/recorder"; | ||
| export { createHuddle } from "./lib/huddle"; | ||
| export { pathUrlOrStreamToStream } from "./lib/utils"; | ||
| //# sourceMappingURL=main.js.map |
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"} |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| export {}; |
| import Speaker from "@mastra/node-speaker"; | ||
| import { MicOptions } from "node-mic"; | ||
| import { RecorderOptions } from "./recorder"; | ||
| import { EventEmitter } from "events"; | ||
| export type HuddleOptions = { | ||
| mic?: Partial<MicOptions>; | ||
| speaker?: Speaker.Options; | ||
| record?: RecorderOptions; | ||
| }; | ||
| export type HuddleEvents = { | ||
| start: []; | ||
| stop: []; | ||
| error: [Error]; | ||
| "mic.pause": []; | ||
| "mic.resume": []; | ||
| "mic.error": [Error]; | ||
| "speaker.error": [Error]; | ||
| "recorder.start": []; | ||
| "recorder.end": []; | ||
| "recorder.error": [Error]; | ||
| }; | ||
| declare class Huddle extends EventEmitter<HuddleEvents> { | ||
| options: HuddleOptions; | ||
| private mic?; | ||
| private speaker?; | ||
| private recorder?; | ||
| private micStream?; | ||
| constructor(options: HuddleOptions); | ||
| private makeMic; | ||
| private makeSpeaker; | ||
| private makeRecorder; | ||
| start(): void; | ||
| stop(): void; | ||
| interrupt(): void; | ||
| play(stream: NodeJS.ReadableStream): void; | ||
| getMicrophoneStream(): NodeJS.ReadableStream; | ||
| } | ||
| export declare function createHuddle(options: HuddleOptions): Huddle; | ||
| export {}; |
| import { MicOptions } from "node-mic"; | ||
| export declare const defaultMicOptions: Partial<MicOptions>; | ||
| export declare function getMicrophoneStream(options?: Partial<MicOptions>): NodeJS.ReadableStream; |
| import { EventEmitter } from "events"; | ||
| export declare const defaultFfmpegOptions: { | ||
| inputOptions: string[]; | ||
| outputOptions: string[]; | ||
| }; | ||
| export type RecorderOptions = { | ||
| outputPath: string; | ||
| ffmpeg?: { | ||
| inputOptions?: string[]; | ||
| outputOptions?: string[]; | ||
| }; | ||
| }; | ||
| export type RecorderEvents = { | ||
| start: []; | ||
| end: []; | ||
| progress: [ | ||
| { | ||
| frames: number; | ||
| currentFps: number; | ||
| currentKbps: number; | ||
| targetSize: number; | ||
| timemark: string; | ||
| percent?: number | undefined; | ||
| } | ||
| ]; | ||
| error: [Error]; | ||
| }; | ||
| export declare class Recorder extends EventEmitter<RecorderEvents> { | ||
| options: RecorderOptions; | ||
| stream: NodeJS.WritableStream; | ||
| ffmpeg: { | ||
| inputOptions: string[]; | ||
| outputOptions: string[]; | ||
| }; | ||
| constructor(options: RecorderOptions); | ||
| start(): void; | ||
| write(data: Buffer): void; | ||
| } | ||
| export declare function recordAudioToFile(stream: NodeJS.ReadableStream, options: RecorderOptions): Recorder; |
| import Speaker from "@mastra/node-speaker"; | ||
| export declare const defaultSpeakerOptions: Speaker.Options; | ||
| export declare function playAudio(pathUrlOrStream: string | NodeJS.ReadableStream, options?: Speaker.Options): Speaker; |
| export declare function isUrl(pathUrlOrStream: string | NodeJS.ReadableStream): pathUrlOrStream is string; | ||
| export declare function isPath(pathUrlOrStream: string | NodeJS.ReadableStream): pathUrlOrStream is string; | ||
| export declare function isStream(pathUrlOrStream: string | NodeJS.ReadableStream): pathUrlOrStream is NodeJS.ReadableStream; | ||
| export declare function pathUrlOrStreamToStream(pathUrlOrStream: string | NodeJS.ReadableStream): NodeJS.ReadableStream; |
| export { getMicrophoneStream } from "./lib/microphone"; | ||
| export { playAudio } from "./lib/speaker"; | ||
| export { recordAudioToFile } from "./lib/recorder"; | ||
| export { createHuddle } from "./lib/huddle"; | ||
| export { pathUrlOrStreamToStream } from "./lib/utils"; |
+7
-2
| { | ||
| "name": "@mastra/node-audio", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "description": "Cross-platform mic/audio recording + playback for Mastra in Node.js", | ||
@@ -13,2 +13,7 @@ "main": "./dist/cjs/main.js", | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "src", | ||
| "README.md" | ||
| ], | ||
| "type": "module", | ||
@@ -34,2 +39,2 @@ "scripts": { | ||
| } | ||
| } | ||
| } |
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist/cjs", | ||
| "module": "CommonJS" | ||
| } | ||
| } |
| { | ||
| "compilerOptions": { | ||
| "outDir": "./dist/esm", | ||
| "module": "ESNext", | ||
| "target": "ES2022", | ||
| "moduleResolution": "node", | ||
| "declaration": true, | ||
| "declarationDir": "./dist/types", | ||
| "sourceMap": true, | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "skipLibCheck": true, | ||
| "resolveJsonModule": true, | ||
| "rootDir": "./src" | ||
| }, | ||
| "include": ["src"] | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11654023
0.43%77
305.26%1134
220.34%12
140%4
300%