Cursed Conlang Circus 3 submission
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

5 months ago
  1. #!/usr/bin/env lua
  2. --- Transforms a code into a list of file to stitch
  3. ---@param code string the code to parse
  4. ---@return table
  5. local function parse(code)
  6. if type(code) ~= "string" then error("parse expects a string") end
  7. local filemap = {
  8. ["1"] = "1.wav",
  9. ["2"] = "2.wav",
  10. ["3"] = "3.wav",
  11. ["4"] = "4.wav",
  12. ["5"] = "5.wav",
  13. ["6"] = "6.wav",
  14. ["7"] = "7.wav",
  15. ["8"] = "8.wav",
  16. ["9"] = "9.wav",
  17. ["0"] = "0.wav",
  18. ["*"] = "Star.wav",
  19. ["#"] = "Octothorpe.wav",
  20. ["A"] = "A.wav",
  21. ["B"] = "B.wav",
  22. ["C"] = "C.wav",
  23. ["D"] = "D.wav",
  24. ["-"] = "skip.wav",
  25. }
  26. local seq = {}
  27. for i = 1, #code do
  28. table.insert(seq, filemap[code:sub(i, i)] or filemap["-"])
  29. end
  30. return seq
  31. end
  32. local args = {...}
  33. local i = 1
  34. while i <= #args do
  35. local code = args[i]
  36. local out = args[i+1] or "out.wav"
  37. local sequence = parse(code)
  38. local list = io.open(out .. ".filelist", "w")
  39. if not list then
  40. io.stderr:write("Cannot open `" .. out .. ".filelist\n")
  41. io.stderr:write("Abborting\n")
  42. os.exit(1)
  43. end
  44. for _, v in ipairs(sequence) do
  45. list:write("file '" .. v .. "'\n")
  46. end
  47. list:close()
  48. os.execute("ffmpeg -f concat -safe 0 -i " .. out .. ".filelist -c copy " .. out)
  49. i = i + 2
  50. end