kaia.js
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

Kaia.js

Kaia.ai platform's JS client library

We have not yet launched the platform. For launch announcement please follow us on Facebook.

Live Demos

Installation

Kaia.ai robot apps run on Android smartphones. To run sample apps:

  1. Go to kaia.ai, familiarize yourself with how the robot platform works
  2. Optional, but highly recommended: if you don't have Kaia.ai account, create an account
  3. Go to Google Play, search for "kaia.ai" to find and install Kaia.ai Android app
  4. Launch Kaia.ai Android app on your Android smartphone
  5. In Kaia.ai Android app: (optional, but highly recommended): sign in, navigate to Kaia.ai App Store
  6. Choose a robot app to launch
  7. Optionally: click the heart icon to pin the robot app to your launch screen

API Overview

TfMobile

let tfMobile = await createTfMobile(model); // load model
let result = await tfMobile.run([img], {    // classify image
  feed: [{width: size, height: size, inputName: 'input', imageMean: 128.0, imageStd: 128.0,
          feedType: 'colorBitmapAsFloat'}],
  run: {enableStats: false},
  fetch: {outputNames: ['MobilenetV1/Predictions/Softmax'], outputTypes: ['float']}
});
let probabilities = result.output[0];

TfLite

let tfLite = await createTfLite(model); // load model
let result = await tfLite.run([img], {  // classify image
  input: [{width: size, height: size, channels: 4, batchSize: 1, imageMean: 128.0, imageStd: 128.0,
           type: 'colorBitmapAsFloat'}],
  output:[{type: 'float', size: [1, 1001]}]
});
let probabilities = result.output[0][0];

Configuration options passed to run():

// Input parameters
  type: 'colorBitmapAsFloat', // input data type colorBitmapAsFloat|float|int|double|long|byte|colorBitmapAsByte
  width: inputWidth,          // input layer width
  height: inputHeight,        // input layer height
  channels: inputChannels,    // input layer channels
  batchSize: inputBatchSize,  // input layer batch size
  imageMean: imageMean,       // input image mean, 0...255, default 128
  imageStd: imageStd,         // input image standard deviation, default 128
// Output parameters
  type: 'float',              // output data type float|int|double|long|byte
  size: [1, 1001],            // output data size
// Miscellaneous options
  useNNAPI: false,            // use Android NN API, default false
  numThreads: 0               // number of threads to use, default 0

TextToSpeech

textToSpeech = await createTextToSpeech();
await textToSpeech.speak('Hello');

Serial

serial = await createSerial({ baudRate: 115200, eventListener: onSerialEvent });
serial.write('Hello Arduino!\n')
 
function onSerialEvent(err, data) {
  if (!err && data.event === 'received')
     console.log(data.message);
}

Installing

Via npm + webpack/rollup

npm install kaia.js

Now you can require/import kaia.js:

import { createTfMobile, createTfLite, createTextToSpeech, createAndroidMultiDetect, createPocketSphinx
         createAndroidSpeechRecognition, createDeviceSettings, createSerial, createSensors} from 'kaia.js';

Via <script>

  • dist/kaia.mjs is a valid JS module.
  • dist/kaia-iife.js can be used in browsers that don't support modules. kaiaJs is created as a global.
  • dist/kaia-iife.min.js As above, but minified.
  • dist/kaia-iife-compat.min.js As above, but works in older browsers such as IE 10.
  • dist/kaia-amd.js is an AMD module.
  • dist/kaia-amd.min.js As above, but minified.

These built versions are also available on jsDelivr, e.g.:

<script src="https://cdn.jsdelivr.net/npm/kaia.js/dist/kaia-iife.min.js"></script>
<!-- Or in modern browsers: -->
<script type="module">
  import { createTfMobile, createTfLite, createTextToSpeech } from 'https://cdn.jsdelivr.net/npm/kaia.js';
</script> 

and unpkg

<script src="https://unpkg.com/kaia.js/dist/kaia-iife.min.js"></script>
<!-- Or in modern browsers: -->
<script type="module">
  import { createTfMobile, createTfLite, createTextToSpeech } from 'https://unpkg.com/kaia.js';
</script> 

Customizing NN Model

Deprecations

  • Expect TextToSpeech to be eventually deprecated in favor of Web text-to-speech API.
  • Expect Serial API to be eventually deprecated in favor of WebUSB

Package Sidebar

Install

npm i kaia.js

Weekly Downloads

2

Version

0.8.0

License

Apache-2.0

Unpacked Size

237 kB

Total Files

10

Last publish

Collaborators

  • kaiaai