Created
December 8, 2021 15:14
-
-
Save xopr/a1520ad966663efb9dababbd8427828b to your computer and use it in GitHub Desktop.
Radio Bergeijk extension (saved for backup purposes)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getEpisodes() | |
local soundDir = '/mnt/nasi/Media/Muziek/Radio Bergeijk/'; | |
local f = assert(io.popen('find "' .. soundDir .. '" -type f | sort')); | |
local output = f:read('*all'); | |
f:close(); | |
local episodes = {} | |
for line in output:gmatch("([^\n]*)\n?") do | |
if (line ~= '') then | |
freeswitch.consoleLog('info', line); | |
table.insert(episodes, line); | |
end | |
end | |
return episodes | |
end | |
function checkValid(num) | |
return (num > 0 and num <= #episodes) | |
end | |
function playEpisode(num) | |
dtmfString = '' | |
if (checkValid(num)) then | |
episode = num; | |
session:speak('Playing episode ' .. num .. ' of ' .. #episodes); | |
freeswitch.consoleLog('info', 'NOW PLAYING: ' .. episodes[num]); | |
session:setInputCallback('parseInput', 'false'); | |
session:streamFile(episodes[num]) | |
episode = num + 1; | |
if (episode > #episodes) then | |
episode = 1; | |
end | |
end | |
end | |
function parseInput(session, type, obj, arg) | |
if (type == 'dtmf') then | |
if tonumber(obj['digit']) ~= nil then | |
dtmfString = dtmfString .. obj['digit']; | |
elseif (obj['digit'] == '*' and dtmfString ~= '') then | |
if (checkValid(tonumber(dtmfString))) then | |
return "stop"; | |
else | |
dtmfString = ''; | |
end | |
end | |
end | |
end | |
session:answer(); | |
session:setAutoHangup(false); | |
session:set_tts_params('flite', 'kal'); | |
dtmfString = ''; | |
episodes = getEpisodes(); | |
episode = 1; | |
while (session:ready()) do | |
os.execute('sleep 1'); | |
if (dtmfString ~= '') then | |
playEpisode(tonumber(dtmfString)); | |
else | |
playEpisode(episode); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment