MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dialogflow-cx/quickstart.js:17–98  ·  view source on GitHub ↗
(
  projectId,
  location,
  agentId,
  audioFileName,
  encoding,
  sampleRateHertz,
  languageCode
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(
18 projectId,
19 location,
20 agentId,
21 audioFileName,
22 encoding,
23 sampleRateHertz,
24 languageCode
25) {
26 // [START dialogflow_cx_quickstart]
27 /**
28 * TODO(developer): Uncomment these variables before running the sample.
29 */
30 // const projectId = 'my-project';
31 // const location = 'global';
32 // const agentId = 'my-agent';
33 // const audioFileName = '/path/to/audio.raw';
34 // const encoding = 'AUDIO_ENCODING_LINEAR_16';
35 // const sampleRateHertz = 16000;
36 // const languageCode = 'en'
37
38 // Imports the Google Cloud Some API library
39 const {SessionsClient} = require('@google-cloud/dialogflow-cx');
40 /**
41 * Example for regional endpoint:
42 * const location = 'us-central1'
43 * const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
44 */
45 const client = new SessionsClient();
46
47 const fs = require('fs');
48 const util = require('util');
49 // Assumes uuid module has been installed from npm,
50 // npm i uuid:
51 const {v4} = require('uuid');
52
53 async function detectIntentAudio() {
54 const sessionId = v4();
55 const sessionPath = client.projectLocationAgentSessionPath(
56 projectId,
57 location,
58 agentId,
59 sessionId
60 );
61
62 // Read the content of the audio file and send it as part of the request.
63 const readFile = util.promisify(fs.readFile);
64 const inputAudio = await readFile(audioFileName);
65
66 const request = {
67 session: sessionPath,
68 queryInput: {
69 audio: {
70 config: {
71 audioEncoding: encoding,
72 sampleRateHertz: sampleRateHertz,
73 },
74 audio: inputAudio,

Callers 1

quickstart.jsFile · 0.70

Calls 1

detectIntentAudioFunction · 0.70

Tested by

no test coverage detected