2
0

sound_test.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --
  2. -- sound_test.lua
  3. --
  4. -- accepts two args and then rolls through the sound files
  5. -- arg 1: type
  6. -- arg 2: rate
  7. --
  8. --[[ Use a dialplan entry like this:
  9. <extension name="sound file tester">
  10. <condition field="destination_number" expression="^((8|16|32|48)000)(.*)$">
  11. <action application="lua" data="sound_test.lua $3 $1"/>
  12. <action application="hangup"/>
  13. </condition>
  14. </extension>
  15. Note the syntax of the destination number: <rate><type>
  16. Rate can be 8000, 16000, 32000, or 48000
  17. Type can be ivr, conference, voicemail, misc, digits, etc.
  18. Using the extension listed above you could call it with mod_portaudio from fs_cli:
  19. pa call 16000ivr
  20. pa call 8000conference
  21. pa call 32000conference
  22. etc.
  23. ]]
  24. -- Create tables that hold our rates and types
  25. tbl_types = {
  26. ['ascii'] = 1,
  27. ['base256'] = 1,
  28. ['conference'] = 1,
  29. ['currency'] = 1,
  30. ['digits'] = 1,
  31. ['directory'] = 1,
  32. ['ivr'] = 1,
  33. ['misc'] = 1,
  34. ['phonetic-ascii'] = 1,
  35. ['time'] = 1,
  36. ['voicemail'] = 1,
  37. };
  38. tbl_rates = {['8000'] = 1 ,['16000'] = 1, ['32000'] = 1, ['48000'] = 1};
  39. stype = argv[1];
  40. srate = argv[2];
  41. freeswitch.consoleLog("INFO","Args: Type = " .. argv[1] .. ', Rate = ' .. argv[2] .. "\n");
  42. if ( tbl_types[stype] == nil ) then
  43. freeswitch.consoleLog("ERR","Type '" .. stype .. "' is not valid.\n");
  44. elseif ( tbl_rates[srate] == nil ) then
  45. freeswitch.consoleLog("ERR","Rate '" .. srate .. "' is not valid.\n");
  46. else
  47. -- Looks good, let's play some sound files
  48. sound_base = session:getVariable('sounds_dir') .. '/en/us/callie/' .. stype .. '/' .. srate;
  49. input_file = '/tmp/filez.txt';
  50. res, what, code = os.execute('ls -1 ' .. sound_base .. ' > ' .. input_file);
  51. freeswitch.consoleLog("INFO","Result of system call: " .. what .. " " .. code .. "\n");
  52. if ( res == true and what == 'exit' and code == 0 ) then
  53. for fname in io.lines(input_file) do
  54. freeswitch.consoleLog("NOTICE","Playing file: " .. fname .. "\n");
  55. session:streamFile(sound_base .. '/' .. fname);
  56. session:sleep(100);
  57. end
  58. else
  59. freeswitch.consoleLog("ERR","Result of system call: " .. what .. " " .. code .. "\n");
  60. end
  61. end