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

Function main

dialogflow-cx/detect-intent-streaming.js:17–127  ·  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_detect_intent_streaming]
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 const {Transform, pipeline} = require('stream');
50 const pump = util.promisify(pipeline);
51
52 async function detectIntentAudio() {
53 const sessionId = Math.random().toString(36).substring(7);
54 const sessionPath = client.projectLocationAgentSessionPath(
55 projectId,
56 location,
57 agentId,
58 sessionId
59 );
60 console.info(sessionPath);
61
62 // Create a stream for the streaming request.
63 const detectStream = client
64 .streamingDetectIntent()
65 .on('error', console.error)
66 .on('data', data => {
67 if (data.recognitionResult) {
68 console.log(
69 `Intermediate Transcript: ${data.recognitionResult.transcript}`
70 );
71 } else {
72 console.log('Detected Intent:');
73 const result = data.detectIntentResponse.queryResult;
74

Callers 1

Calls 1

detectIntentAudioFunction · 0.70

Tested by

no test coverage detected