# rentbot/audio_utils.py import numpy as np def ulaw_to_pcm16(ulaw_data): """ Converts 8-bit μ-law encoded audio to 16-bit PCM. """ # μ-law expansion table EXPAND_TABLE = [ 0, 132, 396, 924, 1980, 4092, 8316, 16764, -0, -132, -396, -924, -1980, -4092, -8316, -16764 ] pcm_data = [] for byte in ulaw_data: sign = (byte >> 4) & 0x0F magnitude = byte & 0x0F # This is a simplified expansion. A more accurate one would use bitwise operations. # However, for STT purposes, this is often sufficient. value = EXPAND_TABLE[sign] + (magnitude << (sign + 3)) pcm_data.append(value) return np.array(pcm_data, dtype=np.int16)