DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
f6c920b
Branches
Tags
master
memoire
src
vocalreview.lua
Abbreviate vocal review "hard, good, easy?" to "rating?"
John Smith
commited
f6c920b
at 2023-168 08:55:16
vocalreview.lua
Blame
History
Raw
--[[ presents `text` thru text-to-speech, with language/voice code `lang` (`false` or `nil` for default) `text` and `lang` may also both be parallel tables implementation may be platform-specific ]] local function speak(text, conf, lang) if type(text) == "string" and (type(lang) == "string" or type(lang) == "nil") then text = {text} lang = {lang} end for i, t in ipairs(text) do os.execute(string.format( "espeak %s %s %q", conf:get("EspeakFlags") or "", lang[i] and ("-v " .. lang[i]) or "", t )) end end local function fn(config, deck, deckfname) if not isatty() then io.write("Review should be done in the terminal\n") return nil end -- collect list of index-pairs for prompts to be reviewed this session local ctrt = review.list(deck, config, function(pr) return not pr:spt():find("IMG%[") end) speak(string.format( "%d prompts to review; how many in this session? ", #ctrt ), config) local climt = io.read("l") local climn = tonumber(climt) if not climn then speak("Input not a number; aborting", conf) return nil end climn = math.min(climn, #ctrt) local lrc = 0 local editqueue = {} local start = os.time() -- review prompts in this session's set for ind, ip in ipairs(ctrt) do if ind > climn then break end local pr = deck[ip[1]][ip[2]] -- remove braces for display local pst = pr.text:gsub("%{([^{}]+)%}", "%1") local st = os.time() io.write(pst .. "\n" .. ind .. "/" .. climn .. "\n") local qt, ql, at, al = prspeak(pr) local heard = false while not heard do speak(qt, config, ql) if io.read("l") ~= "r" then heard = true end end speak(at, config, al) speak("rating?", config) local resp = io.read("l") local sc = review.succfromstr(resp) if sc == -1 then table.insert(editqueue, ip) else if sc == 0 then lrc = lrc + 1 end review.update(deck[ip[1]][ip[2]], st, sc, config) end clear() if resp:sub(#resp):lower() == "q" then climn = ind break end end if #ctrt > 0 then local endt = os.time() io.write(string.format( "Reviewed %d prompts in %d seconds\n", math.min(#ctrt, climn), endt - start )) local s if lrc == 1 then s = "" else s = "s" end io.write(string.format( "(%d lapse%s, %f seconds per card)\n", lrc, s, (endt - start) / math.min(#ctrt, climn) )) end if #editqueue > 0 then io.write(string.format("The following cards are marked for correction:\n")) for _, ip in ipairs(editqueue) do io.write(string.format("%d:%d %s\n", ip[1], ip[2], deck[ip[1]][ip[2]])) end end if climn > 0 then return deck end end return { desc = "(v)ocal review session", nd = true, fn = fn }