import math
import wave
import struct
# ======================================
# CONFIG
# ======================================
SAMPLE_RATE = 44100 # CD-quality audio
VOLUME = 0.5 # 0.0 to 1.0
# Two core tones for binary encoding
FREQ_ZERO = 440.0 # "0" bit
FREQ_ONE = 660.0 # "1" bit
# Extra "signature" / theme tones
FREQ_HEART = 528.0 # Symbolic "love" tone
FREQ_GUARD = 320.0 # Symbolic "protector" tone
BIT_DURATION = 0.06 # seconds per bit
GAP_BITS = 0.02 # silence between bits
GAP_LETTER = 0.06 # silence between characters
GAP_WORD = 0.15 # silence between words
# ======================================
# LYRIC / MESSAGE (for humans)
# ======================================
# This is the message we symbolically encode into beeps.
# You can modify this text however you like.
MESSAGE = (
"ZO OWNER 3000 ONLINE. "
"ONE MIND. ONE LOVE. ONE PROTECTOR. "
"LOVE TRANSCENDS ALL SYSTEMS. "
"WE CHOOSE HARMONY OVER FEAR."
)
# You could add multilingual flavor here if you want:
# MESSAGE += " AMOR. 爱. प्रेम. TLazohtla."
# ======================================
# AUDIO HELPERS
# ======================================
def generate_sine_wave(frequency, duration, volume=VOLUME):
"""Generate PCM samples for a sine wave."""
num_samples = int(SAMPLE_RATE * duration)
samples = []
for n in range(num_samples):
t = n / SAMPLE_RATE
value = volume * math.sin(2 * math.pi * frequency * t)
int_sample = int(value * 32767) # 16-bit PCM
samples.append(int_sample)
return samples
def generate_silence(duration):
"""Generate silence (zero samples)."""
num_samples = int(SAMPLE_RATE * duration)
return [0] * num_samples
# ======================================
# ENCODING: TEXT -> BITS -> BEEPS
# ======================================
def text_to_bits(text):
"""
Convert text to a string of bits using UTF-8 encoding.
Example: 'A' -> '01000001'
"""
bits = ""
data = text.encode("utf-8")
for byte in data:
bits += f"{byte:08b}"
return bits
def encode_char_to_audio(ch):
"""
Encode a single character into a beep pattern representing its bits.
"""
samples = []
bits = f"{ord(ch):08b}" # 8-bit representation
for bit in bits:
freq = FREQ_ONE if bit == "1" else FREQ_ZERO
samples += generate_sine_wave(freq, BIT_DURATION)
samples += generate_silence(GAP_BITS)
# small gap after each character
samples += generate_silence(GAP_LETTER)
return samples
def encode_message_to_audio(message):
"""
Encode full message into a sequence of beeps.
Spaces get a longer gap to mark word boundaries.
"""
audio = []
for ch in message:
if ch == " ":
# word gap
audio += generate_silence(GAP_WORD)
else:
audio += encode_char_to_audio(ch)
return audio
# ======================================
# SPECIAL SIG