misc of python pep8 fixes
This commit is contained in:
parent
39200cd13b
commit
b0e86e65cf
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""
|
"""
|
||||||
FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||||
Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ from twisted.internet import reactor, defer
|
||||||
from twisted.internet.protocol import ClientFactory
|
from twisted.internet.protocol import ClientFactory
|
||||||
import freepy
|
import freepy
|
||||||
|
|
||||||
|
|
||||||
class FsHelper(ClientFactory):
|
class FsHelper(ClientFactory):
|
||||||
|
|
||||||
def __init__(self, host=None, passwd=None, port=None):
|
def __init__(self, host=None, passwd=None, port=None):
|
||||||
|
@ -39,17 +40,17 @@ class FsHelper(ClientFactory):
|
||||||
if passwd:
|
if passwd:
|
||||||
self.passwd = passwd
|
self.passwd = passwd
|
||||||
if port:
|
if port:
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
self.freepyd = None
|
self.freepyd = None
|
||||||
self.connection_deferred = None
|
self.connection_deferred = None
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.freepyd = None
|
self.freepyd = None
|
||||||
self.connection_deferred = None
|
self.connection_deferred = None
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
||||||
if self.freepyd:
|
if self.freepyd:
|
||||||
# if we have a protocol object, we are connected (since we always
|
# if we have a protocol object, we are connected (since we always
|
||||||
# null it upon any disconnection)
|
# null it upon any disconnection)
|
||||||
|
@ -58,7 +59,7 @@ class FsHelper(ClientFactory):
|
||||||
if self.connection_deferred:
|
if self.connection_deferred:
|
||||||
# we are already connecting, return existing dfrd
|
# we are already connecting, return existing dfrd
|
||||||
return self.connection_deferred
|
return self.connection_deferred
|
||||||
|
|
||||||
self.connection_deferred = defer.Deferred()
|
self.connection_deferred = defer.Deferred()
|
||||||
self.connection_deferred.addCallback(self.dologin)
|
self.connection_deferred.addCallback(self.dologin)
|
||||||
self.connection_deferred.addErrback(self.generalError)
|
self.connection_deferred.addErrback(self.generalError)
|
||||||
|
@ -72,29 +73,28 @@ class FsHelper(ClientFactory):
|
||||||
self.connection_deferred = None
|
self.connection_deferred = None
|
||||||
deferred2callback.callback("Connected")
|
deferred2callback.callback("Connected")
|
||||||
|
|
||||||
|
|
||||||
def generalError(self, failure):
|
def generalError(self, failure):
|
||||||
print "General error: %s" % failure
|
print "General error: %s" % failure
|
||||||
return failure
|
return failure
|
||||||
|
|
||||||
def startedConnecting(self, connector):
|
def startedConnecting(self, connector):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
return freepy.FreepyDispatcher(self.conncb, self.discocb)
|
return freepy.FreepyDispatcher(self.conncb, self.discocb)
|
||||||
|
|
||||||
def clientConnectionLost(self, connector, reason):
|
def clientConnectionLost(self, connector, reason):
|
||||||
print "clientConnectionLost! conn=%s, reason=%s" % (connector,
|
print "clientConnectionLost! conn=%s, reason=%s" % (connector,
|
||||||
reason)
|
reason)
|
||||||
self.connection_deferred = None
|
self.connection_deferred = None
|
||||||
self.freepyd = None
|
self.freepyd = None
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
print "clientConnectionFailed! conn=%s, reason=%s" % (connector,
|
print "clientConnectionFailed! conn=%s, reason=%s" % (connector,
|
||||||
reason)
|
reason)
|
||||||
self.freepyd = None
|
self.freepyd = None
|
||||||
deferred2callback = self.connection_deferred
|
deferred2callback = self.connection_deferred
|
||||||
self.connection_deferred = None
|
self.connection_deferred = None
|
||||||
deferred2callback.errback(reason)
|
deferred2callback.errback(reason)
|
||||||
|
|
||||||
def discocb(self, reason):
|
def discocb(self, reason):
|
||||||
|
@ -102,7 +102,7 @@ class FsHelper(ClientFactory):
|
||||||
self.freepyd = None
|
self.freepyd = None
|
||||||
|
|
||||||
def dologin(self, connectmsg):
|
def dologin(self, connectmsg):
|
||||||
return self.freepyd.login(self.passwd)
|
return self.freepyd.login(self.passwd)
|
||||||
|
|
||||||
def originate(self, party2dial, dest_ext_app, bgapi=True):
|
def originate(self, party2dial, dest_ext_app, bgapi=True):
|
||||||
"""
|
"""
|
||||||
|
@ -128,9 +128,6 @@ class FsHelper(ClientFactory):
|
||||||
d.addCallback(originate_inner)
|
d.addCallback(originate_inner)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dialconf(self, people2dial, conf_name, bgapi=True):
|
def dialconf(self, people2dial, conf_name, bgapi=True):
|
||||||
"""
|
"""
|
||||||
conf_name - name of conf TODO: change to match db
|
conf_name - name of conf TODO: change to match db
|
||||||
|
@ -162,7 +159,7 @@ class FsHelper(ClientFactory):
|
||||||
|
|
||||||
def listconf(self, conf_name):
|
def listconf(self, conf_name):
|
||||||
"""
|
"""
|
||||||
conf_name - name of conf
|
conf_name - name of conf
|
||||||
returns - a deferred that will be called back with a result
|
returns - a deferred that will be called back with a result
|
||||||
like:
|
like:
|
||||||
|
|
||||||
|
@ -215,7 +212,6 @@ class FsHelper(ClientFactory):
|
||||||
d.addCallback(confdtmf_inner)
|
d.addCallback(confdtmf_inner)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def confsay(self, conf_name, text2speak, bgapi=True):
|
def confsay(self, conf_name, text2speak, bgapi=True):
|
||||||
"""
|
"""
|
||||||
conf_name - name of conf
|
conf_name - name of conf
|
||||||
|
@ -253,7 +249,7 @@ class FsHelper(ClientFactory):
|
||||||
def confstop(self, conf_name, bgapi=True):
|
def confstop(self, conf_name, bgapi=True):
|
||||||
"""
|
"""
|
||||||
stop playback of all sounds
|
stop playback of all sounds
|
||||||
|
|
||||||
conf_name - name of conf
|
conf_name - name of conf
|
||||||
returns - a deferred that will be called back with a result
|
returns - a deferred that will be called back with a result
|
||||||
like:
|
like:
|
||||||
|
@ -268,7 +264,6 @@ class FsHelper(ClientFactory):
|
||||||
d.addCallback(confstop_inner)
|
d.addCallback(confstop_inner)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def showchannels(self, bgapi=True):
|
def showchannels(self, bgapi=True):
|
||||||
|
|
||||||
def showchannels_inner(ignored):
|
def showchannels_inner(ignored):
|
||||||
|
@ -289,10 +284,9 @@ class FsHelper(ClientFactory):
|
||||||
d.addCallback(killchan_inner)
|
d.addCallback(killchan_inner)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def broadcast(self, uuid, path, legs="both", bgapi=True):
|
def broadcast(self, uuid, path, legs="both", bgapi=True):
|
||||||
"""
|
"""
|
||||||
@legs - one of the following strings: aleg|bleg|both
|
@legs - one of the following strings: aleg|bleg|both
|
||||||
"""
|
"""
|
||||||
def broadcast_inner(ignored):
|
def broadcast_inner(ignored):
|
||||||
df = self.freepyd.broadcast(uuid, path, legs, bgapi)
|
df = self.freepyd.broadcast(uuid, path, legs, bgapi)
|
||||||
|
@ -325,12 +319,10 @@ class FsHelper(ClientFactory):
|
||||||
d.addCallback(sofia_profile_restart_inner)
|
d.addCallback(sofia_profile_restart_inner)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def sofia_status_profile(self, profile_name, bgapi=True):
|
def sofia_status_profile(self, profile_name, bgapi=True):
|
||||||
|
|
||||||
def sofia_status_profile_inner(ignored):
|
def sofia_status_profile_inner(ignored):
|
||||||
df = self.freepyd.sofia_status_profile(profile_name,
|
df = self.freepyd.sofia_status_profile(profile_name, bgapi)
|
||||||
bgapi)
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
d = self.connect()
|
d = self.connect()
|
||||||
|
@ -340,7 +332,7 @@ class FsHelper(ClientFactory):
|
||||||
|
|
||||||
class FsHelperTest:
|
class FsHelperTest:
|
||||||
def __init__(self, fshelper):
|
def __init__(self, fshelper):
|
||||||
self.fshelper=fshelper
|
self.fshelper = fshelper
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_dialconf(self):
|
def test_dialconf(self):
|
||||||
|
@ -349,10 +341,16 @@ class FsHelperTest:
|
||||||
# called "freeswitch" on the local freeswitch instance.
|
# called "freeswitch" on the local freeswitch instance.
|
||||||
# one party is actually another conference, just to make
|
# one party is actually another conference, just to make
|
||||||
# the example more confusing.
|
# the example more confusing.
|
||||||
people2dial = [{'name':'freeswitch',
|
people2dial = [
|
||||||
'number':'888@conference.freeswitch.org'},
|
{
|
||||||
{'name':'mouselike',
|
'name': 'freeswitch',
|
||||||
'number':'904@mouselike.org'}]
|
'number': '888@conference.freeswitch.org'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'mouselike',
|
||||||
|
'number': ' 904@mouselike.org'
|
||||||
|
}
|
||||||
|
]
|
||||||
d = self.fshelper.dialconf(people2dial, "freeswitch", bgapi=False)
|
d = self.fshelper.dialconf(people2dial, "freeswitch", bgapi=False)
|
||||||
def failed(error):
|
def failed(error):
|
||||||
print "Failed to dial users!"
|
print "Failed to dial users!"
|
||||||
|
@ -361,7 +359,7 @@ class FsHelperTest:
|
||||||
d.addErrback(failed)
|
d.addErrback(failed)
|
||||||
def worked(*args):
|
def worked(*args):
|
||||||
print "Worked! Dialed user result: %s" % str(args)
|
print "Worked! Dialed user result: %s" % str(args)
|
||||||
d.addCallback(worked)
|
d.addCallback(worked)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_listconf(self):
|
def test_listconf(self):
|
||||||
|
@ -389,7 +387,7 @@ class FsHelperTest:
|
||||||
def worked(*args):
|
def worked(*args):
|
||||||
print "Kicked user from conf, result: %s" % str(args)
|
print "Kicked user from conf, result: %s" % str(args)
|
||||||
d.addCallback(worked)
|
d.addCallback(worked)
|
||||||
|
|
||||||
|
|
||||||
def test1():
|
def test1():
|
||||||
kick_everyone = False
|
kick_everyone = False
|
||||||
|
@ -409,7 +407,7 @@ def test1():
|
||||||
print "failed: %s" % str(failure)
|
print "failed: %s" % str(failure)
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
if kick_everyone:
|
if kick_everyone:
|
||||||
d.addCallback(kickeveryone)
|
d.addCallback(kickeveryone)
|
||||||
d.addErrback(failed)
|
d.addErrback(failed)
|
||||||
#fsht.test_confkick()
|
#fsht.test_confkick()
|
||||||
#d = fshelper.connect()
|
#d = fshelper.connect()
|
||||||
|
@ -422,14 +420,14 @@ def test1():
|
||||||
def test2():
|
def test2():
|
||||||
fshelper = FsHelper(host="127.0.0.1",
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
passwd="ClueCon",
|
passwd="ClueCon",
|
||||||
port=8021)
|
port=8021)
|
||||||
fshelper.sofia_profile_restart("mydomain.com")
|
fshelper.sofia_profile_restart("mydomain.com")
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def test3():
|
def test3():
|
||||||
fshelper = FsHelper(host="127.0.0.1",
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
passwd="ClueCon",
|
passwd="ClueCon",
|
||||||
port=8021)
|
port=8021)
|
||||||
print "Calling originate.."
|
print "Calling originate.."
|
||||||
party2dial="sofia/foo/600@192.168.1.202:5080"
|
party2dial="sofia/foo/600@192.168.1.202:5080"
|
||||||
d = fshelper.originate(party2dial=party2dial,
|
d = fshelper.originate(party2dial=party2dial,
|
||||||
|
@ -439,25 +437,25 @@ def test3():
|
||||||
def worked(result):
|
def worked(result):
|
||||||
print "Originate succeeded: %s" % result
|
print "Originate succeeded: %s" % result
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
|
||||||
def failed(failure):
|
def failed(failure):
|
||||||
print "failed: %s" % str(failure)
|
print "failed: %s" % str(failure)
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
|
||||||
d.addCallback(worked)
|
d.addCallback(worked)
|
||||||
d.addErrback(failed)
|
d.addErrback(failed)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
def test4():
|
def test4():
|
||||||
fshelper = FsHelper(host="127.0.0.1",
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
passwd="ClueCon",
|
passwd="ClueCon",
|
||||||
port=8021)
|
port=8021)
|
||||||
|
|
||||||
def worked(result):
|
def worked(result):
|
||||||
print "Originate succeeded: %s" % result
|
print "Originate succeeded: %s" % result
|
||||||
#reactor.stop()
|
#reactor.stop()
|
||||||
|
|
||||||
def failed(failure):
|
def failed(failure):
|
||||||
print "failed: %s" % str(failure)
|
print "failed: %s" % str(failure)
|
||||||
#reactor.stop()
|
#reactor.stop()
|
||||||
|
@ -470,39 +468,39 @@ def test4():
|
||||||
bgapi=True)
|
bgapi=True)
|
||||||
d.addCallback(worked)
|
d.addCallback(worked)
|
||||||
d.addErrback(failed)
|
d.addErrback(failed)
|
||||||
party2dial="sofia/foo/someone@bar.com"
|
party2dial="sofia/foo/someone@bar.com"
|
||||||
d2 = fshelper.originate(party2dial=party2dial,
|
d2 = fshelper.originate(party2dial=party2dial,
|
||||||
dest_ext_app=dest_ext_app,
|
dest_ext_app=dest_ext_app,
|
||||||
bgapi=True)
|
bgapi=True)
|
||||||
|
|
||||||
d2.addCallback(worked)
|
d2.addCallback(worked)
|
||||||
d2.addErrback(failed)
|
d2.addErrback(failed)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
def test5():
|
def test5():
|
||||||
fshelper = FsHelper(host="127.0.0.1",
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
passwd="ClueCon",
|
passwd="ClueCon",
|
||||||
port=8021)
|
port=8021)
|
||||||
|
|
||||||
def worked(result):
|
def worked(result):
|
||||||
print "Originate succeeded: %s" % result
|
print "Originate succeeded: %s" % result
|
||||||
#reactor.stop()
|
#reactor.stop()
|
||||||
|
|
||||||
def failed(failure):
|
def failed(failure):
|
||||||
print "failed: %s" % str(failure)
|
print "failed: %s" % str(failure)
|
||||||
#reactor.stop()
|
#reactor.stop()
|
||||||
|
|
||||||
for i in xrange(20):
|
for i in xrange(20):
|
||||||
|
party2dial = "sofia/foo/600@192.168.1.202:5080"
|
||||||
party2dial="sofia/foo/600@192.168.1.202:5080"
|
|
||||||
d = fshelper.originate(party2dial=party2dial,
|
d = fshelper.originate(party2dial=party2dial,
|
||||||
dest_ext_app="700",
|
dest_ext_app="700",
|
||||||
bgapi=True)
|
bgapi=True)
|
||||||
d.addCallback(worked)
|
d.addCallback(worked)
|
||||||
d.addErrback(failed)
|
d.addErrback(failed)
|
||||||
|
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
def test6():
|
def test6():
|
||||||
"""
|
"""
|
||||||
|
@ -514,17 +512,17 @@ def test6():
|
||||||
from wikipbx import channelsutil
|
from wikipbx import channelsutil
|
||||||
def show_chanels(raw_xml):
|
def show_chanels(raw_xml):
|
||||||
print raw_xml
|
print raw_xml
|
||||||
|
|
||||||
def failure(failure):
|
def failure(failure):
|
||||||
print failure
|
print failure
|
||||||
|
|
||||||
d = fshelper.showchannels(bgapi=False)
|
d = fshelper.showchannels(bgapi=False)
|
||||||
d.addCallback(show_chanels)
|
d.addCallback(show_chanels)
|
||||||
d.addErrback(failure)
|
d.addErrback(failure)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
|
||||||
|
if __name__ == "__main__":
|
||||||
#test1()
|
#test1()
|
||||||
#test2()
|
#test2()
|
||||||
#test3()
|
#test3()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""
|
"""
|
||||||
FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||||
Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||||
|
|
||||||
|
@ -23,13 +23,14 @@ the Initial Developer. All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s): Traun Leyden <tleyden@branchcut.com>
|
Contributor(s): Traun Leyden <tleyden@branchcut.com>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Data models for objects inside freeswitch
|
Data models for objects inside freeswitch
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class ConfMember:
|
class ConfMember:
|
||||||
|
|
||||||
def __init__(self, rawstring):
|
def __init__(self, rawstring):
|
||||||
|
@ -45,7 +46,7 @@ class ConfMember:
|
||||||
self.energy_level = None
|
self.energy_level = None
|
||||||
|
|
||||||
self.parse(self.rawstring)
|
self.parse(self.rawstring)
|
||||||
|
|
||||||
def parse(self, rawstring):
|
def parse(self, rawstring):
|
||||||
"""
|
"""
|
||||||
1;sofia/mydomain.com/user@somewhere.com;898e6552-24ab-11dc-9df7-9fccd4095451;FreeSWITCH;0000000000;hear|speak;0;0;300
|
1;sofia/mydomain.com/user@somewhere.com;898e6552-24ab-11dc-9df7-9fccd4095451;FreeSWITCH;0000000000;hear|speak;0;0;300
|
||||||
|
@ -76,6 +77,6 @@ class ConfMember:
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s (%s)" % (self.member_id, self.member_uri)
|
return "%s (%s)" % (self.member_id, self.member_uri)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""
|
"""
|
||||||
FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||||
Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class FreepyRequest(object):
|
||||||
debug("setRequestFinished called. response_content: %s " %
|
debug("setRequestFinished called. response_content: %s " %
|
||||||
self.response_content)
|
self.response_content)
|
||||||
self.finished = True
|
self.finished = True
|
||||||
|
|
||||||
def getDeferred(self):
|
def getDeferred(self):
|
||||||
return self.deferred
|
return self.deferred
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class FreepyRequest(object):
|
||||||
if not line.strip() or len(line.strip()) == 0:
|
if not line.strip() or len(line.strip()) == 0:
|
||||||
self._fsm.BlankLine()
|
self._fsm.BlankLine()
|
||||||
return self.isRequestFinished()
|
return self.isRequestFinished()
|
||||||
|
|
||||||
matchstr = re.compile("auth/request", re.I)
|
matchstr = re.compile("auth/request", re.I)
|
||||||
result = matchstr.search(line)
|
result = matchstr.search(line)
|
||||||
if (result != None):
|
if (result != None):
|
||||||
|
@ -159,7 +159,7 @@ class LoginRequest(FreepyRequest):
|
||||||
"""
|
"""
|
||||||
Example success response
|
Example success response
|
||||||
========================
|
========================
|
||||||
|
|
||||||
lineReceived: Content-Type: auth/request
|
lineReceived: Content-Type: auth/request
|
||||||
lineReceived:
|
lineReceived:
|
||||||
lineReceived: Content-Type: command/reply
|
lineReceived: Content-Type: command/reply
|
||||||
|
@ -176,7 +176,7 @@ class LoginRequest(FreepyRequest):
|
||||||
lineReceived:
|
lineReceived:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(LoginRequest, self).__init__()
|
super(LoginRequest, self).__init__()
|
||||||
import loginrequest_sm
|
import loginrequest_sm
|
||||||
|
@ -190,7 +190,7 @@ class LoginRequest(FreepyRequest):
|
||||||
return
|
return
|
||||||
msg = "Login failed, most likely a bad password"
|
msg = "Login failed, most likely a bad password"
|
||||||
self.errbackDeferred(Failure(Exception(msg)))
|
self.errbackDeferred(Failure(Exception(msg)))
|
||||||
|
|
||||||
def getReplyText(self):
|
def getReplyText(self):
|
||||||
self.response_content
|
self.response_content
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ class BgApiRequest(FreepyRequest):
|
||||||
|
|
||||||
linereceived: Content-Type: command/reply
|
linereceived: Content-Type: command/reply
|
||||||
linereceived: Reply-Text: +OK Job-UUID: 788da080-24e0-11dc-85f6-3d7b12..
|
linereceived: Reply-Text: +OK Job-UUID: 788da080-24e0-11dc-85f6-3d7b12..
|
||||||
linereceived:
|
linereceived:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -233,7 +233,7 @@ class ApiRequest(FreepyRequest):
|
||||||
lineReceived:
|
lineReceived:
|
||||||
lineReceived: Call Requested: result: [SUCCESS]
|
lineReceived: Call Requested: result: [SUCCESS]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ApiRequest, self).__init__()
|
super(ApiRequest, self).__init__()
|
||||||
import apirequest_sm
|
import apirequest_sm
|
||||||
|
@ -255,7 +255,7 @@ class ApiRequest(FreepyRequest):
|
||||||
# we need to add it back .. otherwise the Content-length
|
# we need to add it back .. otherwise the Content-length
|
||||||
# will be off by one
|
# will be off by one
|
||||||
line += "\n"
|
line += "\n"
|
||||||
|
|
||||||
self.response_content += line
|
self.response_content += line
|
||||||
if len(self.response_content) == self.content_length:
|
if len(self.response_content) == self.content_length:
|
||||||
return True
|
return True
|
||||||
|
@ -272,7 +272,7 @@ class ApiRequest(FreepyRequest):
|
||||||
# By default, just return accumulated string
|
# By default, just return accumulated string
|
||||||
return self.response_content
|
return self.response_content
|
||||||
|
|
||||||
|
|
||||||
class DialoutRequest(ApiRequest):
|
class DialoutRequest(ApiRequest):
|
||||||
"""
|
"""
|
||||||
Example raw dialout response
|
Example raw dialout response
|
||||||
|
@ -291,7 +291,7 @@ class DialoutRequest(ApiRequest):
|
||||||
class BgDialoutRequest(BgApiRequest):
|
class BgDialoutRequest(BgApiRequest):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(BgDialoutRequest, self).__init__()
|
super(BgDialoutRequest, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
class ConfKickRequest(ApiRequest):
|
class ConfKickRequest(ApiRequest):
|
||||||
"""
|
"""
|
||||||
|
@ -314,13 +314,13 @@ class BgConfKickRequest(BgApiRequest):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(BgConfKickRequest, self).__init__()
|
super(BgConfKickRequest, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
class ListConfRequest(ApiRequest):
|
class ListConfRequest(ApiRequest):
|
||||||
"""
|
"""
|
||||||
Response to request to list conferences:
|
Response to request to list conferences:
|
||||||
========================================
|
========================================
|
||||||
|
|
||||||
lineReceived: Content-Type: api/response
|
lineReceived: Content-Type: api/response
|
||||||
lineReceived: Content-Length: 233
|
lineReceived: Content-Length: 233
|
||||||
lineReceived:
|
lineReceived:
|
||||||
|
@ -332,7 +332,7 @@ class ListConfRequest(ApiRequest):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ListConfRequest, self).__init__()
|
super(ListConfRequest, self).__init__()
|
||||||
self.conf_members = []
|
self.conf_members = []
|
||||||
|
|
||||||
def add_content(self, line):
|
def add_content(self, line):
|
||||||
"""
|
"""
|
||||||
conf not empty example
|
conf not empty example
|
||||||
|
@ -352,13 +352,13 @@ class ListConfRequest(ApiRequest):
|
||||||
else:
|
else:
|
||||||
confmember = models.ConfMember(line)
|
confmember = models.ConfMember(line)
|
||||||
self.conf_members.append(confmember)
|
self.conf_members.append(confmember)
|
||||||
|
|
||||||
return super(ListConfRequest, self).add_content(line)
|
return super(ListConfRequest, self).add_content(line)
|
||||||
|
|
||||||
def getResponse(self):
|
def getResponse(self):
|
||||||
|
|
||||||
# TODO: parse this content into a meaningful
|
# TODO: parse this content into a meaningful
|
||||||
# 'object' .. though, not sure this is really
|
# 'object' .. though, not sure this is really
|
||||||
# necessary. wait till there's a need
|
# necessary. wait till there's a need
|
||||||
return self.conf_members
|
return self.conf_members
|
||||||
|
|
||||||
|
|
|
@ -2,24 +2,24 @@
|
||||||
# http://wiki.freeswitch.org/wiki/Mod_python
|
# http://wiki.freeswitch.org/wiki/Mod_python
|
||||||
# before reporting errors
|
# before reporting errors
|
||||||
|
|
||||||
import sys, time
|
|
||||||
from freeswitch import *
|
from freeswitch import *
|
||||||
|
|
||||||
|
|
||||||
def onDTMF(input, itype, funcargs):
|
def onDTMF(input, itype, funcargs):
|
||||||
console_log("1","\n\nonDTMF input: %s\n" % input)
|
console_log("1", "\n\nonDTMF input: %s\n" % input)
|
||||||
if input == "5":
|
if input == "5":
|
||||||
return "pause"
|
return "pause"
|
||||||
if input == "3":
|
if input == "3":
|
||||||
return "seek:+60000"
|
return "seek:+60000"
|
||||||
if input == "1":
|
if input == "1":
|
||||||
return "seek:-60000"
|
return "seek:-60000"
|
||||||
if input == "0":
|
if input == "0":
|
||||||
return "stop"
|
return "stop"
|
||||||
return None # will make the streamfile audio stop
|
return None # will make the streamfile audio stop
|
||||||
|
|
||||||
|
|
||||||
def handler(uuid):
|
def handler(uuid):
|
||||||
|
console_log("1", "... test from my python program\n")
|
||||||
console_log("1","... test from my python program\n")
|
|
||||||
session = PySession(uuid)
|
session = PySession(uuid)
|
||||||
session.answer()
|
session.answer()
|
||||||
session.setDTMFCallback(onDTMF, "")
|
session.setDTMFCallback(onDTMF, "")
|
||||||
|
@ -27,13 +27,12 @@ def handler(uuid):
|
||||||
session.playFile("/path/to/your.mp3", "")
|
session.playFile("/path/to/your.mp3", "")
|
||||||
session.speak("Please enter telephone number with area code and press pound sign. ")
|
session.speak("Please enter telephone number with area code and press pound sign. ")
|
||||||
input = session.getDigits("", 11, "*#", "#", 10000)
|
input = session.getDigits("", 11, "*#", "#", 10000)
|
||||||
console_log("1","result from get digits is %s\n" % input)
|
console_log("1", "result from get digits is %s\n" % input)
|
||||||
phone_number = session.playAndGetDigits(5, 11, 3, 10000, "*#",
|
phone_number = session.playAndGetDigits(5, 11, 3, 10000, "*#",
|
||||||
"/sounds/test.gsm",
|
"/sounds/test.gsm",
|
||||||
"/sounds/invalid.gsm",
|
"/sounds/invalid.gsm",
|
||||||
"",
|
"",
|
||||||
"^17771112222$");
|
"^17771112222$")
|
||||||
console_log("1","result from play_and_get_digits is %s\n" % phone_number)
|
console_log("1", "result from play_and_get_digits is %s\n" % phone_number)
|
||||||
session.transfer("1000", "XML", "default")
|
session.transfer("1000", "XML", "default")
|
||||||
session.hangup("1")
|
session.hangup("1")
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,14 @@ from freeswitch import *
|
||||||
from py_modules.speechtools import Grammar, SpeechDetect
|
from py_modules.speechtools import Grammar, SpeechDetect
|
||||||
from py_modules.speechtools import SpeechObtainer
|
from py_modules.speechtools import SpeechObtainer
|
||||||
|
|
||||||
import time, os
|
import os
|
||||||
|
|
||||||
VOICE_ENGINE = "cepstral"
|
VOICE_ENGINE = "cepstral"
|
||||||
VOICE = "William"
|
VOICE = "William"
|
||||||
GRAMMAR_ROOT = "/usr/src/freeswitch_trunk/scripts"
|
GRAMMAR_ROOT = "/usr/src/freeswitch_trunk/scripts"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Example speech recognition application in python.
|
Example speech recognition application in python.
|
||||||
|
|
||||||
How to make this work:
|
How to make this work:
|
||||||
|
|
||||||
|
@ -20,24 +20,24 @@ How to make this work:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class RecipeWizard:
|
class RecipeWizard:
|
||||||
|
|
||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
self.session=session
|
self.session = session
|
||||||
self.session.set_tts_parms(VOICE_ENGINE, VOICE)
|
self.session.set_tts_parms(VOICE_ENGINE, VOICE)
|
||||||
self.main()
|
self.main()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
console_log("debug", "recipe wizard main()\n")
|
||||||
console_log("debug", "recipe wizard main()\n")
|
self.speechdetect = SpeechDetect(self.session, "openmrcp", "127.0.0.1")
|
||||||
self.speechdetect = SpeechDetect(self.session, "openmrcp", "127.0.0.1");
|
|
||||||
self.speechobtainer = SpeechObtainer(speech_detect=self.speechdetect,
|
self.speechobtainer = SpeechObtainer(speech_detect=self.speechdetect,
|
||||||
required_phrases=1,
|
required_phrases=1,
|
||||||
wait_time=5000,
|
wait_time=5000,
|
||||||
max_tries=3)
|
max_tries=3)
|
||||||
gfile = os.path.join(GRAMMAR_ROOT, "mainmenu.xml")
|
gfile = os.path.join(GRAMMAR_ROOT, "mainmenu.xml")
|
||||||
self.grammar = Grammar("mainmenu", gfile,"input",80,90)
|
self.grammar = Grammar("mainmenu", gfile, "input", 80, 90)
|
||||||
self.speechobtainer.setGrammar(self.grammar);
|
self.speechobtainer.setGrammar(self.grammar)
|
||||||
console_log("debug", "calling speechobtainer.run()\n")
|
console_log("debug", "calling speechobtainer.run()\n")
|
||||||
self.speechobtainer.detectSpeech()
|
self.speechobtainer.detectSpeech()
|
||||||
self.session.speak("Hello. Welcome to the recipe wizard. Drinks or food?")
|
self.session.speak("Hello. Welcome to the recipe wizard. Drinks or food?")
|
||||||
|
@ -47,8 +47,9 @@ class RecipeWizard:
|
||||||
self.session.speak("Received result. Result is: %s" % result[0])
|
self.session.speak("Received result. Result is: %s" % result[0])
|
||||||
else:
|
else:
|
||||||
self.session.speak("Sorry, I did not hear you")
|
self.session.speak("Sorry, I did not hear you")
|
||||||
|
|
||||||
console_log("debug", "speechobtainer.run() finished\n")
|
console_log("debug", "speechobtainer.run() finished\n")
|
||||||
|
|
||||||
|
|
||||||
def mainmenu():
|
def mainmenu():
|
||||||
"""
|
"""
|
||||||
|
@ -78,10 +79,9 @@ def mainmenu():
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def handler(uuid):
|
def handler(uuid):
|
||||||
session = PySession(uuid)
|
session = PySession(uuid)
|
||||||
session.answer()
|
session.answer()
|
||||||
rw = RecipeWizard(session)
|
rw = RecipeWizard(session)
|
||||||
session.hangup("1")
|
session.hangup("1")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue