Welcome, guest | Sign In | My Account | Store | Cart

The Voicent Python Simple Interface class contains the following functions.

callText
callAudio
callStatus
callRemove
callTillConfirm

These functions are used to invoke telephone calls from your Python program. For example, callText is used to call a specified number and automatically play your text message using text-to-speech engine.

In order for this class to work, you'll need to have Voicent Gateway installed somewhere in your network. This class simply sends HTTP request for telephone calls to the gateway. Voicent has a free edition for the gateway. You can download it from http://www.voicent.com

More information can be found at: http://www.voicent.com/devnet/docs/pyapi.htm

Python, 121 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import urllib
import time


class Voicent:
	def __init__(self, host="localhost", port="8155"):
		self.host_ = host
		self.port_ = port

	def callText(self, phoneno, text, selfdelete):
		urlstr = "/ocall/callreqHandler.jsp"

		param = {'info' : 'simple text call',
                         'phoneno' : phoneno,
			 'firstocc' : 10,
			 'txt' : text,
			 'selfdelete' : selfdelete}

		rcstr = self.postToGateway(urlstr, param)
		return self.getReqId(rcstr)

	def callAudio(self, phoneno, filename, selfdelete):
		urlstr = "/ocall/callreqHandler.jsp"

		param = {'info' : 'simple audio call',
			 'phoneno' : phoneno,
			 'firstocc' : 10,
			 'audiofile' : filename,
        		 'selfdelete' : selfdelete}

		rcstr = self.postToGateway(urlstr, param)
		return self.getReqId(rcstr)

	def callStatus(self, reqId):
		urlstr = "/ocall/callstatusHandler.jsp"
		param = {'reqid' : reqId}
		rcstr = self.postToGateway(urlstr, param)
		
		if (rcstr.find("^made^") != -1):
			return "Call Made"

		if (rcstr.find("^failed^") != -1):
			return "Call Failed"

		if (rcstr.find("^retry^") != -1):
			return "Call Will Retry"

		return ""

	def callRemove(self, reqId):
		urlstr = "/ocall/callremoveHandler.jsp"
		param = {'reqid' : reqId}
		rcstr = self.postToGateway(urlstr, param)

	def callTillConfirm(self, vcastexe, vocfile, wavfile, ccode):
		urlstr = "/ocall/callreqHandler.jsp"

		cmdline = "\""
		cmdline += vocfile
		cmdline += "\""
		cmdline += " -startnow"
		cmdline += " -confirmcode "
		cmdline += ccode
		cmdline += " -wavfile "
		cmdline += "\""
		cmdline += wavfile
		cmdline += "\""

		param = {'info' : 'Simple Call till Confirm',
			 'phoneno' : '1111111',
			 'firstocc' : 10,
			 'selfdelete' : 0,
			 'startexec' : vcastexe,
			 'cmdline' : cmdline}

		self.postToGateway(urlstr, param)


	def postToGateway(self, urlstr, poststr):
		params = urllib.urlencode(poststr)
		url = "http://" + self.host_ + ":" + self.port_ + urlstr
		f = urllib.urlopen(url, params)
		return f.read()

	def getReqId(self, rcstr):
		index1 = rcstr.find("[ReqId=")
		if (index1 == -1):
			return ""
		index1 += 7

		index2 = rcstr.find("]", index1)
		if (index2 == -1):
			return ""

		return rcstr[index1:index2]



#
# Uncomment out the following for your test
#
#put your own number there
#phoneno = "111-2222"
#
#v = Voicent()
#v.callText(phoneno, "hello, how are you", "1")

#reqid = v.callAudio(phoneno, "C:/Program Files/Voicent/MyRecordings/sample_message.wav", "0")

#while (1):
#	time.sleep(1)
#	status = v.callStatus(reqid)
#	if (status != ""):
#		break

#v.callRemove(reqid)

#v.callTillConfirm("C:/Program Files/Voicent/BroadcastByPhone/bin/vcast.exe",
#                  "C:/temp/testctf.voc",
#                  "C:/Program Files/Voicent/MyRecordings/sample_message.wav",
#                  "1234")