Skip to content

Commit

Permalink
code (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton authored Jan 10, 2025
1 parent b64e019 commit 4d16634
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 103 deletions.
14 changes: 13 additions & 1 deletion backend/gradio_webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@
audio_to_file,
audio_to_float32,
)
from .webrtc import AsyncStreamHandler, StreamHandler, WebRTC
from .webrtc import (
AsyncAudioVideoStreamHandler,
AsyncStreamHandler,
AudioVideoStreamHandler,
StreamHandler,
WebRTC,
VideoEmitType,
AudioEmitType,
)

__all__ = [
"AsyncStreamHandler",
"AudioVideoStreamHandler",
"AudioEmitType",
"AsyncAudioVideoStreamHandler",
"AlgoOptions",
"AdditionalOutputs",
"aggregate_bytes_to_16bit",
Expand All @@ -36,6 +47,7 @@
"stt",
"stt_for_chunks",
"StreamHandler",
"VideoEmitType",
"WebRTC",
"WebRTCError",
"Warning",
Expand Down
1 change: 0 additions & 1 deletion backend/gradio_webrtc/reply_on_pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np

from gradio_webrtc.pause_detection import SileroVADModel, SileroVadOptions
from gradio_webrtc.utils import AdditionalOutputs
from gradio_webrtc.webrtc import EmitType, StreamHandler

logger = getLogger(__name__)
Expand Down
10 changes: 6 additions & 4 deletions backend/gradio_webrtc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ async def player_worker_decode(

logger.debug(
"received array with shape %s sample rate %s layout %s",
audio_array.shape,
audio_array.shape, # type: ignore
sample_rate,
layout,
layout, # type: ignore
)
format = "s16" if audio_array.dtype == "int16" else "fltp"
format = "s16" if audio_array.dtype == "int16" else "fltp" # type: ignore

# Convert to audio frame and resample
# This runs in the same timeout context
frame = av.AudioFrame.from_ndarray( # type: ignore
audio_array, format=format, layout=layout
audio_array, # type: ignore
format=format,
layout=layout, # type: ignore
)
frame.sample_rate = sample_rate

Expand Down
Loading

0 comments on commit 4d16634

Please sign in to comment.