open source
This commit is contained in:
parent
70b6e17c69
commit
a93bfc1ec9
61 changed files with 4013 additions and 126 deletions
30
vocode/streaming/output_device/twilio_output_device.py
Normal file
30
vocode/streaming/output_device/twilio_output_device.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import json
|
||||
import base64
|
||||
|
||||
from fastapi import WebSocket
|
||||
|
||||
from vocode.streaming.output_device.base_output_device import BaseOutputDevice
|
||||
|
||||
|
||||
class TwilioOutputDevice(BaseOutputDevice):
|
||||
def __init__(self, ws: WebSocket = None, stream_sid: str = None):
|
||||
self.ws = ws
|
||||
self.stream_sid = stream_sid
|
||||
|
||||
async def send_async(self, chunk: bytes):
|
||||
twilio_message = {
|
||||
"event": "media",
|
||||
"streamSid": self.stream_sid,
|
||||
"media": {"payload": base64.b64encode(chunk).decode("utf-8")},
|
||||
}
|
||||
await self.ws.send_text(json.dumps(twilio_message))
|
||||
|
||||
async def maybe_send_mark_async(self, message_sent):
|
||||
mark_message = {
|
||||
"event": "mark",
|
||||
"streamSid": self.stream_sid,
|
||||
"mark": {
|
||||
"name": "Sent {}".format(message_sent),
|
||||
},
|
||||
}
|
||||
await self.ws.send_text(json.dumps(mark_message))
|
||||
Loading…
Add table
Add a link
Reference in a new issue