npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

megazord-javascript

v1.0.0

Published

Megazord javascript bindings

Downloads

10

Readme

Megazord bindings for javascript

Megazord is a very good fit to embed an assistant in any app: a game or an email app written in Electron, or even a console app written in NodeJS.

Because the Megazord library can run the entire platform, it means that the users of your app do not need to have the Snips platform preinstalled on their device to use your app. It also means that multiple apps running different assistants can all work at the same time.

You can look at the full Megazord and NodeJS documentation on https://docs.snips.ai

Megazord bindings

This library exposes low-level javascript bindings for Megazord, and a helper high-level SnipsPlatform class which makes it easy to load an assistant.

You can compile the bindings using

yarn install
yarn build

To run the code, you need to have libsnips_megazord in your LD_LIBRARY_PATH or DYLD_LIBRARY_PATH for osX

You can install the libraries on osX using brew tap snipsco/homebrew-snips && brew install libsnips_megazord.

You can see where it has been installed using

brew list libsnips_megazord # on osX

Compile with the electron FFI

If you want to use megazord-javascript in an electron app, you need to use the same ffi version as that used by electron

yarn add --dev electron-rebuild
./node_modules/.bin/electron-rebuild

or

HOME=~/.electron-gyp npm rebuild \
    --runtime=electron \
    --target=3.0.8 \
    --disturl=https://atom.io/download/atom-shell \
    --build-from-source \
    --arch=x64 \
    --target-arch=x64

Run tests:

wget https://resources.snips.ai/assistants/assistant-weather-EN-0.19.0-dyn-heysnipsv4.zip
unzip assistant-weather-EN-0.19.0-dyn-heysnipsv4.zip
yarn test

Quickstart

You can find quickstart code in quickstart

const {SnipsPlatform} = require('megazord-javascript');
const mic = require('mic');

const assistant = new SnipsPlatform('assistant', {
    enableSnipsWatch: true,
    enableLogs: false,
});

var _currentSessionId = null;
assistant
    .onIntentDetected((msg, user_data) => {
        console.log('-- intent detected: ' + msg.intent.intent_name);
        console.log(' - input: ' + msg.input);
        _currentSessionId && assistant.endSession(_currentSessionId);
    })
    .onIntentNotRecognized((msg, user_data) => {
        console.log('-- intent not recognized: ' + msg.input);
        _currentSessionId && assistant.endSession(_currentSessionId);
    })
    .onSessionStarted((msg, user_data) => {
        _currentSessionId = msg.session_id;
    })
    .onSessionEnded((msg, user_data) => {
        _currentSessionId = null;
    })
    .onListeningStateChanged((isListening, user_data) => {
        console.log('-- is_listening: ' + isListening);
    })
    .onSnipsWatch((msg, user_data) => {
        console.log('-- snips_watch', msg);
    });

assistant.start();

// stream audio

var micInstance = mic({rate: '16000', channels: '1'});
var micInputStream = micInstance.getAudioStream();

micInputStream.on('data', function(data) {
    const buf = Buffer.from(data);
    assistant.appendBuffer(buf);
});

micInputStream.on('error', function(err) {
    console.error("Error: " + err);
});

micInstance.start();