def _create_owned_stream(self) -> Any: ...
# ask-ai
b
def _create_owned_stream(self) -> Any: assert self._track is not None req = proto_ffi.FfiRequest() new_audio_stream = req.new_audio_stream new_audio_stream.track_handle = self._track._ffi_handle.handle new_audio_stream.sample_rate = self._sample_rate new_audio_stream.num_channels = self._num_channels if self._frame_size_ms: new_audio_stream.frame_size_ms = self._frame_size_ms new_audio_stream.type = proto_audio_frame.AudioStreamType.AUDIO_STREAM_NATIVE if self._audio_filter_module is not None: new_audio_stream.audio_filter_module_id = self._audio_filter_module if self._audio_filter_options is not None: new_audio_stream.audio_filter_options = json.dumps(self._audio_filter_options) resp = FfiClient.instance.request(req) return resp.new_audio_stream.stream explain this from audio_stream.py
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
_create_owned_stream
method in
audio_stream.py
is responsible for creating a new audio stream designed to receive audio frames from a specific track. Here’s a step-by-step breakdown of what it does and how it fits into LiveKit’s audio stream infrastructure: • Track Validation: Ensures a track is attached to the instance before proceeding. • FFI Request Creation: Sets up a protocol buffer request (FFI), which enables Python code to communicate with the underlying Rust implementation. • Stream Configuration: Assigns track handle, sample rate, channel count, frame size (if set), and marks the stream as a native audio stream. • Audio Filter Configuration: If audio filtering (like noise cancellation) is enabled, it attaches filter modules and their options, allowing server-side audio processing. • FFI Request Execution: Sends the request through the FFI client, creating the stream on the Rust side. The method returns an object representing the new audio stream. This function acts as the bridge between the Python SDK and the native Rust-based WebRTC/audio processing engine, allowing for efficient and configurable audio stream creation within LiveKit’s architecture. For more details, see the internal documentation on audio streams in the Python SDK. Sources: livekit-rtc/livekit/rtc/_proto/ffi_pb2.pyi
b
so the new audio goes to the speech to text?
t
Hey there! I wanted to give you a heads up about something important with audio streams and speech-to-text. The stream created by
_create_owned_stream
won't automatically send audio to the STT service – you'll need to do a bit of manual work. Don't worry, though! Here's a friendly guide to connecting your audio stream to the speech-to-text system: 1. First, create an
AudioStream
from your track. 2. Next, set up a separate STT stream. 3. Then, you'll want to manually forward those audio frames. It's pretty straightforward – here's an example:
Copy code
async for ev in audio_stream:
    stt_stream.push_frame(ev.frame)
This is just how LiveKit's current SDK is set up, so a little extra step is needed to get your speech-to-text working smoothly. Hope this helps! Sources: livekit-rtc/livekit/rtc/audio_stream.py | Transcriptions | LiveKit Docs