0.0.12 • Published 7 years ago

google-assistant-node v0.0.12

Weekly downloads
13
License
ISC
Repository
github
Last release
7 years ago

Google Assistant SDK for Node

This wrapper allows you to use the Google Assistant api in any Node application. It handles events, audio buffering, and client connection automatically.

Installation

npm install google-assistant-node

Usage

let GoogleAssistant = require('google-assistant-node');
let constants = GoogleAssistant.Constants;
let encodings = constants.Encoding;

let assistant = new GoogleAssistant({
  input: {
    encoding: encodings.LINEAR16,
    sampleRateHertz: 16000
  },
  output: {
    encoding: encodings.MP3,
    sampleRateHertz: 16000,
    volumePercentage: 100
  }
});

assistant.on('audio-data', (data) => {
  // Audio Data (bytes)
});

assistant.on('response-text', (text) => {
  //  Reponse Text (string)
});

assistant.on('request-text', (text) => {
  //  Request Text (string)
});

assistant.on('state', (state) => {
  //  Conversation State (bytes)
});

assistant.on('mic-mode', (mode) => {
  //  Microphone Mode (int)
});

assistant.on('unauthorized', (error) => {
  // Authorization error (error)
  // E.g. Did not authenticate with OAuth client
})

assistant.on('error', (error) => {
  //  Error (error)
});

assistant.on('ready', (writeStream) => {
  // Assistant is ready to accept audio data
  audioData.pipe(writeStream);
});

assistant.on('end', () => {
  // Conversation is over. 
}

// Use Google OAuth Client to authenticate: 
// https://github.com/google/google-auth-library-nodejs 
// or
// https://github.com/google/google-api-nodejs-client
assistant.authenticate(authClient);

// Start conversation
assistant.converse();
0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago