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

@slanglabs/slang-web-sdk

v2.2.15

Published

add voice control to your app

Downloads

109

Readme

slang-web-sdk

slang sdk for the web

Integrating slang on to your webapp/pwa/website

Prerequisites

Before starting with integrating slang with your website using the web-sdk, you must create an application in our console and configure it.

console - https://console.slanglabs.in/home console guide - https://docs.slanglabs.in/vax-docs/getting-started/for-web-apps

Step 1 - Installation

npm packages

If you are using npm packages to manage dependencies then you have to add slang-web-sdk to your project. npm install @slanglabs/slang-web-sdk or yarn add @slanglabs/slang-web-sdk

Then import slang where you want to initialize it import Slang from "@slanglabs/slang-web-sdk";

Step 2 - Initialize slang

Once you have Slang in scope, by following either of the above two methods, you have to initialize Slang, which will add a mic button as an overlay to every page.

Slang.initialize({
    buddyId: “BUDDY_ID_HERE”,
    apiKey: “API_KEY_HERE”,
    env: "stage", // one of ['stage','prod']
    locale: "en-IN", // one of ['en-IN','hi-IN']
    onSuccess: () => {
        console.log("Slang initialized successfully"); // anything you want to do once slang gets init successfully
    },
    onFailure: () => {
        console.log("Slang Failed to initialize");  // anything you want to do once slang fails to init
    }
});

Step 3 - Set intent action handler

Slang has processed whatever the user has spoken and has extracted intent and entities from it. Now you can do whatever action you want to take based on the intent and entities. So you have to provide slang with your function that handles the intent.

the signature of the action handler function is

const intentHandler = (intent) => {}

eg:

const intentHandler = (intent) => {
    switch(intent.name){
        case 'show_balance':
            showBalance()
            return true
        default:
            return false
    }
};

Once you have defined your intent handler, you can register your intent handler with slang by:

Slang.setIntentActionHandler(intentHandler);

Few things to note:

The return value lets slang know wether the action was successfull or not. If successful Slang will speak out the affirmative for that intent, else slang will speak out the negetive.

Slang only considers a explicit return value of false to be failure event. Everything else is considered a success event.

If your action requires a async event (eg. a network call) then you must return a Promise. If the promise rejects then slang considers it a failure event. If the promise resolves then slang checks the return value and proceeds as mentioned above.

Other stuff

Slang.cancel() - programmaticaly cancel the current interaction Slang.changeLocale( locale ) - programmaticaly change the current locale. Supported locales - [en-IN,hi-IN] Slang.triggerSlang() - programmatically trigger slang. Or attach to a elem to make it a trigger. eg elem.onclick = () => {Slang.triggerSlang()} Slang.toggleMute() - toggle mute for slang responses. Starts off unmuted Slang.setASRHints(hints) - hints tells slang there is a higher probability of certain words occuring in this application. Hints are a map of locale to an array of strings. eg:

const hints = {
    "en-IN": ["this","is","a","hint"]
}
Slang.setASRHints(hints);

Slang.startConversation( startStatement, isSpoken ) - programmaticaly start a conversation with a given statement instead of the welcome statement configured in the schema. isSpoken is a boolean flag as to wether slang will speak out the statement or not. You can even start a new conversaion from inside a action handler (in which case slang queues the new conversation and starts it as soon as the current cycle is completed)