Send Text to LLM or TTS
Feature Overview
Large Language Models (LLMs) do not natively produce proactive speech. Instead, proactive AI responses must be explicitly triggered by your backend based on specific business rules to improve real-time conversation engagement. For example, if a user is silent for a certain duration, the AI can prompt with a follow-up question; or when a business event occurs, such as an order shipment or scheduled appointment, the AI can immediately notify the user.
TRTC AI Real-Time Chat supports three types of proactive AI speech mechanisms:
Capability | Implementation | Features |
Proactive LLM Invocation | During task execution, send a text injection command ( InvokeLLM) via the task control interface. | Injected text is added to the conversation context, prompting the LLM to generate a response. The reply is synthesized via TTS and broadcast to the room. |
Direct Text-to-TTS | During task execution, send a text broadcast command ( InvokeTTS) via the task control interface. | The text bypasses the LLM and is directly synthesized and broadcast via TTS. The AI's spoken output will match the provided text exactly. |
Fixed Phrase Broadcast | Configure welcome messages and silence follow-ups in DialogConfig when creating the task. | Fixed phrases are broadcast automatically at designated times, triggered by the backend, with no runtime intervention required. |
Note:
These text injection features are supported in Cascade (three-stage) mode. In S2S (end-to-end) mode, speech understanding and generation are handled by the end-to-end model, and there are no separate LLM/TTS stages.
Proactive LLM Invocation (Text Injection)
Usage
To trigger proactive LLM speech, the backend sends a
Command=InvokeLLM request through the task control interface (one of five standard task lifecycle operations):The injected text becomes part of the current conversation context and prompts an LLM response.
The LLM generates a reply based on the updated context, which is then synthesized by TTS and broadcast to the room.
Reply content can be retrieved via client subtitle events and server-side LLM reply callbacks (see below).
This interface also supports
Interrupt (forced interruption) and direct text-to-TTS (InvokeTTS) commands. For details, see Client Interrupt Command.Input Parameters
Parameter Name | Required | Type | Description |
SdkAppId | Yes | Integer | TRTC Application ID. |
TaskId | Yes | String | Task ID. |
Command | Yes | String | Command name: InvokeLLM. |
InvokeLLM | Conditionally Required | Object | Required when Command=InvokeLLM; see fields below. |
InvokeLLM Object:
Field Name | Required | Type | Description |
Content | Yes | String | Text to inject into the conversation, max length 1000 characters. |
Priority | No | Integer | Priority for conflict handling between injected text and current interaction: 0=High;1=Medium;2=Low; |
Priority Explanation
InvokeLLM and InvokeTTS use the same Priority system to manage conflicts between incoming text and ongoing AI interactions:Priority | Level | Behavior |
0 | High Priority | Immediately stop the AI's current interaction (such as an ongoing broadcast) and execute the incoming command. For InvokeTTS, the text is broadcast instantly; for InvokeLLM, the text is injected to trigger an immediate LLM reply and broadcast. |
1 | Medium Priority | Queue the broadcast: wait for the current interaction to finish before broadcasting the incoming text. |
2 | Low Priority | If the AI is currently interacting, discard the incoming text; if idle, broadcast the text. |
Priority Selection Recommendations:
Use high priority for urgent alerts (such as risk control warnings or audit prompts). Use medium priority for general notifications to queue broadcasts. Use low priority for optional background information, to avoid interrupting ongoing conversations.
Request Example
{"SdkAppId": 1400000000,"TaskId": "-nG0jIFU7q3wqZnqm8xB5TY0n43U5rLb...","Command": "InvokeLLM","InvokeLLM": {"Content": "Remind the user that the order has been shipped","Priority": 1}}
Retrieving Replies
Retrieval Method | Description |
Client (Subtitle Event) | The LLM reply is delivered in real time via subtitle events, displayed as complete sentences on the client. See Client Real-Time Subtitles for details. |
Server (LLM Reply Callback) | After each LLM reply, the callback pushes the final text (including round ID). See AI Chat Callback Events for details. |
Proactive TTS Invocation (Direct Text Broadcast)
Usage
To broadcast fixed content directly, the backend sends a
Command=InvokeTTS request through the task control interface:The provided text bypasses the LLM and is sent straight to TTS for synthesis and broadcast by the bot.
The AI's spoken output matches the provided text exactly. This is ideal for system announcements, audit prompts, marketing scripts, and any scenario requiring precise broadcast control.
Broadcasts follow unified interruption control—during broadcast, user speech (in auto-interrupt mode) or an
Interrupt command can immediately interrupt the bot.Differences from InvokeLLM
Comparison Item | InvokeLLM (to LLM) | InvokeTTS (to TTS) |
Workflow | Inject text into conversation → LLM generates reply → TTS broadcast | Send text directly to TTS for synthesis and broadcast (bypasses LLM). |
Broadcast Content | LLM generates content dynamically based on context; output is variable. | Broadcast content matches the business-provided text exactly. |
Typical Use Cases | AI proactively speaks or relays event reminders based on conversation context. | Precise broadcast of fixed content, such as announcements, prompts, or marketing scripts. |
Input Parameters
Parameter Name | Required | Type | Description |
SdkAppId | Yes | Integer | TRTC Application ID. |
TaskId | Yes | String | Task ID. |
Command | Yes | String | Command name: InvokeTTS (case-insensitive). |
InvokeTTS | Conditionally Required | Object | Required when Command=InvokeTTS; see fields below. |
InvokeTTS Object:
Field Name | Required | Type | Description |
Content | Yes | String | Text to broadcast, max length 1000 characters. |
Priority | No | Integer | Priority for conflict handling between broadcast text and current interaction: 0=High;1=Medium;2=Low; |
Request Example
{"SdkAppId": 1400000000,"TaskId": "-nG0jIFU7q3wqZnqm8xB5TY0n43U5rLb...","Command": "InvokeTTS","InvokeTTS": {"Content": "Is there anything you'd like to focus on today?","Priority": 1}}
Retrieving Broadcast Results
Retrieval Method | Description |
Client (Audio Stream) | Subscribe to the bot's audio stream to receive broadcast content. |
Client (Status Event) | Bot status transitions to 'Speaking' during broadcast and 'Finished Speaking' upon completion. See Client Receive AI Bot Status for details. |
Server (Status Callback) | Track broadcast start and end using AI status transition callbacks. See AI Chat Callback Events for details. |
Fixed Phrase Broadcast (Welcome Message & Silence Follow-Up)
Fixed phrases are broadcast directly by TTS at predetermined times by the backend. Configure these in
DialogConfig when creating the task:Field Name | Required | Type | Description |
WelcomeMessage | No | String | Welcome message, automatically broadcast when the host enters the room. |
SilenceFollowUp | No | Integer | Time (seconds) after silence before the bot proactively asks a follow-up question. Range 0–300; 0=disabled (default). |
SilenceFollowUpText | No | String | Text for the silence follow-up prompt. |
Configuration Example:
"DialogConfig": {"InterruptMode": 0,"InterruptSpeechDuration": 200,"SilenceFollowUp": 50,"SilenceFollowUpText": "Are you still there? If you have any questions, just let me know.","WelcomeMessage": "Hello, I'm your AI assistant. How can I help you today?"}
Note:
In addition to the above,
LLMConfig.FailureMessage (fallback text broadcast when LLM invocation fails) is also considered a fixed phrase. See LLM Configuration for details.Typical Use Cases
Scenario | Implementation | Description |
Room Welcome Message | DialogConfig.WelcomeMessage | AI automatically broadcasts a welcome message at the beginning of each conversation. |
Silence Follow-Up (Prevent Awkward Silence) | SilenceFollowUp + SilenceFollowUpText | If the user is silent for an extended period, AI proactively asks a follow-up, e.g., "Are you still there? If you have any questions, just let me know." |
Proactive Business Event Reminder | Runtime InvokeLLM injection | For key events such as order shipped, activity started, or scheduled time, inject: "Remind the user that the order has been shipped" for AI broadcast. |
Proactive Topic Initiation | Runtime InvokeLLM injection | Inject: "The user hasn't spoken for a while, please proactively say something," prompting the AI to speak contextually. |
Precise Fixed Content Broadcast | Runtime InvokeTTS injection | For system announcements, audit prompts, marketing scripts, etc., where exact broadcast is required. |
Deterministic Broadcast (Bypass LLM) | Runtime InvokeTTS injection | For reminders sensitive to latency or content certainty, bypass LLM and synthesize broadcast directly. |
Notes
1. Injected text enters conversation context (InvokeLLM only): Text injected via proactive LLM invocation becomes part of the conversation context for the current and subsequent rounds. To avoid degrading conversation quality, only inject relevant business content. Text sent via
InvokeTTS bypasses the LLM and is broadcast directly.2. Length Limit: Both
InvokeLLM.Content and InvokeTTS.Content are limited to 1000 characters.3. Select priority based on conflict strategy: High priority interrupts the current interaction immediately (users may hear incomplete sentences). Use high priority only for urgent broadcasts. For notifications that are not latency-sensitive, use medium priority to avoid frequent interruptions impacting the conversation.
4. Broadcasts can be interrupted: Proactive TTS broadcasts follow interruption control. In auto-interrupt mode, user speech can interrupt the AI's proactive broadcast. See Client Interrupt Command for details.
5. Only effective for active tasks: Commands are ignored after the task ends or the bot exits the room. Use status transition callbacks to manage task lifecycle.
6. Fixed phrases cannot be changed at runtime: Welcome messages and silence follow-ups are set when the task is created. Only
InterruptMode in DialogConfig supports hot updates via the task modification interface.7. Voice follows task configuration:
InvokeTTS broadcasts use the voice and vendor specified in the task's TTSConfig. The command itself does not specify voice. To change voice, recreate the task (hot updates for TTSConfig are not supported). See TTS Configuration for details.