This page describes how to stream 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. This process is called 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.
Complete the following tasks before you read this guide:
- Read Dialogflow basics.
- Perform 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.
Streaming basics
The Session type's
streamingDetectIntent method returns a bidirectional gRPC streaming object.
The available methods for this object vary by language, so see the reference
documentation for your client library for details.
The streaming object is used to send and receive data concurrently. Using this
object, your client streams audio content to Dialogflow, while
concurrently listening for a StreamingDetectIntentResponse.
The streamingDetectIntent method has a
query_input.audio_config.single_utterance parameter that affects speech
recognition:
- If
false(default), speech recognition does not cease until the client closes the stream. - If
true, Dialogflow will detect a single spoken utterance in input audio. When Dialogflow detects the audio's voice has stopped or paused, it ceases speech recognition and sends aStreamingDetectIntentResponsewith a recognition result ofEND_OF_SINGLE_UTTERANCEto your client. Any audio sent to Dialogflow on the stream after receipt ofEND_OF_SINGLE_UTTERANCEis ignored by Dialogflow.
In bidirectional streaming, a client can half-close the stream object to
signal to the server that it won't send more data. For example, in Java and Go,
this method is called closeSend.
It's important to half-close (but not abort) streams in the following situations:
- Your client has finished sending data.
- Your client is configured with
single_utteranceset totrue, and it receives aStreamingDetectIntentResponsewith a recognition result ofEND_OF_SINGLE_UTTERANCE.
After closing a stream, your client should start a new request with a new stream as needed.
Streaming detect intent
The following samples use the
Session
type's streamingDetectIntent method to stream audio.
To authenticate to Dialogflow CX, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
To authenticate to Dialogflow CX, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
To authenticate to Dialogflow CX, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
To authenticate to Dialogflow CX, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
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.
Go
Java
Node.js
Python
Additional languages
Samples
For more information about best practices on streaming from a browser microphone to Dialogflow, see the Samples page.