I have created this tool which is a module that is a dynamic music player that loads in assets from the Catalogue and plays either a single song or a playlist based on the query.
. Eliza DJ - Creator Store (roblox.com)
This is based off a Tool I created for a Large Language Model. This can be used to create an efficient and diverse music player. =]
Here’s an example of how to use the code
cm=require(workspace.MusicPlayer:Clone()) print(cm.DiscJockey(" play some haunted music"),game.Players.LocalPlayer)
For those interested here is the entire code!
local cm={}
local audioargs={
query="",
audiotype="",
playlist="",
}
local debris=game:GetService("Debris")
local internalstop=false
function cm.Playlist(result,player,stop)
spawn(function()
for i, page in ipairs(result:GetCurrentPage()) do
local audio=Instance.new("Sound")--script.ErrorSound:Clone()--
pcall(function()audio.SoundId="rbxassetid://"..page.Id end)
debris:AddItem(audio,tonumber(page.Duration)+6)
audio.Parent=player.PlayerGui
audio:Play()
local incre=16
for i=1, incre do
task.wait(tonumber(page.Duration/incre))
if internalstop ==true then
break
end
end
task.wait()
end
end)
end
function cm.AudioScraper(query,audiotype,playlist,player,recycle)
local searchParams = Instance.new("AudioSearchParams")
searchParams.SearchKeyword = query
if audiotype==nil then
audiotype="music"
end
if string.find(audiotype:lower(),"stop") or string.find(query:lower(),"stop") then
internalstop=true
else
internalstop=false
end
searchParams.AudioSubType=Enum.AudioSubType[audiotype]
local assetService = game:GetService("AssetService")
local success, result = pcall(function()
return assetService:SearchAudio(searchParams)
end)
if success then
print(result:GetFullName())
print(result:GetChildren())
for i, page in ipairs(result:GetCurrentPage()) do
print(page.AudioType)
print(page.Id)
if playlist==true then
cm.Playlist(result,player)
else
local audio=Instance.new("Sound") pcall(function()audio.SoundId="rbxassetid://"..page.Id end)
if recycle==nil then debris:AddItem(audio,tonumber(page.Duration)+6)
end
audio.Parent=player.PlayerGui
audio:Play()
end
return "",page.Description
end
else
warn("Failed to search audio assets: " .. result)
end
end
function cm.Music(argumentsJson,player)
print(argumentsJson.query)
local audioresult,response=cm.AudioScraper(argumentsJson.query,argumentsJson.audiotype,argumentsJson.playlist,player)
end
function cm.DiscJockey(text,player)
local response = ""
local user = string.lower(text)
local userOrig = user
-- randomly selected replies if no keywords
local randReplies = {
"What does that suggest to you?",
"I see...",
"I'm not sure I understand you fully.",
"Can you elaborate on that?",
"That is quite interesting!",
"That's so... Please continue...",
"I understand...", "Well, well... Do go on",
"Why are you saying that?",
"Please explain the background to that remark...",
"Could you say that again, in a different way?",
}
local audioargs={
query="",
audiotype="Music",
playlist=true,
}
local replies = {
["song"] = {{"Perhaps you would like to be able to"},{" play a song", " play some music", " play a track"},function(query)
local audioargs={
query=query,
audiotype="Music",
playlist=false,
}
cm.Music(audioargs,player)
end},
["playlist"] ={{"Perhaps you would like to be able to"},{" play a playlist", " play the playlist", " play some "},function(query)
local audioargs={
query=query,
audiotype="Music",
playlist=true,
}
cm.Music(audioargs,player)
end},
--["change character"] = {"Perhaps you would like to be able to"},{" play a playlist", " play the playlist"}
}
-- keywords, replies
-- conjugate
local conjugate = {
[" i "] = "you",
[" are "] = "am",
[" were "] = "was",
[" you "] = "me",
[" your "] = "my",
[" i've "] = "you've",
[" i'm "] = "you're",
[" me "] = "you",
[" am i "] = "you are",
[" am "] = "are",
}
local function createSentences(str)
local sentences = {} -- create an empty table to store the sentences
local start = 1 -- initialize the start index of the current sentence
for i = 1, #str do -- loop through each character in the input string
local c = str:sub(i, i) -- get the current character
if c == "!" or c == "?" or c == "." or i==#str then -- check if the current character is a punctuation mark
local sentence = str:sub(start, i) -- get the current sentence from the start index to the current index
table.insert(sentences, sentence) -- insert the current sentence into the table
start = i + 1 -- update the start index to the next character after the punctuation mark
end
end
if sentences[1]==nil then
return {str}
end
-- random replies, no keyword
return sentences -- return the table of sentences
end
local function processSentences(user,response)
-- find keyword, phrase
local function replyRandomly()
response = randReplies[math.random(#randReplies)]..""
end
local function processInput()
for key, variables in replies do
for num, keyword in variables[2] do
local d, e = string.find(user, keyword, 1, 1)
if d then
local reply=variables[1]--[math.random(1,#variables[1])]
-- process keywords
local chr=reply[math.random(1,#reply)]
response = response..chr.." "
if string.byte(string.sub(chr, -1)) < 65 then -- "A"
response = response..""; return
end
local h = string.len(user) - (d + string.len(keyword))
if h > 0 then
user = string.sub(user, -h)
end
for cFrom, cTo in pairs(conjugate) do
local f, g = string.find(user, cFrom, 1, 1)
if f then
local j = string.sub(user, 1, f - 1).." "..cTo
local z = string.len(user) - (f - 1) - string.len(cTo)
response = response..j..""
if z > 2 then
local l = string.sub(user, -(z - 2))
if not string.find(userOrig, l) then return end
end
if z > 2 then response = response..string.sub(user, -(z - 2)).."" end
if z < 2 then response = response.."" end
return
end--if f
end--for
response = response..user..""
variables[3](user)
return response,user
end--if d
end
end--for
replyRandomly()
return response
end
-- main()
-- accept user input
if string.sub(user, 1, 3) == "bye" then
response = "Bye, bye for now.See you again some time."
return response
end
if string.sub(user, 1, 7) == "because" then
user = string.sub(user, 8)
end
user = " "..user.." "
-- process input, print reply
processInput()
response = response..""
return response
end
local responsec=""
local responses={}
for i,v in pairs(createSentences(user)) do
local response=nil
local answ=processSentences(v," ")
if responses[answ]==nil then
print(responses)
responses[answ]=1
responsec=responsec..answ
end
end
return responsec
end
return cm
It’s build off this architecture and template.
Eliza Chatbot Ported to Luau [Open-Source] - Resources / Community Resources - Developer Forum | Roblox