Skip to content

Commit

Permalink
changed import
Browse files Browse the repository at this point in the history
  • Loading branch information
eavanvalkenburg committed Jan 17, 2025
1 parent 56e949c commit 590fcc4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
)
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
from semantic_kernel.connectors.ai.realtime_client_base import RealtimeClientBase
from semantic_kernel.connectors.ai.realtime_helpers import SKAudioTrack
from semantic_kernel.contents.audio_content import AudioContent
from semantic_kernel.contents.chat_history import ChatHistory
from semantic_kernel.contents.function_call_content import FunctionCallContent
Expand Down Expand Up @@ -682,6 +681,8 @@ async def create_session(
**kwargs: Any,
) -> None:
"""Create a session in the service."""
from semantic_kernel.connectors.ai.realtime_helpers import SKAudioTrack

ice_servers = [RTCIceServer(urls=["stun:stun.l.google.com:19302"])]
self.peer_connection = RTCPeerConnection(configuration=RTCConfiguration(iceServers=ice_servers))

Expand Down
10 changes: 5 additions & 5 deletions python/semantic_kernel/connectors/ai/realtime_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from typing import Any, Final

import numpy as np
import sounddevice as sd
from aiortc.mediastreams import MediaStreamError, MediaStreamTrack
from av.audio.frame import AudioFrame
from av.frame import Frame
from pydantic import Field, PrivateAttr
from sounddevice import InputStream, OutputStream

from semantic_kernel.contents.audio_content import AudioContent
from semantic_kernel.kernel_pydantic import KernelBaseModel
Expand Down Expand Up @@ -37,7 +37,7 @@ class SKAudioTrack(KernelBaseModel, MediaStreamTrack):
device: str | int | None = None
queue: asyncio.Queue[Frame] = Field(default_factory=asyncio.Queue)
is_recording: bool = False
stream: sd.InputStream | None = None
stream: InputStream | None = None
frame_size: int = 0
_recording_task: asyncio.Task | None = None
_loop: asyncio.AbstractEventLoop | None = None
Expand Down Expand Up @@ -101,7 +101,7 @@ def callback(indata: np.ndarray, frames: int, time: Any, status: Any) -> None:
if self._loop and self._loop.is_running():
asyncio.run_coroutine_threadsafe(self.queue.put(frame), self._loop)

self.stream = sd.InputStream(
self.stream = InputStream(
device=self.device,
channels=self.channels,
samplerate=self.sample_rate,
Expand Down Expand Up @@ -135,11 +135,11 @@ class SKSimplePlayer(KernelBaseModel):
channels: int = PLAYER_CHANNELS
frame_duration_ms: int = FRAME_DURATION
queue: asyncio.Queue[np.ndarray] = Field(default_factory=asyncio.Queue)
_stream: sd.OutputStream | None = PrivateAttr(None)
_stream: OutputStream | None = PrivateAttr(None)

def model_post_init(self, __context: Any) -> None:
"""Initialize the audio stream."""
self._stream = sd.OutputStream(
self._stream = OutputStream(
callback=self.callback,
samplerate=self.sample_rate,
channels=self.channels,
Expand Down

0 comments on commit 590fcc4

Please sign in to comment.