local sensor = peripheral.find("plethora:sensor") local monitors = {peripheral.find("monitor")} -- Get all bees in an area to define a randomseed local function defineRandomSeed() local entities = sensor.sense() local seed = "" for k,entity in pairs(entities) do seed = seed .. math.abs(math.floor(entity.x)) .. math.abs(math.floor(entity.y)) .. math.abs(math.floor(entity.z)) end if not (seed == nil or "") then math.randomseed(tonumber(seed)) end end --print(Markov) function say(message) local voice = "" local gender = math.random(1,2) if gender == 1 then voice = "m"..math.random(1,7) elseif gender == 2 then voice = "f"..math.random(1,5) end local url = "https://music.madefor.cc/tts?text=" .. textutils.urlEncode(message) .."&voice=en-us%2B"..voice local response, err = http.get { url = url, binary = true } if not response then error(err, 0) end local speaker = peripheral.find("speaker") local decoder = require("cc.audio.dfpwm").make_decoder() while true do local chunk = response.read(16 * 1024) if not chunk then break end local buffer = decoder(chunk) while not speaker.playAudio(buffer) do os.pullEvent("speaker_audio_empty") end end end local request = http.get("http://:1234/getmarkov") local markov = textutils.unserializeJSON(request.readAll()) request.close() local words={} --Get dictionary of all the words for purposes local n=0 for k,v in pairs(markov) do n=n+1 words[n]=k end local depth = 3 local function split(str, f) tbl = {} for i in str:gmatch("[^" .. n .. "]+") do table.insert(tbl, i) end return tbl end local function log(text, mark) if mark then local tbl = split(text, "\n") tbl[mark] = tbl[mark] .. " SELECTED" text = table.concat(tbl, "\n") end print(text) for k,m in pairs(monitors) do local old = term.current() term.redirect(m) print(text) term.redirect(old) end end while true do local sentence = {} local firstwords = words[math.random(#words)] --sentence[1] = firstwords:match("([^ ]+) [^ ]+") --sentence[2] = firstwords:match("[^ ]+ ([^ ]+)") for word in firstwords:gmatch("%S+") do table.insert(sentence, word) end for x=depth+1,16 do defineRandomSeed() local correct = true for y=1,depth,1 do if sentence[x-y] == nil then correct = false end end if correct then --local lastwords = sentence[x-2] .. " " .. sentence[x-1] local lastwords = "" for y=depth,1,-1 do lastwords = lastwords .. sentence[x-y] .. " " end lastwords = lastwords:sub(1, -2) -- log("'" .. lastwords .. "'") if not (markov[lastwords] == nil) and (#markov[lastwords] > 0) then local randnum = math.random(#markov[lastwords]) -- log(textutils.serialize(markov[lastwords]), randnum+1) sentence[x] = markov[lastwords][randnum] end end end local output = "" for k,v in pairs(sentence) do output = output .. v .. " " end log(output) say(output) sleep(3) end