This guide shows how to send audio input to a detect intent request using the API. Dialogflow processes the audio and converts it to text before attempting an intent match. This conversion is known as audio input, speech recognition, speech-to-text, or STT.
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.
You should do the following before reading this guide:
- Read Dialogflow basics.
- Perform setup steps.
Create an agent
If you have not already created an agent, create one now:
- Go to the Dialogflow ES console.
- If requested, sign in to the Dialogflow Console. See Dialogflow console overview for more information.
- Click Create Agent in the left sidebar menu. (If you already have other agents, click the agent name, scroll to the bottom and click Create new agent.)
- Enter your agent's name, default language, and default time zone.
- If you have already created a project, enter that project. If you want to allow the Dialogflow Console to create the project, select Create a new Google project.
- Click the Create button.
Import the example file to your agent
The steps in this guide make assumptions about your agent, so you need to import an agent prepared for this guide. When importing, these steps use the restore option, which overwrites all agent settings, intents, and entities.
To import the file, follow these steps:
-
Download the
room-booking-agent.zip
file. - Go to the Dialogflow ES console.
- Select your agent.
- Click the settings settings button next to the agent name.
- Select the Export and Import tab.
- Select Restore From Zip and follow instructions to restore the zip file that you downloaded.
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 JSON request below.
Here is a Linux example:
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 examples on other platforms, see Base64 encoding audio content in the Cloud Speech-to-Text API documentation.
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" } }
Notice that the value of the queryResult.action
field is "room.reservation",
and the value of the queryResult.fulfillmentMessages[0|1].text.text[0]
field asks the user for more information.
Go
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow, 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 reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow reference documentation for Ruby.