0.0.1 • Published 5 years ago

lex-audio-client v0.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

JavaScript Style Guide

lex-audio-client

Hey: This project isn't quite ready yet.

Enables you to easily capture voice / audio input for use with Amazon Lex. Browser-friendly.

Usage

Initializing

Create an instance of the client by passing in a valid AWS.LexRuntime client.

import AWS from 'aws-sdk'
import LexAudioClient from 'lex-audio-client'

// ...

// :: create a Lex runtime client
const lexClient = new AWS.LexRuntime({
  region: 'us-west-2',  // <-- or your any other region where Lex is available
  credentials: new AWS.Credentials(accessKey, secretKey, null)
})

// :: create a Lex audio client
const lexAudioClient = new LexAudioClient(lexClient)

If you're using AWS Amplify for authentication, you can grab your credentials from the Amplify Auth module.

import AWS from 'aws-sdk'
import { Auth } from 'aws-amplify'
import LexAudioClient from 'lex-audio-client'

// ...

const credentials = await Auth.currentCredentials()
const lexClient = new AWS.LexRuntime({
  credentials: Auth.essentialCredentials(credentials),
  // ...
})

Recording audio

To start recording, call .start() on the audio client. This will return a Promise that resolves / rejects with the (eventual) query against Lex once recording is completed.

const conversation = lexAudioClient.start()

// ...

conversation
  .then((message) => { ... })
  .catch((error) => { ... })

To end recording, just call .stop() on the audio client. This will return the same Promise that .start() returned, and will initiate a query against Lex. The Promises will resolve / reject with the query response.

lexAudioClient.stop()
  .then((message) => { ... })
  .catch((error) => { ... })