sound_test.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. ['zrtp'] = 1
  38. };
  39. tbl_rates = {['8000'] = 1 ,['16000'] = 1, ['32000'] = 1, ['48000'] = 1};
  40. stype = argv[1];
  41. srate = argv[2];
  42. freeswitch.consoleLog("INFO","Args: Type = " .. argv[1] .. ', Rate = ' .. argv[2] .. "\n");
  43. if ( tbl_types[stype] == nil ) then
  44. freeswitch.consoleLog("ERR","Type '" .. stype .. "' is not valid.\n");
  45. elseif ( tbl_rates[srate] == nil ) then
  46. freeswitch.consoleLog("ERR","Rate '" .. srate .. "' is not valid.\n");
  47. else
  48. -- Looks good, let's play some sound files
  49. sound_base = session:getVariable('sounds_dir') .. '/en/us/callie/' .. stype .. '/' .. srate;
  50. input_file = '/tmp/filez.txt';
  51. res = os.execute('ls -1 ' .. sound_base .. ' > ' .. input_file);
  52. freeswitch.consoleLog("INFO","Result of system call: " .. res .. "\n");
  53. if ( res == 0 ) then
  54. for fname in io.lines(input_file) do
  55. freeswitch.consoleLog("NOTICE","Playing file: " .. fname .. "\n");
  56. session:streamFile(sound_base .. '/' .. fname);
  57. session:sleep(100);
  58. end
  59. else
  60. freeswitch.consoleLog("ERR","Result of system call: " .. res .. "\n");
  61. end
  62. end