Recipes
Let an LLM write tagged text
Have a voice agent's LLM add emotion and style tags, and check them before they're spoken.
Teach the LLM the 12 tags in its system prompt, then remove anything else it puts in brackets. Tags are covered in Emotion and speaking style.
Add the tags to the system prompt
Paste this into your agent's system prompt, after your own instructions:
Your replies are spoken by a text-to-speech voice.
You can set how a sentence sounds with a tag at its start. Use only these 12 tags, spelled exactly like this:
[neutral] [happy] [sad] [angry] [fearful] [surprised] [whisper]
[news] [storytelling] [advertising] [call_center] [conversational]
Rules:
- Start your reply with [conversational].
- Use at most one tag per sentence, at the start of the sentence.
- A tag lasts until the next tag, so add one only where the tone changes.
- Pick the tag that fits the words: [sad] for an apology, [happy] for good news.
- Never put anything else in square brackets: no other names or synonyms, and no sound effects or stage directions such as [laughs] or [pause].
- Keep tag names in English, also when you reply in Arabic.
- Write plain spoken sentences: no Markdown, lists or emoji.Check the reply before you speak it
The LLM can still invent a tag such as [laughs], and any bracket that isn't one of the 12 is
spoken. Remove those, then send the reply as text, as in
Play speech as it streams:
const DELIVERIES = new Set([
'neutral', 'happy', 'sad', 'angry', 'fearful', 'surprised', 'whisper',
'news', 'storytelling', 'advertising', 'call_center', 'conversational',
]);
// Keeps the 12 tags and removes any other [bracketed] text, which would be spoken.
function cleanTags(reply: string): string {
return reply
.replace(/\s*\[([^[\]]*)\]/g, (tag, name: string) => (DELIVERIES.has(name.toLowerCase()) ? tag : ''))
.trim();
}
for await (const chunk of client.synthesizeStream(cleanTags(reply), {
voice_id: voice.id,
model: TtsModel.Nebula,
timeoutSeconds: 30,
})) {
process.stdout.write(chunk.audio);
}If your agent sends one sentence per request, carry the last tag over to the next sentence that has none: a delivery doesn't carry over between requests.
Listen to an example reply
Voice mul_nourah.
| Language | Text sent | Listen |
|---|---|---|
| English | [conversational] Sure, I can help with that. [happy] Good news: your order shipped this morning and should arrive tomorrow. | |
| Arabic | [conversational] أكيد، أقدر أساعدك. [happy] خبر حلو: طلبك انشحن الصباح وبيوصلك بكرة. |
Rules and limitations: Emotion and speaking style reference.