Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- sender.lua
- -- Transmits camera/hologram data and voice recordings to another computer
- local camera = peripheral.find("camera")
- local microphone = peripheral.find("microphone")
- local modem = peripheral.find("modem")
- if not camera then
- print("No camera found!")
- return
- end
- if not microphone then
- print("No microphone found!")
- return
- end
- if not modem then
- print("No modem found!")
- return
- end
- -- Configuration
- local CHANNEL_SEND = 1
- local CHANNEL_REPLY = 100
- local CAMERA_NETWORK = "security"
- -- Setup
- camera.setNetwork(CAMERA_NETWORK)
- camera.start()
- microphone.startListening()
- modem.open(CHANNEL_REPLY)
- print("=== Camera & Voice Sender ===")
- print("Camera network: " .. CAMERA_NETWORK)
- print("Sending on channel: " .. CHANNEL_SEND)
- print("Press Ctrl+T to stop")
- print("")
- -- Track if someone is speaking
- local currentRecording = nil
- local recordingStartTime = 0
- local MAX_RECORDING_TIME = 5 -- Max seconds per recording chunk
- while true do
- -- Check for voice events
- while microphone.hasVoiceEvent() do
- local event = microphone.getVoiceEvent()
- if event then
- if event.event == "start" then
- -- Start recording when someone speaks
- currentRecording = "voice_" .. os.epoch("utc")
- microphone.startRecording(currentRecording)
- recordingStartTime = os.epoch("utc") / 1000
- print("[VOICE] " .. event.player .. " started speaking")
- elseif event.event == "stop" then
- -- Stop recording and send when they stop
- if currentRecording then
- microphone.stopRecording()
- local packets = microphone.getRecordingPackets(currentRecording)
- if packets and #packets > 0 then
- print("[VOICE] Sending " .. #packets .. " audio packets")
- modem.transmit(CHANNEL_SEND, CHANNEL_REPLY, {
- type = "voice",
- player = event.player,
- packets = packets
- })
- end
- -- Clean up recording
- microphone.deleteRecording(currentRecording)
- currentRecording = nil
- end
- print("[VOICE] " .. event.player .. " stopped speaking")
- end
- end
- end
- -- Check if recording is too long (chunk it)
- if currentRecording then
- local elapsed = (os.epoch("utc") / 1000) - recordingStartTime
- if elapsed >= MAX_RECORDING_TIME then
- -- Send current chunk and start new recording
- microphone.stopRecording()
- local packets = microphone.getRecordingPackets(currentRecording)
- if packets and #packets > 0 then
- print("[VOICE] Sending chunk: " .. #packets .. " packets")
- modem.transmit(CHANNEL_SEND, CHANNEL_REPLY, {
- type = "voice",
- player = "chunk",
- packets = packets
- })
- end
- microphone.deleteRecording(currentRecording)
- -- Start new recording immediately
- currentRecording = "voice_" .. os.epoch("utc")
- microphone.startRecording(currentRecording)
- recordingStartTime = os.epoch("utc") / 1000
- end
- end
- -- Send camera/hologram data
- local playerData = camera.get3DPlayerData()
- local center = camera.getNetworkCenter()
- if center then
- modem.transmit(CHANNEL_SEND, CHANNEL_REPLY, {
- type = "hologram",
- players = playerData,
- center = center
- })
- if #playerData > 0 then
- print("[CAM] Tracking " .. #playerData .. " player(s)")
- end
- end
- sleep(0.05) -- 20 updates per second
- end
Advertisement
Add Comment
Please, Sign In to add comment