Merge pull request #165 from pipecat-ai/clear-audio-output-buffer-when-interrupted

transport(base): clear audio output buffer if interrupted
This commit is contained in:
Aleix Conchillo Flaqué
2024-05-23 07:31:33 +08:00
committed by GitHub
3 changed files with 3 additions and 27 deletions

View File

@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Clear the audio output buffer if we are interrupted.
- Re-add exponential smoothing after volume calculation. This makes sure the
volume value being used doesn't fluctuate so much.

View File

@@ -1,25 +0,0 @@
#
# Copyright (c) 2024, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#
from typing import List
from pipecat.frames.frames import AudioRawFrame
def maybe_split_audio_frame(frame: AudioRawFrame, largest_write_size: int) -> List[AudioRawFrame]:
"""Subdivide large audio frames to enable interruption."""
frames: List[AudioRawFrame] = []
if len(frame.audio) > largest_write_size:
for i in range(0, len(frame.audio), largest_write_size):
chunk = frame.audio[i: i + largest_write_size]
frames.append(
AudioRawFrame(
audio=chunk,
sample_rate=frame.sample_rate,
num_channels=frame.num_channels))
else:
frames.append(frame)
return frames

View File

@@ -175,8 +175,7 @@ class BaseOutputTransport(FrameProcessor):
self._internal_push_frame(frame), self.get_event_loop())
future.result()
else:
# Send any remaining audio
self._send_audio_truncated(buffer, bytes_size_10ms)
# If we get interrupted just clear the output buffer.
buffer = bytearray()
if isinstance(frame, EndFrame):