S4 Client Library
A client library developed on node.js that can be used to send data files to the S4 service for processing.
Contents
Overview
The goal of this library is to abstract from an end user application the mechanics of creating and dispatching HTTP requests, and handling coressponding responses. In addition to using this library in scenarios where the input data is a real time audio stream, it can also be used in test scenarios, where the data is read from a static file and sent to the server for testing/evaluation.
This documentation outlines how the library can be downloaded and used as a dependency to an application.
This library has been developed using JavaScript for the NodeJs engine, specifically version 10+ of NodeJS.
Installation
This library can be installed by using the npm tool as follows:
npm install git+https://gitlab.lyricsemiconductor.com/platformdevops/s4-client-lib.git
** NOTE: **
- Use the
--save
option to save the dependency in your project's package.json
file
Usage
Include the library in your code by using require
:
var s4ClientLib = require('s4-client-lib');
Making Requests
Before data can be sent to a server, a new client object must be created as follows:
var client = new s4ClientLib.S4Client('http://asr.lyricsemiconductor.com/service_path', {
apiKey: 'QRTV4Fh2W+ID',
micConfig: '<mic config data>'
});
The first argument to the constructor is the url of the S4 service endpoint. The second argument is configuration information for the client request. Details are as follows:
apiKey
: A shared secret key that the client can use to authenticate against the servermicConfig
: A string that specifies the microphone configuration
Once a client object has been created, a data can be streamed to the service by invoking the sendStream(readable)
method, with a readable stream as the first argument.
var stream = createStreamFromSource();
var promise = client.sendStream(stream);
Handling Responses
All requests made using the client object will return a promise that conforms to the (Promises/A+)[https://promisesaplus.com/] specification. Each promise supports a then
method that can be invoked with a success handler and a failure handler, as shown below:
promise.then(function(response) {
}, function(err) {
});