#!/usr/bin/env python3 """ Create a silent OPUS audio file with 1 second of silence. """ import os import opuslib import numpy as np import struct # Configuration SAMPLE_RATE = 48000 CHANNELS = 1 FRAME_SIZE = 960 # 20ms at 48kHz SILENCE_DURATION = 1.0 # seconds OUTPUT_FILE = "silent.opus" # Calculate number of frames needed num_frames = int((SAMPLE_RATE * SILENCE_DURATION) / (FRAME_SIZE * CHANNELS)) # Initialize Opus encoder enc = opuslib.Encoder(SAMPLE_RATE, CHANNELS, 'voip') # Create silent audio data (all zeros) silent_frame = struct.pack('h' * FRAME_SIZE * CHANNELS, *([0] * FRAME_SIZE * CHANNELS)) # Create Ogg Opus file with open(OUTPUT_FILE, 'wb') as f: # Write Ogg header f.write(b'OggS') # Magic number f.write(b'\x00') # Version f.write(b'\x00') # Header type (0 = normal) f.write(b'\x00\x00\x00\x00\x00\x00\x00\x00') # Granule position f.write(b'\x00\x00\x00\x00') # Bitstream serial number f.write(b'\x00\x00\x00\x00') # Page sequence number f.write(b'\x00\x00\x00\x00') # Checksum f.write(b'\x01') # Number of segments f.write(b'\x00') # Segment table (0 = 1 byte segment) # Write Opus header f.write(b'OpusHead') # Magic signature f.write(b'\x01') # Version f.write(chr(CHANNELS).encode('latin1')) # Channel count f.write(struct.pack('