项目作者: awernick

项目描述 :
Google Assistant SDK wrapper for Node (DEPRECATED use https://github.com/endoplasmic/google-assistant)
高级语言: JavaScript
项目地址: git://github.com/awernick/google-assistant-node.git
创建时间: 2017-06-08T21:02:17Z
项目社区:https://github.com/awernick/google-assistant-node

开源协议:

下载


Google Assistant SDK for Node

DEPRECATED Use https://github.com/endoplasmic/google-assistant instead.

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

This module uses the GRPC implementation of the Google Assistant SDK.
More info can be found here.

Installation

  1. npm install google-assistant-node

Usage

  1. let GoogleAssistant = require('google-assistant-node');
  2. let constants = GoogleAssistant.Constants;
  3. let encodings = constants.Encoding;
  4. let assistant = new GoogleAssistant({
  5. input: {
  6. encoding: encodings.LINEAR16,
  7. sampleRateHertz: 16000
  8. },
  9. output: {
  10. encoding: encodings.MP3,
  11. sampleRateHertz: 16000,
  12. volumePercentage: 100
  13. }
  14. });
  15. // Audio Data (bytes)
  16. assistant.on('audio-data', (data) => {
  17. });
  18. // Reponse Text (string)
  19. assistant.on('response-text', (text) => {
  20. });
  21. // Request Text (string)
  22. assistant.on('request-text', (text) => {
  23. });
  24. // Conversation State (bytes)
  25. assistant.on('state', (state) => {
  26. });
  27. // Microphone Mode (int)
  28. assistant.on('mic-mode', (mode) => {
  29. });
  30. // Authorization error (error)
  31. // E.g. Did not authenticate with OAuth client
  32. assistant.on('unauthorized', (error) => {
  33. })
  34. // Error (error)
  35. assistant.on('error', (error) => {
  36. });
  37. // Assistant is ready to accept audio data. NOTE: .once() is used.
  38. assistant.once('ready', (wstream) => {
  39. audioData.pipe(wstream);
  40. });
  41. // Current conversation is over.
  42. // NOTE: 'end' will be called even if there is a 'follow-on' event.
  43. assistant.once('end', () => {
  44. });
  45. // Assistant is expecting a follow-on response from user.
  46. assistant.on('follow-on', () => {
  47. // Setup follow-on 'ready' and 'end' event handler to change audio source
  48. // if desired (or if you used .once()).
  49. assistant.once('ready', (wstream) => {
  50. moreAudioData.pipe(wstream)
  51. });
  52. // Handle follow-on conversation end.
  53. assistant.once('end', () => {
  54. moreAudioData.end();
  55. })
  56. // Don't forget to call .converse() to resume conversation
  57. assistant.converse();
  58. })
  59. // Use Google OAuth Client to authenticate:
  60. // https://github.com/google/google-auth-library-nodejs
  61. // or
  62. // https://github.com/google/google-api-nodejs-client
  63. assistant.authenticate(authClient);
  64. // Start conversation
  65. assistant.converse();

Constants

Encoding

  • LINEAR16: Uncompressed 16-bit signed little-endian samples.
  • FLAC: Free Lossless Audio Codec. Input audio only.
  • MP3: MP3 Audio Encoding. Output audio only.
  • OPUS_IN_OGG: Opus-encoded audio wrapped in an ogg container. Output audio only.

MicMode

  • CLOSE_MICROPHONE: The service is not expecting a follow-on question from the user.
  • DIALOG_FOLLOW_ON: The service is expecting a follow-on question from the user.

Contributing

Please feel free to make pull requests if you want to include a feature or
if you fix an issue previously reported in the tracker.