This Python script makes my wifi broadcast a peaceful chant every few seconds or so

 

import time

# The chant (this string is stored in memory)
chant = ["Thank","You","Air!"]

import socket
import time

# Define broadcast settings
BROADCAST_IP = '255.255.255.255'  # Standard broadcast address for your local network
PORT = 5005                       # Port number to send on (you can choose any port not in use)
chanta = "Nam ";
chantb = "Mô ";
chantc = "A "       # The chant message
chantd = "Di "       # The chant message
chante = "Đà "       # The chant message
chantf = "Phật! "
chantg = "Thank you "
chanth = "air! "
chanti = "May "
chantj = "all "
chantk = "beings "
chantl = "here "
chantm = "be "
chantn = "safe."
interval = 3.353/12                      # Time interval (in seconds) between broadcasts

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Enable the socket to send broadcast messages
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

print("Broadcasting the chant... Press Ctrl+C to stop.")

try:
    while True:
        # Send the chant as a UDP broadcast message
        sock.sendto(chanta.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chanta}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantb.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantb}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantc.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantc}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantd.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantd}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chante.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chante}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantf.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantf}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantg.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantg}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chanth.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chanth}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chanti.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chanti}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantj.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantj}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantk.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantk}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantl.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantl}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantm.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantm}",end='',flush=True)
        time.sleep(interval)
        sock.sendto(chantn.encode('utf-8'), (BROADCAST_IP, PORT))
        print(f"{chantn}",end='',flush=True)
        time.sleep(interval)
        time.sleep(interval)
        
except KeyboardInterrupt:
    print("\nBroadcasting stopped.")
finally:
    sock.close()

# i=0
# while True:
#     # "Chant" by printing the message
#     print(chant[i],end=" ",flush=True)
#     i = i+1
#     if i >= len(chant):
#         i = 0;
#         # print()
#     # Wait for a second before chanting again
#     time.sleep(0.168033)

Comments

Popular posts from this blog

Music Styles Tags List/Randomizer

Music genres/adjectives/instruments/additional elements Picker/Randomizer

Random Breed Generator (originally designed to work with comma separated Suno tags)