Add the last one
This commit is contained in:
parent
5769eca2f2
commit
f40da609ad
4 changed files with 170 additions and 0 deletions
1
artist.lua
Normal file
1
artist.lua
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
shell.run(".artist.d/src/launch.lua")
|
||||||
127
lol.lua
Normal file
127
lol.lua
Normal file
|
|
@ -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://<NotForYou>: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
|
||||||
31
markovread.lua
Normal file
31
markovread.lua
Normal file
|
|
@ -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)
|
||||||
11
startup.lua
Normal file
11
startup.lua
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
function lol()
|
||||||
|
while true do
|
||||||
|
turtle.suckUp()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function artist()
|
||||||
|
shell.run("artist")
|
||||||
|
end
|
||||||
|
|
||||||
|
parallel.waitForAll(lol, artist)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue