quart#
Quart is an async Python web framework based on Flask. VoiceStream provides integrations to send and receive audio using websockets using Quart.
Note
Flask generally uses SocketIO through the Flask_SocketIO library, which is different from regular WebSockets. If you just want regular websockets, it’s easier to switch to Quart, which is a drop in replacement.
- async voice_stream.integrations.quart.quart_websocket_sink(async_iter: AsyncIterator[str | Dict | bytes]) None#
Takes an async iterator and sends everything to a Quart websocket. Handles .
- async voice_stream.integrations.quart.quart_websocket_source() AsyncIterator[bytes | str]#
Data flow source for receiving messages from a Quart WebSocket connection.
This function facilitates the handling of incoming text or binary messages from a client connected through a Quart WebSocket. It continuously listens for messages and yields them as they arrive. The function handles the WebSocket connection lifecycle by accepting the connection and managing disconnection events.
- Returns:
An asynchronous iterator that yields incoming messages as bytes or strings.
- Return type:
AsyncIterator[Union[bytes, str]]
Notes
The function uses an infinite loop to listen for messages. It exits the loop and stops iterating when a CancelledError exception occurs.
Examples
>>> from quart import Quart >>> import asyncio >>> >>> app = Quart() >>> >>> @app.websocket("/ws") >>> async def websocket_endpoint(): >>> stream = quart_websocket_source(websocket) >>> stream = map_step(stream, lambda x: "Echo: "+x) >>> await quart_websocket_sink(stream)