Augnito Speech SDK
You can use Augnito SDK to make use of the Speech Recognition AI. To get access credentials or talk to us about your project, get in touch with us at partnerships@augnito.ai.
Installation
Install the library in your Typescript project.
npm install augnitosdk
use https://cdn.jsdelivr.net/npm/augnitosdk@latest/dist/augnitosdk.js to import the library from npm using CDN url.
Basic Usage
1- Import the library
import { Augnito } from 'augnitosdk';
import { Augnito } from 'https://cdn.jsdelivr.net/npm/augnitosdk@latest/dist/augnitosdk.js';
Note - All other steps are common for Vanilla JS and Typescript implementations.
2- Create the configuration file and instantiate Augnito Client
const augnitoConfig: AugnitoConfig = {
server: '<your domain server>',
accountCode: '<your accountcode>',
accessKey: '<your accesskey>',
userTag: '<your usertag>',
sourceApp: '<your sourceapp>',
lmId: '<your lmid>'
enableLogs: false,
listOfControls: [],
editor: EditorType.HTML
};
const augnito = new Augnito(augnitoConfig);
3- Toggle the client!
Now all you have to do is toggle the status when you want to connect/disconnect!
augnito.toggleListening((shouldPauseResume = false));
augnito.requestMicOff();
Mobile Application
Whether you want to use the Augnito Mic as your microphone, or you want to develop your own app, we got you covered.
All you have to do is initialize the mobile configuration. The SDK will generate a value that you need to use to generate a QR code which should be scanned in the App.
import { AugnitoMobileConfig } from 'augnitosdk';
const mobileConfig: AugnitoMobileConfig = {
enableLogs: false
};
const augnitoMobile = augnito.initMobileClient(mobileConfig);
const code = augnito.getQRCode();
Config Philips Speech Mic
If you have a Philips speech mic and want to use it as the input device, then include the below code.
import { PhilipsMicMode } from 'augnitosdk';
const philipMicConfig = {
philipsMicMode: PhilipsMicMode['HandsFree']
};
const philipMicHandler = augnito.initPhilipMicClient(philipMicConfig);
- HandsFree - where you push the record button speak and the push the button to stop
- PushToTalk - where you press and hold the record button to speak. Release of the button will stop
- BOTH - SDK will intelligently handle the other two modes based on user action
Augnito - Speech Related Callbacks
Name | type | Description |
---|
onFinalResult | (finalText: Recipe) => boolean | A final result is called when text has been processed by the Speech Server. Returns true to stop the processing in the SDK |
onCommandResult | (command: Recipe) => boolean | A command generated from the server. Returns true to stop the processing in the SDK |
onStateChanged | (isConnected: boolean) => void | Callback to indicate the status of the microphone listening state has changed. |
onSessionEvent | (data: AugnitoSocketResponse) => void | Callback to intercept Session Events |
onIdleMic | () => void | Callback when the Mic is idle for 5 minutes |
onMicrophoneOnError | (isWebClient: boolean) => void | Callback triggered when trying to start the connection, but it fails because it is already opened. (It can be opened in another tab, or it was not closed properly) |
onError | (error: AugnitoSDKErrorMessage) => void | Callback triggered when the SDK encouters an error |
Augnito Mobile - Speech Related Callbacks
Name | type | Description |
---|
onConnectionRequest | () => void | Callback when a mobile client is requesting to connect |
onMobileScan | () => void | Callback when a mobile client has scanned the QR Code |
Philips Speech Mic Related Callbacks
Name | type | Description |
---|
onPhilipsMicPressed | () => void | Callback when record button is pressed on Philips Speech Mic |
Augnito Methods
prop | type | notes |
---|
toggleListening | void | Toggles the Speech API connection: if already connected, it will stop the web socket; otherwise, it will start a new connection. If optional parameter shouldPauseResume is set to true then listening to mic will be suspended and resumed, here web socket will remain alive throughout the session. Consumers of the sdk are expected to call requestMicOff to stop the web sockeet and clean the resources in the end |
isConnected | boolean | Returns the status of the web socket: true if connected; otherwise false. |
getQRCode | string | Returns the Generated Value for the QR Code (If and only if the DeviceId was provided). |
dispose | void | Dispose all resources. |
initMobileClient | AugnitoMobile | Creates a web socket for getting notifications from client mobile application: only to be used with Mobile App |
apisFactory | FactoryAPI | Returns an Abstract Factory to create different API Clients. |
requestMicOff | void | Sends a request to close all opened connections. |
initPhilipMicClient | PhilipsMicClient | To be used with Philips Speecch Mic. It will listen to press event of record button on the mic. |
MacrosAPI
MacrosAPI Methods
name | type | notes |
---|
getMacros | Promise: MacroResult | Returns a list of macros for the specified user. |
upsertMacro | Promis: MacroResult | Creates or Updates a Macro for the specified user. |
deleteMacro | Promise: MacroResult | Deletes a Macro for the specified user. |
1- Create Macros Client
const macrosClient = augnito.apisFactory.getMacrosAPI();
import { MacrosAPI } from 'augnitosdk';
const macrosClient = new MacrosAPI(accountCode, accessKey, server);
2- Use the Macros Client to list, create, update or delete user macros
macrosClient
.getMacros({
UserTag: userTag
})
.then((result) => {
console.log(result);
});
Formatting Preference API
Formatting Preference API Interfaces
interface Edge
{
PK: string;
SK: string;
}
interface UserFormattingRequest
{
PageId?: Edge;
Limit?: number;
}
interface FormattingItem
{
SpokenForm: string;
DisplayForm: string;
ID: string;
}
interface FormattingResult
{
Status: number;
ErrorMessage: string;
Data: {
StatusMessage: string;
FormattingPreferenceItems? :
{
PageSize: number;
PageIdNext?: Edge;
PageIdPrevious?: Edge;
Items: Array<FormattingItem>;
};
};
}
interface UpsertFormattingRequest {
SpokenForm: string;
DisplayForm: string;
ID?: string;
}
RemoveFormattingRequest {
ID: string;
}
Formatting Preference API Methods
name | type | notes |
---|
getFormatting(request: UserFormattingRequest) | Promise: FormattingResult | Returns a list of formatting preferfences for the specified user. |
upsertFormatting(request: UpsertFormattingRequest) | Promise: FormattingResult | Creates or Updates a formatting preference for the specified user. |
removeFormatting(request: RemoveFormattingRequest) | Promise: FormattingResult | Deletes a formatting preference for the specified user. |
1- Create Formatting Preference Client
const formattingAPI = augnito.apisFactory.getFormattingAPI();
import { FormattingAPI } from 'augnitosdk';
const formattingAPI = new FormattingAPI({
UserCode: <your usercode>,
SubscriptionCode: <your subscription code>,
AccessKey: <your access key>,
SmId: <your sm id>,
DeviceCode: <your device code>,
SourceApp: <your source app>,
AccountCode: <your account code>,
Server: <your server>,
EnableLogs: true | false,
});
2- Use the Formatting Preference Client to list, create, update or delete user macros
formatApi
.getFormatting({
Limit: 10
})
.then((result) => {
console.log('formatting', result);
});
Vocabulary API
Vocabulary items can be added to the model for a specific user and model.
When the word has been added and is ready to be recognised a notification will be sent to the client and the microphone will need to be restarted.
Vocabulary Models
interface Edge
{
PK: string;
SK: string;
}
interface UserVocabularyRequest
{
PageId?: Edge;
Limit?: number;
}
interface VocabularyItem
{
Word: string;
SpokenWord: string | null;
IsAbbreviation: boolean;
CreatedAt: Date;
Status: string;
}
interface VocabularyResult
{
Status: number;
ErrorMessage: string;
Data: {
StatusMessage: string;
WordItems? :
{
SubscriptionCode: string;
UserCode: string;
PageSize: number;
PageIdNext?: Edge;
PageIdPrevious?: Edge;
Items: Array<VocabularyItem>;
};
};
}
interface UpsertVocabularyRequest
{
file: File;
Word: string;
SpokenWord: string;
IsAbbreviation: boolean;
}
interface RemoveVocabularyRequest
{
Word: string;
}
VocabularyAPI Methods
name | type | notes |
---|
getVocabulary(request: UserVocabularyRequest) | Promise: VocabularyResult | Returns a list of vocabulary for the specified user. |
upsertFormatting(request: UpsertVocabularyRequest) | Promise: VocabularyResult | Creates or Updates vocabulary for the specified user. |
removeFormatting(request: RemoveVocabularyRequest) | Promise: VocabularyResult | Deletes a vocabulary for the specified user. |
VocabularyAPI Callback
Name | type | Description |
---|
onVocabularyAdded | (notification: AugnitoAppNotification) => void | Notification that a vocabulary word has been processed. |
Vocbaulary Helper Methods
Name | type | Description |
---|
startRecording() | (Promise) => void | Starts recording audio. Will turn off main Augnito mic if on |
stopRecording() | (blob:Promise) => void | Stops recording audio and returns the audio |
The audio for the vocabulary to be added must be between 1 and 8 seconds long.
If you call stop recording less than 1 second after start the recording will wait for a second to have passed since it started before resolving the promise.
If you call stop recording more than 8 seconds after start the returned recording will be the first 8 seconds recorded.
1- Create Vocabulary Client
const vocabularyAPI = augnito.apisFactory.getVocabularyAPI();
vocabularyAPI.onVocabularyAdded = (notification: AugnitoAppNotification) => {
console.log(notification);
};
2 - Add a new vocabulary item
vocabularyAPI.startRecording();
...
vocabularyAPI.stopRecording().then((blob) => {
vocabularyAPI.upsertVocabulary({
file: new File([blob], 'test.wav'),
Word: 'test',
SpokenWord: 'test',
IsAbbreviation: false,
});
});
3 - List vocabulary items from multiple pages
const loadWords = (page?: Edge) => {
vocabularyAPI
.getVocabulary({ Limit: 10, PageId: page })
.then(function (result) {
if (typeof result != 'string') {
result.Data.WordItems?.Items.forEach((value) => {
console.log(value);
});
if (result.Data.WordItems?.PageIdNext) {
loadWords( result.Data.WordItems.PageIdNext);
}
}
});
};
loadWords();
MedicineOrderingAPI
MedicineOrderingAPI Methods
Name | type | Description |
---|
getMedicineOrderData | Promise: MedicineOrderingResult Or String | Returns medicine ordering data for text specified by the user. |
1- Create MedicineOrdering Client
const orderingClient = augnito.apisFactory.getMedicineOrderingAPI();
2- Use the MedicineOrdering Client to get medicine order data in the following manner
orderingClient
.getMedicineOrderData({
Text: ''
})
.then((result) => {
console.log(result);
});