项目作者: Dabolus

项目描述 :
Google Assistant SDK for Node.js.
高级语言: TypeScript
项目地址: git://github.com/Dabolus/nodejs-assistant.git
创建时间: 2018-11-08T20:04:21Z
项目社区:https://github.com/Dabolus/nodejs-assistant

开源协议:MIT License

下载


Google Assistant logo

Google Assistant SDK: Node.js Client

Node.js idiomatic client for Google Assistant SDK (unofficial).

The Google Assistant SDK lets you add hotword detection, voice
control, natural language understanding and Google’s smarts to your devices.
Your device captures an utterance (a spoken audio request, such as
What’s on my calendar?), sends it to the Google Assistant, and receives a
spoken audio response in addition to the raw text of the utterance.

Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

Some configuration steps are needed to make this library work correctly, for
example creating a Cloud Platform project, creating a device and generating
OAuth2 credentials. Please, follow
the Google Assistant Library for Python guide
to get started quickly.

Installing the client library

  1. npm install --save nodejs-assistant

Using the client library

  1. // Imports the Google Cloud client library
  2. const {Assistant, AssistantLanguage} = require('nodejs-assistant');
  3. // Your credentials
  4. const credentials = require('path-to-your-credentials.json');
  5. // Creates a client
  6. const assistant = new Assistant(/* required credentials */ {
  7. type: 'authorized_user',
  8. client_id: credentials.client_id,
  9. client_secret: credentials.client_secret,
  10. refresh_token: credentials.refresh_token,
  11. }, /* additional, optional options */ {
  12. locale: AssistantLanguage.ITALIAN, // Defaults to AssistantLanguage.ENGLISH (en-US)
  13. deviceId: 'your device id',
  14. deviceModelId: 'your device model id',
  15. });
  16. // Sends a text query to the assistant
  17. assistant.query('Hi!')
  18. .then(response => {
  19. // response contains all the fields returned by the assistant, such as the text and audio
  20. console.log(`Response: ${response.text}`);
  21. // response.audio is a Buffer containing the audio response by the assistant
  22. })
  23. .catch(err => {
  24. console.error('ERROR: ', err);
  25. });

Head over the API docs for
more information.

Samples

Samples are in the samples/ directory. The samples’ README.md
has instructions for running the samples.

Sample Source Code Try it
Quickstart source code Open in Cloud Shell
Text Conversation source code Open in Cloud Shell
Audio Conversation source code Open in Cloud Shell

You might also want to check out Google Assistant Desktop (Unofficial)
for a more concrete example.

Contributing

Contributions welcome! See the Contributing Guide.

License

MIT

See LICENSE