resume-node-rest-connector

Resume API Connector for Node.JS (sati.co.th)

Usage no npm install needed!

<script type="module">
  import resumeNodeRestConnector from 'https://cdn.skypack.dev/resume-node-rest-connector';
</script>

README

Resume Node.JS REST API Connector

Resume API Connector for Node.JS

About the Project

Resume™ (RE-SU-ME), the Medical Speech to Clinical Summarized Text, is the API developed by Thai SaTI Partnership, Limited (SaTI™).

Resume Node.JS REST API Connector provides simplicity to connect Resume API as REST Client (and WebSocket Client in the future). For more detail about SaTI's Resume Service, Please follow sati.co.th.

Built With


Getting Started

Install

npm install resume-node-rest-connector

Pass Credentials and Configuration

The credentials is for authenication to Resume API. And the configuration will be default values for the API of the client. More details about ResumeCredentials and configuration are in docs/config.md.

Place credentials file

You can place credentials.js file from Resume Administration System in server root folder. The config.js of Resume REST API Connector will parse it when server starts. The example of credentials file locate at ../credentials.template.json.

Example content in `credentials.js

{
  "host": "https://resume.sati.co.th",
  "username": "USERNAME",
  "password": "PASSWORD",
  "section_id_default": 0
}

Pass credentials as environmental variables

You can also specified Authenication information for Resume API via environmental variable. This method suits for Docker Container development. Please see Environment variables in Compose for more details.

Example of docker-compose.yaml for Resume Socket.IO container.

version: "3.4"

services:
  resume-demo:
    # ...

    environment:
      REST_HOST: https://resume.sati.co.th
      REST_USER: USERNAME
      REST_PW: PASSWORD
    
    # ...


You can also place these secret in ".env" file as Docker suggestion.

Example of .env for Resume Socket.IO container.

REST_HOST=https://resume.sati.co.th
REST_USER=USERNAME
REST_PW=PASSWORD
REST_DEFAULT_SECTION=0
REST_LANG=["th","en"]

Programmatic input

You can give Resume Host, Username, and Password to the class constructor directly. Please read create the object.


Usage

Create the object

const { HttpClient } = require('resume-node-rest-connector');
restClient = new HttpClient();

You can override credentials from configuration in ResumeCredentials by passing as constructor parameters.

const { HttpClient } = require('resume-node-rest-connector');

const HOST = "https://resume.sati.co.th";
const USER = "USERNAME";
const PW = "PASSWORD";

const restClient = new HttpClient(HOST, USER, PW);

HttpClient constructor


Request for new Session ID from Resume API

restClient.newSession(sectionId, lang, hint, docFormat, multiSpeaker, userStartTime)
    .then(res => {
        var sessionID = res.data.session_id;
        var pseudoIdentifier = res.data.pseudoIdentifier;
        var cookies = res.cookies;
    })
    .catch(err => { /*  Error handling  */ });

HttpClient.newSession method

Note: the HttpClient object is totally stateless. Every method call, it always needs session ID, section ID, and cookies (for load balancer) to communication with correct session on Resume API.


Push Sound Chunk to Resume API

/* tell the API to keep the session */
let isEnd = false;

/* create ResumeSoundInfo */
let info = {
    _id: soundID, /* Index of sound chunk in this session, count from 0 - n */
    datetime: new Date().toJSON(),
    is_end: isEnd,
    tag: tag, /* form name for Resume Combination or Dictation mode */
    user_transcript: userTranscript /* User input in this form, used for feedback the transcription result */
}


/* Upload to Resume API */
restClient.sendSound(sessionId, sectionID, info, blob, cookies)
    .then(transcript => {
        /* Resume API feedback that the session is ended. */
        let completeEnd = transcript.is_end; 
        
        /* process the transcript */

        // About the transcript object
        // Please Read docs/Resume-REST-API-Connect.md#module_Resume-REST-API-Connect..Transcript
    }).catch(err => { /*  Error handling  */ });

Note: Don't send sound after the session end, it will result in 500 HTTP Error.

Get Updated Result from Resume API

let lastUpdate = null;   /* set last update time, or null */

restClient.updateResult(sessionId, sectionID, lastUpdate, cookies)
    .then(function (transcript) {
        if (transcript) {
            // transcript is not null.

            /* Handling updated transcript */

        } else {
            // If no updated result since lastUpdate,
            // transcript will be null.
            
        }
    }).catch(err => { /*  Error handling  */ });

Note:

  1. transcript response can be null. Please check it before next process to prevent exeception.
  2. If the session is ended, the server will respond Transcript.is_end = true.

End the Session

Set ResumeSoundInfo.is_end = true

/* tell the API to end the session */
let isEnd = true; 

/* create ResumeSoundInfo */
let info = {
    _id: soundID, /* Index of sound chunk in this session, count from 0 - n */
    datetime: new Date().toJSON(),
    is_end: isEnd,
    tag: tag, /* form name for Resume Combination or Dictation mode */
    user_transcript: userTranscript /* User input in this form, used for feedback the transcription result */
}


/* Upload to Resume API */
restClient.sendSound(sessionId, sectionID, info, blob, cookies)
    .then(transcript => {
        /* Resume API feedback that the session is ended. */
        let completeEnd = transcript.is_end; 
        
        /* process the transcript */

        // About the transcript object
        // Please Read docs/Resume-REST-API-Connect.md#module_Resume-REST-API-Connect..Transcript
    }).catch(err => { /*  Error handling  */ });

Differences between Resume API mode

Part Conversation Mode Dictation Mode Combinatory Mode
transcript result contains MlGroupTxt both MlGroupTxt and TagRawTxt same to Dictation Mode
multiSpeaker parameter in HttpClient.newSession method true false true
Need to set tag property No Yes: for every sound chunk Every sound chunk in Dictation periods.
Set to null for sound chunks in Conversation mode.

More information


© 2021 - copyright by Tanapat Kahabodeekanokkul - the founder of RESUME.