Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services(azure): chunk audio so interruptions work better #225

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to **pipecat** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed an issue in `AzureTTSService` that was causing interruptions to take
longer. Azure Speech Synthesizer returns big chunks of audio. Currently, we
don't have a way to stop a long `AudioRawFrame`, so we have to chunk longer
audio into small chunks.

## [0.0.29] - 2024-06-07

### Added
Expand Down
8 changes: 7 additions & 1 deletion src/pipecat/services/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
if result.reason == ResultReason.SynthesizingAudioCompleted:
await self.stop_ttfb_metrics()
# Azure always sends a 44-byte header. Strip it off.
yield AudioRawFrame(audio=result.audio_data[44:], sample_rate=16000, num_channels=1)
audio = result.audio_data[44:]
# Chunk it to 20ms so interruptions work properly
bytes_frames = 640
while len(audio) > 0:
chunk = audio[:bytes_frames]
yield AudioRawFrame(audio=chunk, sample_rate=16000, num_channels=1)
audio = audio[bytes_frames:]
elif result.reason == ResultReason.Canceled:
cancellation_details = result.cancellation_details
logger.warning(f"Speech synthesis canceled: {cancellation_details.reason}")
Expand Down
Loading