Text To Speech - Bank Balance

Text To Speech - Bank Balance

TTS or Text To Speech is a process which converts text to WAV file. If someone types a sentence in a note pad, TTS software would convert it to voice and plays it through speaker attached to computer or laptop. This sample automates the process of account balance enquiries and assists the customers in knowing the status of their account balance, wherever they are.

Download the evaluation version of Xtend IVR and install the telephony application in your system. Run the sample script from the Script Editor. Click here to refer the code.

The automated attendant will work as given below:

  • IVR waits for the call
  • Accepts the call and plays the Welcome message
  • IVR asks the caller to enter the account number either through speech or through keypad
  • Verifies the account number in the database
  • If the account number is valid, the IVR informs the account balance status to the caller
Download the source file zip download for the Text to Speech Application - Bank Balance


$db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=bankacc.mdb;User Id=admin;Password=;"


$retrycount = 2

MAIN:
	display "Waiting for call . . ."
	
	
	answer 1
	
	
	speak "<pitch absmiddle='5'/>Welcome to Lotus Bank Telebanking service."
	play "\pau=500\"
	
ACCEPT_ACCNO:
	
	display "Accept account number"
	
	
	$msg = "Please enter your account number"	
	$Acno = AcceptNum($msg)
	if $Acno == "" then goto GOODBYE
	
	
ACCEPT_PIN:
	
	display "Accept PIN number"
		
	
	$msg = "Please enter your pin number."	
	$Pin = AcceptNum($msg)
	if $Pin == "" then goto GOODBYE	
	
	display "Validating User"
	
	
	$sql = format("SELECT * FROM BANK WHERE AccNo = '%s'",$Acno)
	$dbalias = db.RunSQL($db, $sql)
	if $dbalias.eof
		speak "The account number you have entered is invalid."
		goto GOODBYE
	endif
	
	
	if compare($dbalias.PIN,$Pin) <> 0
		speak "The pin number you have entered is invalid."
		goto GOODBYE
	endif
	
	play "\pau=500\"
	$bal = concat("The balance amount in ", $dbalias.Name, "'s account 
			number <rate absspeed='-3'><context ID='number_digit'>", 
			$dbalias.Accno, "</context></rate> is ")
	Speak $bal
	
	
	$money = concat("<context ID = 'currency'>$",$dbalias.Balance,".</context>")
	speak $money
	
	
GOODBYE:
	
	display "Terminating Call"
	play "\pau=500\"
	speak "Thank you for using the service."
	hangup
	goto MAIN
	
	
	
ONHANGUP:
	hangup
	goto MAIN
	
	
ONSYSTEMERROR:
	log $error
	display $error
	hangup
	goto MAIN
	
function AcceptNum($speech)
	
	$retry = $retrycount
	
	while $retry > 0
		
		$digit = ""
		speak concat("<pitch absmiddle='5'/>",$speech)
		play "\pau=500\"
		
		
		srKeepGrammar(true)
		srAcceptWords("zero","one","two","three","four","five","six","seven",
			"eight","nine","0","1","2","3","4","5","6","7","8","9")
		
		while true
			$key = Input(4,5)
			if $InputMode == "S"
				if srConfidence() >= 100
					
					$value = ConvertSpeech($key)
					
					if len($value) != 0
						$digit = concat($digit,$value)
						
						
						if len($digit) >= 4
							$key = $digit
							break
						endif
					endif
				endif
			else
				break
			endif
		endwhile
		
		if len($key) != 0
			break
		endif
		$retry -= 1
	endwhile	
	
	return $key
	

function ConvertSpeech($sp)
	$result = ""
	if $sp == "zero" or $sp == "0"
		$result = "0"
	endif
	
	if $sp == "one" or $sp == "1"
		$result = "1"
	endif
	
	if $sp == "two" or $sp == "2"
		$result = "2"
	endif
	
	if $sp == "three" or $sp == "3"
		$result = "3"
	endif
	
	if $sp == "four" or $sp == "4"
		$result = "4"
	endif
	
	if $sp == "five" or $sp == "5"
		$result = "5"
	endif
	
	if $sp == "six" or $sp == "6"
		$result = "6"
	endif
	
	if $sp == "seven" or $sp == "7"
		$result = "7"
	endif
	
	if $sp == "eight" or $sp == "8"
		$result = "8"
	endif
	
	if $sp == "nine" or $sp == "9"
		$result = "9"
	endif
	
	return $result	




$Words = ""
$Ctr = 1
while $Ctr <= $PluginParamCount
	$Var = format("$PluginParam%d",$Ctr)
	$Str = alltrim($$Var)
	if len($Str) <> 0
		$Words = format("%s,%s", $Words, $Str)
	endif
	$Ctr += 1
endwhile


$Words = alltrim($Words)
if len($Words) == 0
	srGrammar("")
	return
endif


$GrmStart = '<GRAMMAR LANGID="409"> <DEFINE> 
	<ID NAME="RID_Language" VAL="409"/> </DEFINE> 
	<RULE ID="RID_Language" TOPLEVEL="ACTIVE"> <LIST PROPID="RID_Language"> '
$GrmEnd = ' </LIST> </RULE> </GRAMMAR>'
$GrmWord = ' <P>%s</P> '


$Grm = $GrmStart
while TRUE
	$Words = alltrim($Words)
	if len($Words) == 0
		break
	endif
	$pos = find($Words,',')
	if $pos == -1
		$Str = format($GrmWord,$Words)
		$Grm = format("%s%s", $Grm, $Str)
		break
	endif
	$Str = mid($Words,0,$pos)
	$Str = alltrim($Str)
	if len($Str) <> 0
		$Str = format($GrmWord,$Str)
		$Grm = format("%s%s", $Grm, $Str)
	endif
	$Words = mid($Words, $pos+1)s
endwhile
$Grm = concat($Grm, $GrmEnd)


srGrammar($Grm)
return