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

Function detectIntentAudio

dialogflow-cx/quickstart.js:53–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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,
75 },
76 languageCode,
77 },
78 };
79 const [response] = await client.detectIntent(request);
80 console.log(`User Query: ${response.queryResult.transcript}`);
81 for (const message of response.queryResult.responseMessages) {
82 if (message.text) {
83 console.log(`Agent Response: ${message.text.text}`);
84 }
85 }
86 if (response.queryResult.match.intent) {
87 console.log(
88 `Matched Intent: ${response.queryResult.match.intent.displayName}`
89 );
90 }
91 console.log(
92 `Current Page: ${response.queryResult.currentPage.displayName}`
93 );
94 }
95
96 detectIntentAudio();
97 // [END dialogflow_cx_quickstart]

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected