This guide describes how to send audio input to a detect intent request by using the API. Dialogflow processes the audio and converts it to text before it attempts an intent match.
Before you begin
This feature is only applicable when using the API for end-user interactions. If you are using an integration, you can skip this guide.
Before you read this guide, complete the following tasks:
- Read Dialogflow basics.
- Complete the setup steps.
Create an agent
- Go to the Dialogflow ES console.
- Sign in to the console if prompted. For more information, see the Dialogflow console overview.
- In the sidebar menu, expand Loading agents.
- Click Create new agent.
- Enter the agent name, default language, and default time zone.
- Enter an existing project. To let the Dialogflow console create a project, select Create a new Google project.
- Click Create.
Detect intent
To detect intent, call the detectIntent method on the
Sessions type.
REST
Download thebook-a-room.wav
sample input audio file, which says "book a room." The audio file must be
Base64-encoded for this example, so it can be provided in the following JSON
request.
To encode the audio file for the request, use the following commands on Linux:
wget https://cloud.google.com/dialogflow/es/docs/data/book-a-room.wav base64 -w 0 book-a-room.wav > book-a-room.b64
For more information about encoding audio content, see Base64-encoding audio content.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- AUDIO: the base64 encoded audio content
HTTP method and URL:
POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/agent/sessions/123456789:detectIntent
Request JSON body:
{
"queryInput": {
"audioConfig": {
"languageCode": "en-US"
}
},
"inputAudio": "AUDIO"
}
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"responseId": "3c1e5a89-75b9-4c3f-b63d-4b1351dd5e32",
"queryResult": {
"queryText": "book a room",
"action": "room.reservation",
"parameters": {
"time": "",
"date": "",
"guests": "",
"duration": "",
"location": ""
},
"fulfillmentText": "I can help with that. Where would you like to reserve a room?",
"fulfillmentMessages": [
{
"text": {
"text": [
"I can help with that. Where would you like to reserve a room?"
]
}
}
],
"intent": {
"name": "projects/PROJECT_ID/agent/intents/e8f6a63e-73da-4a1a-8bfc-857183f71228",
"displayName": "room.reservation"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": "en-us"
}
}
The queryResult.action field value is "room.reservation", and the
queryResult.fulfillmentMessages[0|1].text.text[0] field value asks the user
for more information.
Go
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for Ruby.