The DialogFlow.AI Java SDK makes it easy to integrate speech recognition with DialogFlow.AI natural language processing API on Android devices. API.AI allows using voice commands and integration with dialog scenarios defined for a particular agent in API.AI.
Authentication is accomplished through setting the client access token when initializing an AIConfiguration object. The client access token specifies which agent will be used for natural language processing.
Note: The DialogFlow.AI Java SDK only makes query requests, and cannot be used to manage entities and intents. Instead, use the API.AI user interface or REST API to create, retrieve, update, and delete entities and intents.
These samples demonstrate the use of the Dialogflow API.
These samples show how to detect intents with text, audio, and streaming audio.
These samples show how to manage contexts, entities, entity types, and intents
This sample requires you to have Java8.
To get started, download and install it.
-
Create a project with the Google Cloud Console, and enable the Dialogflow API.
-
Set up authentication. For example, from the Cloud Console, create a service account, download its json credentials file, then set the appropriate environment variable:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
-
To run tests, set GOOGLE_CLOUD_PROJECT to your PROJECT_ID:
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
mvn clean verify
-
Set PROJECT_ID in pom.xml to your Google Cloud Project Id.
-
Set SESSION_ID in pom.xml to a session name of your choice. (Defaults to SESSION_ID)
-
Set CONTEXT_ID in pom.xml to a context name of your choice. (Defaults to CONTEXT_ID)
To build the sample, we use Maven.
mvn clean package
Import the sample agent (RoomReservation.zip) from the resources directory to your Dialogflow Project using the following guide: Versioning with Import/Export
DialogFlow API Detect Intent sample with text inputs.
mvn exec:java -DDetectIntentTexts
DialogFlow API Detect Intent sample with audio files. Returns the result of detect intent with an audio file as input.
Note: Execute the following commands in order to yield reasonable outputs.
mvn exec:java -DDetectIntentAudioBookARoom
mvn exec:java -DDetectIntentAudioMountainView
mvn exec:java -DDetectIntentAudioToday
mvn exec:java -DDetectIntentAudio230PM
mvn exec:java -DDetectIntentAudioHalfAnHour
mvn exec:java -DDetectIntentAudioTwoPeople
DialogFlow API Detect Intent sample with audio files processes as an audio stream.
mvn exec:java -DDetectIntentStreamBookARoom
mvn exec:java -DDetectIntentStreamMountainView
DialogFlow API Context sample.
Lists contexts
mvn exec:java -DContextManagementList
Create an entity type
mvn exec:java -DContextManagementCreate
Delete entity type
mvn exec:java -DContextManagementDelete
DialogFlow API Entity sample.
List entities
mvn exec:java -DEntityManagementList
Create an entity
mvn exec:java -DEntityManagementCreate
Delete entity
mvn exec:java -DEntityManagementDelete
DialogFlow API EntityType sample.
List entity types
mvn exec:java -DEntityTypeManagementList
Create an entity type
mvn exec:java -DEntityTypeManagementCreate
Delete entity type
mvn exec:java -DEntityTypeManagementDelete
DialogFlow API Intent sample.
List intents
mvn exec:java -DIntentManagementList
Create an intent
mvn exec:java -DIntentManagementCreate
Delete intent
mvn exec:java -DIntentManagementDelete
DialogFlow API SessionEntityType sample.
List session entity types
mvn exec:java -DSessionEntityTypeManagementList
Create session entity type
mvn exec:java -DSessionEntityTypeManagementCreate
Delete session entity type
mvn exec:java -DSessionEntityTypeManagementDelete