Python implementation of WebRTC and ORTC for real-time peer-to-peer communication
87
Build a real-time audio stream receiver that can accept incoming RTP audio streams from a remote peer, decode the audio, and save it to a file.
@generates
import asyncio
from aiortc import RTCPeerConnection, RTCSessionDescription
class AudioReceiver:
"""
Receives real-time audio from a remote WebRTC peer.
"""
def __init__(self, output_file: str):
"""
Initialize the audio receiver.
Args:
output_file: Path where received audio will be saved (WAV format)
"""
pass
async def receive_offer(self, offer_sdp: str, offer_type: str) -> dict:
"""
Process an incoming SDP offer from a remote peer and generate an answer.
Args:
offer_sdp: The SDP offer string from the remote peer
offer_type: The type of the offer (typically "offer")
Returns:
dict with keys 'sdp' (str) and 'type' (str) containing the answer
"""
pass
async def add_ice_candidate(self, candidate: str, sdp_mid: str, sdp_mline_index: int):
"""
Add an ICE candidate received from the remote peer.
Args:
candidate: The ICE candidate string
sdp_mid: Media stream identification
sdp_mline_index: Index of the media description in the SDP
"""
pass
async def start(self):
"""
Start receiving and processing audio. Blocks until the connection ends.
"""
pass
async def close(self):
"""
Close the connection and finalize the audio file.
"""
passProvides WebRTC implementation for real-time audio/video communication.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-aiortcdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10