Pure asyncio RTP protocol implementation with G.711 μ-law codec support and precise 20ms frame timing with drift correction. Complete RTP session management for bidirectional audio over UDP.
# Source: https://github.com/aicc2025/sip-to-ai | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""RTP session with precise 20ms timing using asyncio.
This module implements RTP (Real-time Transport Protocol) for audio streaming
with G.711 codec support and precise 20ms frame timing.
"""
import asyncio
import audioop
import random
from dataclasses import dataclass
from typing import AsyncIterator, Callable, Optional
import structlog
logger = structlog.get_logger(__name__)
class PortBindError(Exception):
"""Raised when RTP port binding fails (port already in use)."""
def __init__(self, port: int, original_error: Exception):
self.port = port
self.origina
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key