2
0

tdd_echo.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. local count = 0;
  2. local tddstring = {};
  3. function my_cb(s, type, obj, arg)
  4. if (arg) then
  5. freeswitch.console_log("info", "\ntype: " .. type .. "\n" .. "arg: " .. arg .. "\n");
  6. else
  7. freeswitch.console_log("info", "\ntype: " .. type .. "\n");
  8. end
  9. tdddata = obj:getHeader("TDD-Data");
  10. count = 0;
  11. table.insert(tddstring, tdddata);
  12. freeswitch.console_log("info", obj:serialize("xml"));
  13. end
  14. function all_done(s, how)
  15. freeswitch.console_log("info", "done: " .. how .. "\n");
  16. end
  17. function tablelength(T)
  18. local count = 0
  19. for _ in pairs(T) do count = count + 1 end
  20. return count
  21. end
  22. blah = "args";
  23. session:setHangupHook("all_done");
  24. session:setInputCallback("my_cb", "blah");
  25. session:answer();
  26. session:execute("playback", "silence_stream://2000");
  27. session:execute("spandsp_detect_tdd");
  28. session:execute("spandsp_send_tdd", "Welcome to FreeSWITCH");
  29. while session:ready() do
  30. session:streamFile("silence_stream://10000");
  31. if (count > 0) then
  32. count = 0;
  33. if (tablelength(tddstring) > 0) then
  34. session:execute("spandsp_send_tdd", "You said: " .. table.concat(tddstring));
  35. tddstring = {};
  36. end
  37. end
  38. count = count + 1;
  39. end