Hints

Use speech hints to improve recognition accuracy for domain-specific vocabulary, brand names, technical terms, and other words the STT engine might misinterpret.

View as MarkdownOpen in Claude

Why Use Hints?

Speech Hints.
Speech Hints

Adding Simple Hints

Single Hint

1from signalwire_agents import AgentBase
2
3
4class MyAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="my-agent")
7 self.add_language("English", "en-US", "rime.spore")
8
9 # Add single hint
10 self.add_hint("Acme")
11 self.add_hint("SignalWire")

Multiple Hints

1## Add list of hints
2self.add_hints([
3 "Acme",
4 "SignalWire",
5 "API",
6 "webhook",
7 "SWML"
8])

What to Hint

CategoryExamples
Brand NamesAcme Corp, SignalWire, company name, product names
Technical TermsAPI, webhook, OAuth, SDK, JSON
Industry JargonKYC, AML, SLA, EOD, PTO
NamesEmployee names, customer names, location names
Numbers/CodesAccount numbers, ZIP codes, reference IDs
ActionsTransfer, escalate, reschedule

Hint Examples by Use Case

Customer Service

1self.add_hints([
2 # Brand and products
3 "Acme", "Acme Pro", "Acme Enterprise",
4
5 # Common actions
6 "account", "billing", "refund", "exchange", "return",
7 "cancel", "upgrade", "downgrade",
8
9 # Support terms
10 "representative", "supervisor", "escalate", "ticket",
11 "case number", "reference number"
12])

Technical Support

1self.add_hints([
2 # Product names
3 "Windows", "macOS", "Linux", "Chrome", "Firefox",
4
5 # Technical terms
6 "reboot", "restart", "reinstall", "cache", "cookies",
7 "browser", "firewall", "antivirus", "driver",
8
9 # Error terms
10 "error code", "blue screen", "crash", "freeze",
11 "not responding", "won't start"
12])

Healthcare

1self.add_hints([
2 # Appointment terms
3 "appointment", "reschedule", "cancel", "follow-up",
4
5 # Medical terms
6 "prescription", "refill", "pharmacy", "dosage",
7 "medication", "symptoms", "diagnosis",
8
9 # Department names
10 "cardiology", "dermatology", "pediatrics", "radiology",
11
12 # Common medications (if applicable)
13 "Tylenol", "Advil", "Lipitor", "Metformin"
14])

Financial Services

1self.add_hints([
2 # Account terms
3 "checking", "savings", "IRA", "401k", "Roth",
4
5 # Transaction terms
6 "transfer", "deposit", "withdrawal", "wire",
7 "ACH", "routing number", "account number",
8
9 # Services
10 "mortgage", "auto loan", "credit card", "overdraft",
11
12 # Verification
13 "social security", "date of birth", "mother's maiden name"
14])

Pattern Hints (Advanced)

Pattern hints use regular expressions to match and normalize spoken input. They’re useful for:

  • Normalizing common mishearings of brand names
  • Capturing structured data (account numbers, order IDs)
  • Handling variations in how people say things

Pattern Hint Syntax

1self.add_pattern_hint(
2 hint="what STT should listen for",
3 pattern=r"regex pattern to match",
4 replace="normalized output",
5 ignore_case=True # optional, default False
6)

Common Pattern Examples

Brand name normalization:

1# Catch common mishearings of "Acme"
2self.add_pattern_hint(
3 hint="Acme",
4 pattern=r"(acme|ackme|ac me|acmee)",
5 replace="Acme",
6 ignore_case=True
7)
8
9# SignalWire variations
10self.add_pattern_hint(
11 hint="SignalWire",
12 pattern=r"(signal wire|signalwire|signal-wire)",
13 replace="SignalWire",
14 ignore_case=True
15)

Account/Order numbers:

1# 8-digit account numbers
2self.add_pattern_hint(
3 hint="account number",
4 pattern=r"\d{8}",
5 replace="${0}" # Keep the matched digits
6)
7
8# Order IDs like "ORD-12345"
9self.add_pattern_hint(
10 hint="order ID",
11 pattern=r"ORD[-\s]?\d{5,8}",
12 replace="${0}",
13 ignore_case=True
14)

Phone numbers:

1# Various phone number formats
2self.add_pattern_hint(
3 hint="phone number",
4 pattern=r"\d{3}[-.\s]?\d{3}[-.\s]?\d{4}",
5 replace="${0}"
6)

Email addresses:

1self.add_pattern_hint(
2 hint="email",
3 pattern=r"\S+@\S+\.\S+",
4 replace="${0}"
5)

Dates:

1# Dates like "January 15th" or "Jan 15"
2self.add_pattern_hint(
3 hint="date",
4 pattern=r"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\s+\d{1,2}(st|nd|rd|th)?",
5 replace="${0}",
6 ignore_case=True
7)

Pattern Hint Tips

Test patterns first:

Before adding pattern hints, test your regex at a site like regex101.com. STT output may vary from what you expect.

Start simple:

Begin with basic patterns and refine based on actual transcription errors you observe.

Use capture groups carefully:

  • ${0} = entire match
  • ${1} = first capture group
  • ${2} = second capture group, etc.

Debug with logging:

Enable debug logging to see what STT produces, then craft patterns to match.

1import logging
2logging.basicConfig(level=logging.DEBUG)

Order matters:

If multiple patterns could match, they’re evaluated in registration order. Put more specific patterns first.

Organizing Hints

For large hint lists, organize by category:

1class OrganizedHintsAgent(AgentBase):
2 # Hint categories
3 BRAND_HINTS = ["Acme", "Acme Pro", "Acme Enterprise"]
4 ACTION_HINTS = ["account", "billing", "refund", "cancel"]
5 SUPPORT_HINTS = ["representative", "supervisor", "escalate"]
6
7 def __init__(self):
8 super().__init__(name="organized-hints")
9 self.add_language("English", "en-US", "rime.spore")
10
11 # Add all hint categories
12 self.add_hints(self.BRAND_HINTS)
13 self.add_hints(self.ACTION_HINTS)
14 self.add_hints(self.SUPPORT_HINTS)

Dynamic Hints

Add hints based on context:

1class DynamicHintsAgent(AgentBase):
2 DEPARTMENT_HINTS = {
3 "sales": ["pricing", "quote", "demo", "trial", "discount"],
4 "support": ["ticket", "bug", "error", "fix", "issue"],
5 "billing": ["invoice", "payment", "refund", "charge"]
6 }
7
8 def __init__(self):
9 super().__init__(name="dynamic-hints")
10 self.add_language("English", "en-US", "rime.spore")
11
12 # Common hints for all departments
13 self.add_hints(["Acme", "account", "help"])
14
15 def on_swml_request(self, request_data=None, callback_path=None, request=None):
16 call_data = (request_data or {}).get("call", {})
17 called_num = call_data.get("to", "")
18
19 # Add department-specific hints
20 if "555-1000" in called_num:
21 self.add_hints(self.DEPARTMENT_HINTS["sales"])
22 elif "555-2000" in called_num:
23 self.add_hints(self.DEPARTMENT_HINTS["support"])
24 else:
25 self.add_hints(self.DEPARTMENT_HINTS["billing"])

Hint Best Practices

DO:

  • Hint brand names and product names
  • Hint technical terms specific to your domain
  • Hint common employee/customer names
  • Hint acronyms and abbreviations
  • Test with actual callers to find missed words

DON’T:

  • Hint common English words (already recognized well)
  • Add hundreds of hints (quality over quantity)
  • Hint full sentences (single words/short phrases work best)
  • Forget to update hints when products/terms change

Testing Hints

Use swaig-test to verify hints are included:

$## View SWML including hints
$swaig-test my_agent.py --dump-swml | grep -A 20 "hints"

Check the generated SWML for the hints array:

1{
2 "version": "1.0.0",
3 "sections": {
4 "main": [{
5 "ai": {
6 "hints": [
7 "Acme",
8 "SignalWire",
9 "account",
10 "billing"
11 ]
12 }
13 }]
14 }
15}

Complete Example

1#!/usr/bin/env python3
2## hinted_agent.py - Agent with speech recognition hints
3from signalwire_agents import AgentBase, SwaigFunctionResult
4
5
6class HintedAgent(AgentBase):
7 def __init__(self):
8 super().__init__(name="hinted-agent")
9 self.add_language("English", "en-US", "rime.spore")
10
11 # Brand hints
12 self.add_hints([
13 "Acme", "Acme Pro", "Acme Enterprise",
14 "AcmePay", "AcmeCloud"
15 ])
16
17 # Product SKUs
18 self.add_hints([
19 "SKU", "A100", "A200", "A300",
20 "PRO100", "ENT500"
21 ])
22
23 # Common actions
24 self.add_hints([
25 "account", "billing", "invoice", "refund",
26 "cancel", "upgrade", "downgrade",
27 "representative", "supervisor"
28 ])
29
30 # Technical terms
31 self.add_hints([
32 "API", "webhook", "integration",
33 "OAuth", "SSO", "MFA"
34 ])
35
36 self.prompt_add_section(
37 "Role",
38 "You are a customer service agent for Acme Corporation."
39 )
40
41 self.define_tool(
42 name="lookup_product",
43 description="Look up product by SKU",
44 parameters={
45 "type": "object",
46 "properties": {
47 "sku": {
48 "type": "string",
49 "description": "Product SKU like A100 or PRO100"
50 }
51 },
52 "required": ["sku"]
53 },
54 handler=self.lookup_product
55 )
56
57 def lookup_product(self, args, raw_data):
58 sku = args.get("sku", "").upper()
59 products = {
60 "A100": "Acme Basic - $99/month",
61 "A200": "Acme Standard - $199/month",
62 "A300": "Acme Premium - $299/month",
63 "PRO100": "Acme Pro - $499/month",
64 "ENT500": "Acme Enterprise - Custom pricing"
65 }
66 if sku in products:
67 return SwaigFunctionResult(f"{sku}: {products[sku]}")
68 return SwaigFunctionResult(f"SKU {sku} not found.")
69
70
71if __name__ == "__main__":
72 agent = HintedAgent()
73 agent.run()

Next Steps

You now know how to build and configure agents. Next, learn about SWAIG functions to add custom capabilities.