Skip to content

Commit

Permalink
upgrades websockets and cartesia to latest versions (#729)
Browse files Browse the repository at this point in the history
* upgrades websockets and cartesia to latest versions

* fix lint

* fix typecheck
  • Loading branch information
ajar98 authored Nov 15, 2024
1 parent fb8e079 commit e054c33
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 281 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from websockets.server import serve
from websockets.asyncio.server import serve

from vocode.streaming.models.websocket_agent import (
WebSocketAgentMessage,
Expand Down
622 changes: 358 additions & 264 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sentry-sdk = { extras = ["fastapi"], version = "^2.3.1" }
sounddevice = "^0.4.7"
tiktoken = "^0.7.0"
uvicorn = "^0.30.0"
websockets = "^12.0"
websockets = "^14.1"
nltk = "^3.8.1"

# LLM Providers
Expand All @@ -43,7 +43,7 @@ groq = { version = "^0.9.0", optional = true }
# Synthesizers
google-cloud-texttospeech = { version = "^2.16.3", optional = true }
pvkoala = { version = "^2.0.1", optional = true }
cartesia = { version = "^1.0.10", optional = true }
cartesia = {version = "^1.1.0", optional = true}

# Transcribers
google-cloud-speech = { version = "^2.26.0", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions vocode/streaming/agent/websocket_user_implemented_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import websockets
from loguru import logger
from websockets.client import WebSocketClientProtocol, connect
from websockets.asyncio.client import ClientConnection

from vocode.streaming.agent.base_agent import (
AgentInput,
Expand Down Expand Up @@ -73,10 +73,10 @@ async def _process(self) -> None:
socket_url = self.get_agent_config().respond.url
logger.info("Connecting to web socket agent %s", socket_url)

async with connect(socket_url) as ws:
async with websockets.connect(socket_url) as ws:

async def sender(
ws: WebSocketClientProtocol,
ws: ClientConnection,
) -> None: # sends audio to websocket
while not self.has_ended:
logger.info("Waiting for data from agent request queue")
Expand Down Expand Up @@ -109,7 +109,7 @@ async def sender(

logger.debug("Terminating web socket agent sender")

async def receiver(ws: WebSocketClientProtocol) -> None:
async def receiver(ws: ClientConnection) -> None:
while not self.has_ended:
try:
msg = await ws.recv()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async def establish_websocket_listeners(self, chunk_size):

async with websockets.connect(
url,
extra_headers=headers,
additional_headers=headers,
) as ws:

async def write() -> None:
Expand Down
2 changes: 1 addition & 1 deletion vocode/streaming/transcriber/assembly_ai_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def process(self):

async with websockets.connect(
URL,
extra_headers=(("Authorization", self.api_key),),
additional_headers=(("Authorization", self.api_key),),
ping_interval=5,
ping_timeout=20,
) as ws:
Expand Down
12 changes: 7 additions & 5 deletions vocode/streaming/transcriber/deepgram_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import websockets
from loguru import logger
from pydantic.v1 import BaseModel, Field
from websockets.client import WebSocketClientProtocol
from websockets.asyncio.client import ClientConnection

from vocode import getenv
from vocode.streaming.models.audio import AudioEncoding
Expand Down Expand Up @@ -389,16 +389,18 @@ async def process(self):
self.audio_cursor = 0.0
self.start_ts = now()

extra_headers = {"Authorization": f"Token {self.api_key}"}
additional_headers = {"Authorization": f"Token {self.api_key}"}
deepgram_url = self.get_deepgram_url()
logger.info(f"Connecting to Deepgram at {deepgram_url}")

try:
async with websockets.connect(deepgram_url, extra_headers=extra_headers) as ws:
async with websockets.connect(
deepgram_url, additional_headers=additional_headers
) as ws:
self.connected_ts = now()

async def sender(
ws: WebSocketClientProtocol,
ws: ClientConnection,
): # sends audio to websocket
byte_rate = self.get_byte_rate()

Expand All @@ -417,7 +419,7 @@ async def sender(

logger.debug("Terminating Deepgram transcriber sender")

async def receiver(ws: WebSocketClientProtocol):
async def receiver(ws: ClientConnection):
buffer = ""
buffer_avg_confidence = 0.0
num_buffer_utterances = 1
Expand Down
6 changes: 3 additions & 3 deletions vocode/streaming/transcriber/rev_ai_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import websockets
from loguru import logger
from websockets.client import WebSocketClientProtocol
from websockets.asyncio.client import ClientConnection

from vocode import getenv
from vocode.streaming.models.transcriber import (
Expand Down Expand Up @@ -71,7 +71,7 @@ async def _run_loop(self):
async def process(self):
async with websockets.connect(self.get_rev_ai_url()) as ws:

async def sender(ws: WebSocketClientProtocol):
async def sender(ws: ClientConnection):
while not self.closed:
try:
data = await asyncio.wait_for(self._input_queue.get(), 5)
Expand All @@ -81,7 +81,7 @@ async def sender(ws: WebSocketClientProtocol):
await ws.close()
logger.debug("Terminating Rev.AI transcriber sender")

async def receiver(ws: WebSocketClientProtocol):
async def receiver(ws: ClientConnection):
buffer = ""

while not self.closed:
Expand Down

0 comments on commit e054c33

Please sign in to comment.