ElijahCrafter

Audio Transfer and Hologram Test Send

Dec 3rd, 2025 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 KB | Source Code | 0 0
  1. -- sender.lua
  2. -- Transmits camera/hologram data and voice recordings to another computer
  3.  
  4. local camera = peripheral.find("camera")
  5. local microphone = peripheral.find("microphone")
  6. local modem = peripheral.find("modem")
  7.  
  8. if not camera then
  9.     print("No camera found!")
  10.     return
  11. end
  12.  
  13. if not microphone then
  14.     print("No microphone found!")
  15.     return
  16. end
  17.  
  18. if not modem then
  19.     print("No modem found!")
  20.     return
  21. end
  22.  
  23. -- Configuration
  24. local CHANNEL_SEND = 1
  25. local CHANNEL_REPLY = 100
  26. local CAMERA_NETWORK = "security"
  27.  
  28. -- Setup
  29. camera.setNetwork(CAMERA_NETWORK)
  30. camera.start()
  31. microphone.startListening()
  32. modem.open(CHANNEL_REPLY)
  33.  
  34. print("=== Camera & Voice Sender ===")
  35. print("Camera network: " .. CAMERA_NETWORK)
  36. print("Sending on channel: " .. CHANNEL_SEND)
  37. print("Press Ctrl+T to stop")
  38. print("")
  39.  
  40. -- Track if someone is speaking
  41. local currentRecording = nil
  42. local recordingStartTime = 0
  43. local MAX_RECORDING_TIME = 5  -- Max seconds per recording chunk
  44.  
  45. while true do
  46.     -- Check for voice events
  47.     while microphone.hasVoiceEvent() do
  48.         local event = microphone.getVoiceEvent()
  49.         if event then
  50.             if event.event == "start" then
  51.                 -- Start recording when someone speaks
  52.                 currentRecording = "voice_" .. os.epoch("utc")
  53.                 microphone.startRecording(currentRecording)
  54.                 recordingStartTime = os.epoch("utc") / 1000
  55.                 print("[VOICE] " .. event.player .. " started speaking")
  56.             elseif event.event == "stop" then
  57.                 -- Stop recording and send when they stop
  58.                 if currentRecording then
  59.                     microphone.stopRecording()
  60.                    
  61.                     local packets = microphone.getRecordingPackets(currentRecording)
  62.                     if packets and #packets > 0 then
  63.                         print("[VOICE] Sending " .. #packets .. " audio packets")
  64.                         modem.transmit(CHANNEL_SEND, CHANNEL_REPLY, {
  65.                             type = "voice",
  66.                             player = event.player,
  67.                             packets = packets
  68.                         })
  69.                     end
  70.                    
  71.                     -- Clean up recording
  72.                     microphone.deleteRecording(currentRecording)
  73.                     currentRecording = nil
  74.                 end
  75.                 print("[VOICE] " .. event.player .. " stopped speaking")
  76.             end
  77.         end
  78.     end
  79.    
  80.     -- Check if recording is too long (chunk it)
  81.     if currentRecording then
  82.         local elapsed = (os.epoch("utc") / 1000) - recordingStartTime
  83.         if elapsed >= MAX_RECORDING_TIME then
  84.             -- Send current chunk and start new recording
  85.             microphone.stopRecording()
  86.            
  87.             local packets = microphone.getRecordingPackets(currentRecording)
  88.             if packets and #packets > 0 then
  89.                 print("[VOICE] Sending chunk: " .. #packets .. " packets")
  90.                 modem.transmit(CHANNEL_SEND, CHANNEL_REPLY, {
  91.                     type = "voice",
  92.                     player = "chunk",
  93.                     packets = packets
  94.                 })
  95.             end
  96.            
  97.             microphone.deleteRecording(currentRecording)
  98.            
  99.             -- Start new recording immediately
  100.             currentRecording = "voice_" .. os.epoch("utc")
  101.             microphone.startRecording(currentRecording)
  102.             recordingStartTime = os.epoch("utc") / 1000
  103.         end
  104.     end
  105.    
  106.     -- Send camera/hologram data
  107.     local playerData = camera.get3DPlayerData()
  108.     local center = camera.getNetworkCenter()
  109.    
  110.     if center then
  111.         modem.transmit(CHANNEL_SEND, CHANNEL_REPLY, {
  112.             type = "hologram",
  113.             players = playerData,
  114.             center = center
  115.         })
  116.        
  117.         if #playerData > 0 then
  118.             print("[CAM] Tracking " .. #playerData .. " player(s)")
  119.         end
  120.     end
  121.    
  122.     sleep(0.05)  -- 20 updates per second
  123. end
Advertisement
Add Comment
Please, Sign In to add comment