View module source on GitHub

is_silence

def is_silence(pcm_bytes, threshold=500, min_silence_ratio=0.95)
Detects if the given PCM16 byte buffer is mostly silence. Arguments:
NameTypeDescription
pcm_bytesbytesPCM16LE audio data.
thresholdintMax absolute value to consider as silence.
min_silence_ratiofloatMinimum ratio of silent samples to consider the buffer as silence.
Returns:
NameDescription
boolTrue if buffer is mostly silence, False otherwise.

pcm16_to_wav_bytes

def pcm16_to_wav_bytes(pcm_bytes: bytes,
                       num_channels: int = 1,
                       sample_rate: int = 24000) -> bytes
Convert PCM-16 audio data to WAV format bytes. Arguments:
NameTypeDescription
pcm_bytesbytesRaw PCM-16 audio data
num_channelsintNumber of audio channels (default: 1)
sample_rateintSample rate in Hz (default: 24000)
Returns:
NameDescription
bytesWAV format audio data

make_object_serializable

def make_object_serializable(obj: Any) -> Any
Convert any Python object into a JSON-serializable format while preserving as much information as possible about the original object. Arguments:
NameDescription
objAny Python object
Returns: A JSON-serializable representation of the object