diff --git a/artist.lua b/artist.lua new file mode 100644 index 0000000..d127949 --- /dev/null +++ b/artist.lua @@ -0,0 +1 @@ +shell.run(".artist.d/src/launch.lua") \ No newline at end of file diff --git a/lol.lua b/lol.lua new file mode 100644 index 0000000..fe9a362 --- /dev/null +++ b/lol.lua @@ -0,0 +1,127 @@ +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 diff --git a/markovread.lua b/markovread.lua new file mode 100644 index 0000000..959040f --- /dev/null +++ b/markovread.lua @@ -0,0 +1,31 @@ +local markov_name = "bigmarkov.txt" + +dofile(markov_name) + +--print(Markov) + +local words={} +local n=0 + +for k,v in pairs(Markov) do + n=n+1 + words[n]=k +end + +local sentence = {} + +sentence[1] = words[math.random(#words)] + +for x=2,10,1 do + local lastword = sentence[x-1] + if not (Markov[lastword] == nil) then + sentence[x] = Markov[lastword][math.random(#Markov[lastword])] + end +end + +local output = "" +for k,v in pairs(sentence) do + output = output .. v .. " " +end + +print(output) \ No newline at end of file diff --git a/startup.lua b/startup.lua new file mode 100644 index 0000000..d9d0e66 --- /dev/null +++ b/startup.lua @@ -0,0 +1,11 @@ +function lol() + while true do + turtle.suckUp() + end +end + +function artist() + shell.run("artist") +end + +parallel.waitForAll(lol, artist)