Skip to content

Commit

Permalink
Merge pull request #280 from bolna-ai/plivo-v1
Browse files Browse the repository at this point in the history
adding plivo clear and mark events
  • Loading branch information
prateeksachan authored Jun 23, 2024
2 parents 53cd006 + 645e7ee commit 8415586
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bolna/agent_manager/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ async def __check_for_completion(self):
meta_info={'io': 'default', "request_id": str(uuid.uuid4()), "cached": False, "sequence_id": -1, 'format': 'wav'}
await self._synthesize(create_ws_data_packet("Hey, are you still there?", meta_info= meta_info))
else:
meta_info={'io': 'twilio', "request_id": str(uuid.uuid4()), "cached": False, "sequence_id": -1, 'format': 'pcm'}
meta_info={'io': self.tools["output"].get_provider(), "request_id": str(uuid.uuid4()), "cached": False, "sequence_id": -1, 'format': 'pcm'}
await self._synthesize(create_ws_data_packet("Hey, are you still there?", meta_info= meta_info))

#Just in case we need to clear messages sent before
Expand Down Expand Up @@ -1510,7 +1510,7 @@ async def __start_transmitting_ambient_noise(self):
meta_info={'io': 'default', 'message_category': 'ambient_noise', "request_id": str(uuid.uuid4()), "sequence_id": -1, "type":'audio', 'format': 'wav'}
else:

meta_info={'io': 'twilio', 'message_category': 'ambient_noise', 'stream_sid': self.stream_sid , "request_id": str(uuid.uuid4()), "cached": True, "type":'audio', "sequence_id": -1, 'format': 'pcm'}
meta_info={'io': self.tools["output"].get_provider(), 'message_category': 'ambient_noise', 'stream_sid': self.stream_sid , "request_id": str(uuid.uuid4()), "cached": True, "type":'audio', "sequence_id": -1, 'format': 'pcm'}
while True:
logger.info(f"Before yielding ambient noise")
for chunk in yield_chunks_from_memory(audio, self.output_chunk_size*2 ):
Expand Down
19 changes: 13 additions & 6 deletions bolna/output_handlers/telephony_providers/plivo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ def __init__(self, websocket=None, mark_set=None, log_dir_name=None):
io_provider = 'plivo'

super().__init__(io_provider, websocket, mark_set, log_dir_name)
self.is_chunking_supported = False
self.is_chunking_supported = True

async def handle_interruption(self):
logger.info("interrupting because user spoke in between")
message_clear = {
"event": "clearAudio",
"streamId": self.stream_sid,
}
await self.websocket.send_text(json.dumps(message_clear))
self.mark_set = set()

async def form_media_message(self, audio_data, audio_format):
base64_audio = base64.b64encode(audio_data).decode("utf-8")
Expand All @@ -30,11 +39,9 @@ async def form_media_message(self, audio_data, audio_format):

async def form_mark_message(self, mark_id):
mark_message = {
"event": "mark",
"streamSid": self.stream_sid,
"mark": {
"name": mark_id
}
"event": "checkpoint",
"streamId": self.stream_sid,
"name": mark_id
}

return mark_message
1 change: 1 addition & 0 deletions bolna/synthesizer/elevenlabs_synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ async def generate(self):
message = await self.internal_queue.get()
logger.info(f"Generating TTS response for message: {message}, using mulaw {self.use_mulaw}")
meta_info, text = message.get("meta_info"), message.get("data")
audio = None
if self.caching:
if self.cache.get(text):
logger.info(f"Cache hit and hence returning quickly {text}")
Expand Down

0 comments on commit 8415586

Please sign in to comment.