Skip to content

Commit

Permalink
transcription
Browse files Browse the repository at this point in the history
  • Loading branch information
keepingitneil committed Apr 27, 2024
1 parent 0d8cb8a commit 806a88b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion livekit-rtc/livekit/rtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
RemoteTrackPublication,
TrackPublication,
)
from .transcription import TranscriptionSegment
from .transcription import Transcription, TranscriptionSegment
from .version import __version__
from .video_frame import (
VideoFrame,
Expand Down Expand Up @@ -110,6 +110,7 @@
"LocalTrackPublication",
"RemoteTrackPublication",
"TrackPublication",
"Transcription",
"TranscriptionSegment",
"VideoFrame",
"VideoSource",
Expand Down
20 changes: 8 additions & 12 deletions livekit-rtc/livekit/rtc/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
RemoteTrackPublication,
TrackPublication,
)
from .transcription import TranscriptionSegment
from .transcription import Transcription


class PublishTrackError(Exception):
Expand Down Expand Up @@ -131,13 +131,7 @@ async def publish_data(
if cb.publish_data.error:
raise PublishDataError(cb.publish_data.error)

async def publish_transcription(
self,
participant_identity: str,
track_id: str,
segments: List[TranscriptionSegment],
language: str,
) -> None:
async def publish_transcription(self, transcription: Transcription) -> None:
req = proto_ffi.FfiRequest()
proto_segments = [
ProtoTranscriptionSegment(
Expand All @@ -147,13 +141,15 @@ async def publish_transcription(
end_time=s.end_time,
final=s.final,
)
for s in segments
for s in transcription.segments
]
# fmt: off
req.publish_transcription.local_participant_handle = self._ffi_handle.handle
req.publish_transcription.participant_identity = participant_identity
req.publish_transcription.participant_identity = transcription.participant_identity
req.publish_transcription.segments.extend(proto_segments)
req.publish_transcription.track_id = track_id
req.publish_transcription.language = language
req.publish_transcription.track_id = transcription.track_id
req.publish_transcription.language = transcription.language
# fmt: on
queue = FfiClient.instance.queue.subscribe()
try:
resp = FfiClient.instance.request(req)
Expand Down
9 changes: 9 additions & 0 deletions livekit-rtc/livekit/rtc/transcription.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from typing import List
from dataclasses import dataclass


@dataclass
class Transcription:
participant_identity: str
track_id: str
segments: List["TranscriptionSegment"]
language: str


@dataclass
class TranscriptionSegment:
id: str
Expand Down

0 comments on commit 806a88b

Please sign in to comment.