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

botbuilder-calling-speech

v1.0.21

Published

Dialog extensions for botbuilder-calling to manage speech-to-text and language understanding

Downloads

21

Readme

Installation

npm install --save botbuilder-calling-speech

Peer dependencies

npm install --save botbuilder-calling cognitive-speech-client cognitive-luis-client

Usage

TypeScript

Sample bot

Use the static methods of SpeechDialog to prompt the caller to either understandSpeech() (speech-to-text and LUIS) or recognizeSpeech() (just speech-to-text). These methods extend the functionality of the built in Prompts class.

import { SpeechDialog, speechLibrary } from 'botbuilder-calling-speech';
import { UniversalCallBot } from 'botbuilder-calling';
import { SpeechAuthClient, SpeechClient, SpeechResult } from 'cognitive-speech-client';
import { LuisClient, LuisResult } from 'cognitive-luis-client';

// your bot
const bot = new UniversalCallBot(/* params */);

// cognitive apis
const speechClient = new SpeechClient(new SpeechAuthClient('key'));
const luisClient = new LuisClient('appId', 'key');

// attach attach speech library to your bot
bot.library(speechLibrary(speechClient, luisClient));

// use SpeechDialog to prompt for a recording and process it
bot.dialog('/', [
  (session: CallSession, args, next) => {

    // speech-to-text and language understanding
    SpeechDialog.understandSpeech(session, 'Where do you want to go today?');

    // just speech-to-text
    // SpeechDialog.recognizeSpeech(session, 'Where do you want to go today?');
  },
  (session: CallSession, args, next) => {
    if (args.error) {
      console.error(args.err);
      return session.error(args.error);
    }

    const speech: SpeechResult = args.response.speech;
    const luis: LuisResult = args.response.language;

    session.endDialog(`You said ${speech.header.name}, with intent ${luis.topScoringIntent.intent} and ${luis.entities.length} entities`);
  },
]);

Automatic Intent-to-Dialog mapping

Use a LuisDialog instance and its triggerAction() method to automatically call a dialog when a certain intent is recognized by LUIS.

import { IUnderstandRecording, LuisDialog } from 'botbuilder-calling-speech';

bot.dialog('myIntentDialog', new LuisDialog([
  (session, args: IUnderstandRecording, next) => {
    session.endDialog('Your order is shipping soon!');
  },
]).triggerAction({
  match: 'intent.order.status',
  threshold: 0.8, // optional
}));

Note Automatic dialog mapping only occurs for prompts initiated by SpeechDialog.understandSpeech().

JavaScript

const bcs = require('botbuilder-calling-speech');
const bc = require('botbuilder-calling');
const csc = require('cognitive-speech-client');
const clc = require('cognitive-luis-client');

// your bot
const bot = new bc.UniversalCallBot(/* params */);

// cognitive apis
const speechClient = new csc.SpeechClient(new SpeechAuthClient('key'));
const luisClient = new clc.LuisClient('appId', 'key');

// attach attach speech library to your bot
bot.library(bcs.speechLibrary(speechClient, luisClient));

// see TypeScript section for examples of bcs.SpeechDialog prompts

API

Use the static SpeechDialog functions just like you would use the static Prompt functions from botbuilder-calling.

SpeechDialog

Methods

  • (static) recognizeSpeech(session, playPrompt, options): Prompt caller and process speech through the configured SpeechClient.
    • session: a CallSession object
    • playPrompt: typically a string. May be any prompt recognized by -Prompts.record()frombotbuilder-calling`
    • options: (optional) IRecordPromptOptions object from botbuilder-calling
  • (static) understandSpeech(session, playPrompt, options): Prompt caller and process speech through both the configured SpeechClient and LuisClient.
    • session: a CallSession object
    • playPrompt: typically a string. May be any prompt recognized by - rompts.record()frombotbuilder-calling`
    • options: (optional) IRecordPromptOptions object from botbuilder-calling

LuisDialog

Wrap a dialog around a specific LUIS intent

Constructor

  • new LuisDialog(dialog): Create a new instance
    • dialog: any valid Dialog|IDialogWaterfallStep[]|IDialogWaterfallStep that will handle the intent

Methods

  • triggerAction(options): assign a named intent and optional confidence threshold to this LuisDialog
    • options.match: (string) name of the LUIS intent to match
    • options.threshold: (number) optional threshold required to trigger this dialog
    • returns the current LuisDialog