Merge pull request #252 from pipecat-ai/aleix/daily-check-size-read-audio-frames

transports(daily): always check size of read audio frames
This commit is contained in:
Aleix Conchillo Flaqué
2024-06-25 09:45:05 -07:00
committed by GitHub
6 changed files with 47 additions and 41 deletions

View File

@@ -5,6 +5,13 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- Fixed a Daily transport blocking situation that occurred while reading audio
frames after a participant left the room. Needs daily-python >= 0.10.1.
## [0.0.32] - 2024-06-22 ## [0.0.32] - 2024-06-22
### Added ### Added

View File

@@ -4,7 +4,7 @@
# #
# pip-compile --all-extras pyproject.toml # pip-compile --all-extras pyproject.toml
# #
aiofiles==23.2.1 aiofiles==24.1.0
# via deepgram-sdk # via deepgram-sdk
aiohttp==3.9.5 aiohttp==3.9.5
# via # via
@@ -51,8 +51,6 @@ certifi==2024.6.2
# httpcore # httpcore
# httpx # httpx
# requests # requests
cffi==1.16.0
# via sounddevice
charset-normalizer==3.3.2 charset-normalizer==3.3.2
# via requests # via requests
click==8.1.7 click==8.1.7
@@ -64,7 +62,7 @@ coloredlogs==15.0.1
# via onnxruntime # via onnxruntime
ctranslate2==4.3.1 ctranslate2==4.3.1
# via faster-whisper # via faster-whisper
daily-python==0.10.0 daily-python==0.10.1
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
dataclasses-json==0.6.7 dataclasses-json==0.6.7
# via # via
@@ -94,7 +92,7 @@ fastapi-cli==0.0.4
# via fastapi # via fastapi
faster-whisper==1.0.2 faster-whisper==1.0.2
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
filelock==3.15.3 filelock==3.15.4
# via # via
# huggingface-hub # huggingface-hub
# pyht # pyht
@@ -121,7 +119,7 @@ future==1.0.0
# via pyloudnorm # via pyloudnorm
google-ai-generativelanguage==0.6.4 google-ai-generativelanguage==0.6.4
# via google-generativeai # via google-generativeai
google-api-core[grpc]==2.19.0 google-api-core[grpc]==2.19.1
# via # via
# google-ai-generativelanguage # google-ai-generativelanguage
# google-api-python-client # google-api-python-client
@@ -139,7 +137,7 @@ google-auth-httplib2==0.2.0
# via google-api-python-client # via google-api-python-client
google-generativeai==0.5.4 google-generativeai==0.5.4
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
googleapis-common-protos==1.63.1 googleapis-common-protos==1.63.2
# via # via
# google-api-core # google-api-core
# grpcio-status # grpcio-status
@@ -219,7 +217,7 @@ langchain-openai==0.1.9
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
langchain-text-splitters==0.2.1 langchain-text-splitters==0.2.1
# via langchain # via langchain
langsmith==0.1.81 langsmith==0.1.82
# via # via
# langchain # langchain
# langchain-community # langchain-community
@@ -338,8 +336,6 @@ pyasn1-modules==0.4.0
# via google-auth # via google-auth
pyaudio==0.2.14 pyaudio==0.2.14
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
pycparser==2.22
# via cffi
pydantic==2.7.4 pydantic==2.7.4
# via # via
# anthropic # anthropic
@@ -404,7 +400,7 @@ safetensors==0.4.3
# via # via
# timm # timm
# transformers # transformers
scipy==1.13.1 scipy==1.14.0
# via pyloudnorm # via pyloudnorm
shellingham==1.5.4 shellingham==1.5.4
# via typer # via typer
@@ -416,8 +412,6 @@ sniffio==1.3.1
# anyio # anyio
# httpx # httpx
# openai # openai
sounddevice==0.4.7
# via pipecat-ai (pyproject.toml)
sqlalchemy==2.0.31 sqlalchemy==2.0.31
# via # via
# langchain # langchain
@@ -428,7 +422,7 @@ sympy==1.12.1
# via # via
# onnxruntime # onnxruntime
# torch # torch
tenacity==8.4.1 tenacity==8.4.2
# via # via
# langchain # langchain
# langchain-community # langchain-community

View File

@@ -1,10 +1,10 @@
# #
# This file is autogenerated by pip-compile with Python 3.12 # This file is autogenerated by pip-compile with Python 3.10
# by the following command: # by the following command:
# #
# pip-compile --all-extras pyproject.toml # pip-compile --all-extras pyproject.toml
# #
aiofiles==23.2.1 aiofiles==24.1.0
# via deepgram-sdk # via deepgram-sdk
aiohttp==3.9.5 aiohttp==3.9.5
# via # via
@@ -28,6 +28,10 @@ anyio==4.4.0
# openai # openai
# starlette # starlette
# watchfiles # watchfiles
async-timeout==4.0.3
# via
# aiohttp
# langchain
attrs==23.2.0 attrs==23.2.0
# via # via
# aiohttp # aiohttp
@@ -47,8 +51,6 @@ certifi==2024.6.2
# httpcore # httpcore
# httpx # httpx
# requests # requests
cffi==1.16.0
# via sounddevice
charset-normalizer==3.3.2 charset-normalizer==3.3.2
# via requests # via requests
click==8.1.7 click==8.1.7
@@ -60,7 +62,7 @@ coloredlogs==15.0.1
# via onnxruntime # via onnxruntime
ctranslate2==4.3.1 ctranslate2==4.3.1
# via faster-whisper # via faster-whisper
daily-python==0.10.0 daily-python==0.10.1
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
dataclasses-json==0.6.7 dataclasses-json==0.6.7
# via # via
@@ -78,6 +80,10 @@ einops==0.8.0
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
email-validator==2.2.0 email-validator==2.2.0
# via fastapi # via fastapi
exceptiongroup==1.2.1
# via
# anyio
# pytest
fal-client==0.4.0 fal-client==0.4.0
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
fastapi==0.111.0 fastapi==0.111.0
@@ -86,7 +92,7 @@ fastapi-cli==0.0.4
# via fastapi # via fastapi
faster-whisper==1.0.2 faster-whisper==1.0.2
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
filelock==3.15.3 filelock==3.15.4
# via # via
# huggingface-hub # huggingface-hub
# pyht # pyht
@@ -112,7 +118,7 @@ future==1.0.0
# via pyloudnorm # via pyloudnorm
google-ai-generativelanguage==0.6.4 google-ai-generativelanguage==0.6.4
# via google-generativeai # via google-generativeai
google-api-core[grpc]==2.19.0 google-api-core[grpc]==2.19.1
# via # via
# google-ai-generativelanguage # google-ai-generativelanguage
# google-api-python-client # google-api-python-client
@@ -130,7 +136,7 @@ google-auth-httplib2==0.2.0
# via google-api-python-client # via google-api-python-client
google-generativeai==0.5.4 google-generativeai==0.5.4
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
googleapis-common-protos==1.63.1 googleapis-common-protos==1.63.2
# via # via
# google-api-core # google-api-core
# grpcio-status # grpcio-status
@@ -208,7 +214,7 @@ langchain-openai==0.1.9
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
langchain-text-splitters==0.2.1 langchain-text-splitters==0.2.1
# via langchain # via langchain
langsmith==0.1.81 langsmith==0.1.82
# via # via
# langchain # langchain
# langchain-community # langchain-community
@@ -296,8 +302,6 @@ pyasn1-modules==0.4.0
# via google-auth # via google-auth
pyaudio==0.2.14 pyaudio==0.2.14
# via pipecat-ai (pyproject.toml) # via pipecat-ai (pyproject.toml)
pycparser==2.22
# via cffi
pydantic==2.7.4 pydantic==2.7.4
# via # via
# anthropic # anthropic
@@ -362,7 +366,7 @@ safetensors==0.4.3
# via # via
# timm # timm
# transformers # transformers
scipy==1.13.1 scipy==1.14.0
# via pyloudnorm # via pyloudnorm
shellingham==1.5.4 shellingham==1.5.4
# via typer # via typer
@@ -374,8 +378,6 @@ sniffio==1.3.1
# anyio # anyio
# httpx # httpx
# openai # openai
sounddevice==0.4.7
# via pipecat-ai (pyproject.toml)
sqlalchemy==2.0.31 sqlalchemy==2.0.31
# via # via
# langchain # langchain
@@ -386,7 +388,7 @@ sympy==1.12.1
# via # via
# onnxruntime # onnxruntime
# torch # torch
tenacity==8.4.1 tenacity==8.4.2
# via # via
# langchain # langchain
# langchain-community # langchain-community
@@ -400,6 +402,8 @@ tokenizers==0.19.1
# anthropic # anthropic
# faster-whisper # faster-whisper
# transformers # transformers
tomli==2.0.1
# via pytest
torch==2.3.1 torch==2.3.1
# via # via
# pipecat-ai (pyproject.toml) # pipecat-ai (pyproject.toml)
@@ -423,6 +427,7 @@ typer==0.12.3
typing-extensions==4.12.2 typing-extensions==4.12.2
# via # via
# anthropic # anthropic
# anyio
# deepgram-sdk # deepgram-sdk
# fastapi # fastapi
# google-generativeai # google-generativeai
@@ -435,6 +440,7 @@ typing-extensions==4.12.2
# torch # torch
# typer # typer
# typing-inspect # typing-inspect
# uvicorn
typing-inspect==0.9.0 typing-inspect==0.9.0
# via dataclasses-json # via dataclasses-json
ujson==5.10.0 ujson==5.10.0

View File

@@ -36,8 +36,8 @@ Website = "https://pipecat.ai"
[project.optional-dependencies] [project.optional-dependencies]
anthropic = [ "anthropic~=0.25.7" ] anthropic = [ "anthropic~=0.25.7" ]
azure = [ "azure-cognitiveservices-speech~=1.37.0" ] azure = [ "azure-cognitiveservices-speech~=1.37.0" ]
cartesia = [ "numpy~=1.26.0", "sounddevice", "cartesia" ] cartesia = [ "cartesia~=0.1.1" ]
daily = [ "daily-python~=0.10.0" ] daily = [ "daily-python~=0.10.1" ]
deepgram = [ "deepgram-sdk~=3.2.7" ] deepgram = [ "deepgram-sdk~=3.2.7" ]
examples = [ "python-dotenv~=1.0.0", "flask~=3.0.3", "flask_cors~=4.0.1" ] examples = [ "python-dotenv~=1.0.0", "flask~=3.0.3", "flask_cors~=4.0.1" ]
fal = [ "fal-client~=0.4.0" ] fal = [ "fal-client~=0.4.0" ]

View File

@@ -55,7 +55,7 @@ class BaseInputTransport(FrameProcessor):
async def push_audio_frame(self, frame: AudioRawFrame): async def push_audio_frame(self, frame: AudioRawFrame):
if self._params.audio_in_enabled or self._params.vad_enabled: if self._params.audio_in_enabled or self._params.vad_enabled:
self._audio_in_queue.put_nowait(frame) await self._audio_in_queue.put(frame)
# #
# Frame processor # Frame processor

View File

@@ -209,19 +209,18 @@ class DailyTransportClient(EventHandler):
async def read_next_audio_frame(self) -> AudioRawFrame | None: async def read_next_audio_frame(self) -> AudioRawFrame | None:
sample_rate = self._params.audio_in_sample_rate sample_rate = self._params.audio_in_sample_rate
num_channels = self._params.audio_in_channels num_channels = self._params.audio_in_channels
num_frames = int(sample_rate / 100) * 2 # 20ms of audio
if self._other_participant_has_joined: future = self._loop.create_future()
num_frames = int(sample_rate / 100) * 2 # 20ms of audio self._speaker.read_frames(num_frames, completion=completion_callback(future))
audio = await future
future = self._loop.create_future()
self._speaker.read_frames(num_frames, completion=completion_callback(future))
audio = await future
if len(audio) > 0:
return AudioRawFrame(audio=audio, sample_rate=sample_rate, num_channels=num_channels) return AudioRawFrame(audio=audio, sample_rate=sample_rate, num_channels=num_channels)
else: else:
# If no one has ever joined the meeting `read_frames()` would block, # If we don't read any audio it could be there's no participant
# instead we just wait a bit. daily-python should probably return # connected. daily-python will return immediately if that's the
# silence instead. # case, so let's sleep for a little bit (i.e. busy wait).
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
return None return None