mytest.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Please see latest version of this script at
  2. # http://wiki.freeswitch.org/wiki/Mod_python
  3. # before reporting errors
  4. from freeswitch import *
  5. def onDTMF(input, itype, funcargs):
  6. console_log("1", "\n\nonDTMF input: %s\n" % input)
  7. if input == "5":
  8. return "pause"
  9. if input == "3":
  10. return "seek:+60000"
  11. if input == "1":
  12. return "seek:-60000"
  13. if input == "0":
  14. return "stop"
  15. return None # will make the streamfile audio stop
  16. def handler(uuid):
  17. console_log("1", "... test from my python program\n")
  18. session = PySession(uuid)
  19. session.answer()
  20. session.setDTMFCallback(onDTMF, "")
  21. session.set_tts_parms("cepstral", "david")
  22. session.playFile("/path/to/your.mp3", "")
  23. session.speak("Please enter telephone number with area code and press pound sign. ")
  24. input = session.getDigits("", 11, "*#", "#", 10000)
  25. console_log("1", "result from get digits is %s\n" % input)
  26. phone_number = session.playAndGetDigits(5, 11, 3, 10000, "*#",
  27. "/sounds/test.gsm",
  28. "/sounds/invalid.gsm",
  29. "",
  30. "^17771112222$")
  31. console_log("1", "result from play_and_get_digits is %s\n" % phone_number)
  32. session.transfer("1000", "XML", "default")
  33. session.hangup("1")