voiceTbl = {}
concommand.Add(
"record_me",
function()
hook.Remove(
"Think",
"VoiceChat_Example") voiceTbl = {}
voiceStartTick=engine.TickCount()
hook.
Add(
"HolyLib:PreProcessVoiceChat",
"VoiceChat_Example",
function(ply, voiceData)
if !voiceTbl[ply]
then
voiceTbl[ply] = {}
end
voiceTbl[ply][engine.TickCount() - voiceStartTick] =
voiceData:
CreateCopy()
end)
end)
concommand.Add(
"stop_record",
function()
hook.Remove(
"HolyLib:PreProcessVoiceChat",
"VoiceChat_Example")
end)
concommand.Add(
"play_me",
function(ply)
if !voiceTbl[ply]
then
ply:ChatPrint(
"You first need to record.")
return
end
if !player.GetBots()[1]
then
RunConsoleCommand(
"bot")
end
hook.Remove(
"HolyLib:PreProcessVoiceChat",
"VoiceChat_Example")
voiceIdx = 0
hook.
Add(
"Think",
"VoiceChat_Example",
function()
if !IsValid(ply)
then
hook.Remove(
"Think",
"VoiceChat_Example")
return
end
voiceIdx = voiceIdx + 1
local voiceData = voiceTbl[ply][voiceIdx]
if voiceData
then
voicechat.
ProcessVoiceData(player.GetBots()[1], voiceData)
end
end)
end)
concommand.Add(
"save_record",
function(ply)
local voiceStream =
voicechat.
CreateVoiceStream()
voiceStream:
SetData(voiceTbl[ply]
or {})
voicechat.
SaveVoiceStream(voiceStream,
"voiceData_" .. ply:SteamID64() ..
".dat",
"DATA")
ply:ChatPrint(
"Saved the VoiceStream")
end)
concommand.Add(
"load_record",
function(ply)
local voiceStream, status =
voicechat.
LoadVoiceStream(
"voiceData_" .. ply:SteamID64() ..
".dat",
"DATA")
if voiceStream
then
voiceTbl[ply] =
voiceStream:
GetData()
ply:ChatPrint(
"Loaded the VoiceStream")
else
ply:ChatPrint(
"Failed to load VoiceStream. You probably don't have a save.")
end
end)
concommand.Add(
"async_save_record",
function(ply)
local voiceStream =
voicechat.
CreateVoiceStream()
voiceStream:
SetData(voiceTbl[ply]
or {})
voicechat.
SaveVoiceStream(voiceStream,
"voiceData_" .. ply:SteamID64() ..
".dat",
"DATA", async,
function(voiceStream, status)
if !IsValid(ply)
then return end
ply:ChatPrint(
"Saved the VoiceStream")
end)
end)
concommand.Add(
"async_load_record",
function(ply)
voicechat.
LoadVoiceStream(
"voiceData_" .. ply:SteamID64() ..
".dat",
"DATA",
true,
function(voiceStream, status)
if !IsValid(ply)
then return end
if voiceStream
then
voiceTbl[ply] =
voiceStream:
GetData()
ply:ChatPrint(
"Loaded the VoiceStream")
else
ply:ChatPrint(
"Failed to load VoiceStream. You probably don't have a save.")
end
end)
end)