Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jayeshp19 committed Jan 24, 2025
1 parent 288a3ef commit 400d245
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def __init__(
self._transcriber.on("input_speech_done", self._on_input_speech_done)
if self._opts.enable_agent_audio_transcription:
self._agent_transcriber = TranscriberSession(
client=self._client, model=self._opts.model
client=self._client, model=self._opts.model, sample_rate=24000
)
self._agent_transcriber.on("input_speech_done", self._on_agent_speech_done)
# init dummy task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ def __init__(
*,
client: genai.Client,
model: LiveAPIModels | str,
sample_rate: int = 16000,
):
"""
Initializes a TranscriberSession instance for interacting with Google's Realtime API.
"""
super().__init__()
self._client = client
self._model = model
self._sample_rate = sample_rate
self._bstream = utils.audio.AudioByteStream(
16000,
1,
samples_per_channel=1200,
)
self._closed = False
system_instructions = types.Content(
parts=[types.Part(text=SYSTEM_INSTRUCTIONS)]
Expand All @@ -77,13 +84,28 @@ def __init__(
def _push_audio(self, frame: rtc.AudioFrame) -> None:
if self._closed:
return
self._queue_msg(
types.LiveClientRealtimeInput(
media_chunks=[
types.Blob(data=frame.data.tobytes(), mime_type="audio/pcm")
]
if self._sample_rate != 16000:
bstream = utils.audio.AudioByteStream(
16000,
1,
samples_per_channel=1200,
)
for f in bstream.write(frame.data.tobytes()):
self._queue_msg(
types.LiveClientRealtimeInput(
media_chunks=[
types.Blob(data=f.data.tobytes(), mime_type="audio/pcm")
]
)
)
else:
self._queue_msg(
types.LiveClientRealtimeInput(
media_chunks=[
types.Blob(data=frame.data.tobytes(), mime_type="audio/pcm")
]
)
)
)

def _queue_msg(self, msg: ClientEvents) -> None:
if not self._closed:
Expand Down

0 comments on commit 400d245

Please sign in to comment.