3232from ._proto .room_pb2 import (
3333 TranscriptionSegment as ProtoTranscriptionSegment ,
3434)
35- from ._utils import BroadcastQueue
35+ from ._utils import BroadcastQueue , split_utf8
3636from .track import LocalTrack
3737from .track_publication import (
3838 LocalTrackPublication ,
@@ -555,19 +555,48 @@ async def stream_text(
555555 topic : str = "" ,
556556 extensions : Dict [str , str ] = {},
557557 reply_to_id : str | None = None ,
558+ total_size : int | None = None ,
558559 ) -> TextStreamWriter :
560+ """
561+ Returns a TextStreamWriter that allows to write individual chunks of text to a text stream.
562+ In most cases where you want to simply send a text message use send_text() instead.
563+ """
559564 writer = TextStreamWriter (
560565 self ,
561566 topic = topic ,
562567 extensions = extensions ,
563568 reply_to_id = reply_to_id ,
564569 destination_identities = destination_identities ,
570+ total_size = total_size ,
565571 )
566572
567573 await writer ._send_header ()
568574
569575 return writer
570576
577+ async def send_text (
578+ self ,
579+ text : str ,
580+ destination_identities : List [str ] = [],
581+ topic : str = "" ,
582+ extensions : Dict [str , str ] = {},
583+ reply_to_id : str | None = None ,
584+ ):
585+ total_size = len (text .encode ())
586+ writer = await self .stream_text (
587+ destination_identities = destination_identities ,
588+ topic = topic ,
589+ extensions = extensions ,
590+ reply_to_id = reply_to_id ,
591+ total_size = total_size ,
592+ )
593+
594+ for chunk in split_utf8 (text , STREAM_CHUNK_SIZE ):
595+ await writer .write (chunk )
596+ await writer .close ()
597+
598+ return writer .info
599+
571600 async def stream_file (
572601 self ,
573602 file_name : str ,
@@ -577,6 +606,10 @@ async def stream_file(
577606 stream_id : str | None = None ,
578607 destination_identities : List [str ] = [],
579608 ) -> FileStreamWriter :
609+ """
610+ Returns a FileStreamWriter that allows to write individual chunks of bytes to a file stream.
611+ In cases where you want to simply send a file from the file system use send_file() instead.
612+ """
580613 writer = FileStreamWriter (
581614 self ,
582615 file_name = file_name ,
0 commit comments