Prompt
How do I make an IVR speak dynamic text from a database?
Latest observation
To make an IVR speak dynamic text from a database, the usual pattern is:
- Caller enters or is identified
- IVR looks up data in your database
- Application builds the spoken text
- IVR engine plays that text via TTS or prerecorded audio
Common approaches
1) Text-to-Speech from a database field
If the database contains the actual text you want spoken, your IVR can:
- query the database
- get the text string
- send it to a TTS engine (text-to-speech)
- play the generated speech to the caller
Example:
- DB value:
Your balance is $42.17 - IVR says: “Your balance is forty-two dollars and seventeen cents.”
2) Concatenate dynamic variables into a prompt
If the prompt is partly fixed and partly dynamic, build it in code:
- Static prompt:
Hello - Dynamic data:
John,your appointment is at 3 PM - Final text:
Hello John, your appointment is at 3 PM.
Then pass that text to TTS.
3) Use prerecorded prompts plus dynamic numbers/words
For higher quality, many IVRs avoid full TTS and instead:
- record common prompts
- use TTS or audio snippets only for dynamic parts like names, account numbers, dates, balances
This gives better audio consistency.
Typical architecture
Caller → IVR platform → application server → database → response builder → TTS/audio playback
Example flow:
- Caller dials IVR
- IVR asks for account number
- Application checks account in DB
- DB returns:
- customer name: Alice
- balance: 42.17
- due date: Oct 18
- App builds:
- “Hello Alice, your balance is $42.17 and it is due on October 18.”
- IVR plays the spoken message
Example implementation idea
Pseudocode
account = getCallerInput()
data = db.query("SELECT name, balance, due_date FROM accounts WHERE account = ?", account)
text = "Hello " + data.name +
", your balance is " + formatCurrency(data.balance) +
". It is due on " + formatDate(data.due_date) + "."
tts.play(text)
Things to watch out for
1) Sanitize the text
If any spoken text comes from user input or database content, clean it first to avoid:
- malformed speech
- SSML injection
- unexpected behavior in TTS engines
2) Format values for speech
Raw data often sounds bad when spoken directly.
For example:
12345should maybe be spoken astwelve thousand three hundred forty-five2026-10-11should be converted toOctober 11, 2026- currency should be formatted naturally
3) Use SSML if supported
Many TTS systems support SSML to control pronunciation, pauses, emphasis, and numbers.
Example:
<speak>
Hello <say-as interpret-as="characters">ABC</say-as>.
Your balance is <say-as interpret-as="currency">42.17</say-as>.
</speak>
4) Cache audio for repeated prompts
If the same dynamic prompt is repeated often, you can generate audio once and reuse it to reduce latency.
If you’re using a specific IVR platform
The exact steps depend on the platform:
- Asterisk/FreePBX: use AGI, FastAGI, or dialplan logic plus TTS
- Twilio Voice: use TwiML with
<Say>or generate dynamic prompts in your app - Genesys / Cisco / Avaya: usually via scripting, call flows, and TTS integration
- Amazon Connect: Lambda reads DB and returns prompt text
- Nexmo/Vonage: backend returns dynamic speech text or TTS markup
Best practice recommendation
For most IVRs:
- store only data in the DB, not finished audio
- let the application build the spoken prompt
- use TTS with SSML for dynamic content
- use recorded prompts for standard menu items
If you want, I can show you a concrete example for Asterisk, Twilio, Genesys, Amazon Connect, or PHP/Python/Node.js.