Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const inputAudio = await readFile(audioFilePath);
const request = {
session: sessionPath,
queryInput: {
audioConfig: {
audioEncoding: `AUDIO_ENCODING_LINEAR_16`,
sampleRateHertz: 16000,
languageCode: languageCode,
model: model,
},
},
inputAudio: inputAudio,
};
// Recognizes the speech in the audio and detects its intent.
const responses = await sessionClient.detectIntent(request);
const contextClient = new dialogflow.ContextsClient();
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
const parameters = JSON.stringify(struct.decode(result.parameters));
console.log(` Parameters: ${parameters}`);
if (result.outputContexts && result.outputContexts.length) {
console.log(` Output contexts:`);
result.outputContexts.forEach(context => {
const contextId = contextClient.matchContextFromContextName(context.name);
const contextParameters = JSON.stringify(
struct.decode(context.parameters)