File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 11import daily
22import threading
33import pyaudio
4+ import json
45
56SAMPLE_RATE = 16000
67NUM_CHANNELS = 1
@@ -160,3 +161,15 @@ def receive_bot_audio(self):
160161
161162 if len (buffer ) > 0 :
162163 self .__output_audio_stream .write (buffer , CHUNK_SIZE )
164+
165+ def send_app_message (self , message ):
166+ """
167+ Send an application message to the assistant.
168+
169+ :param message: The message to send (expects a dictionary).
170+ """
171+ try :
172+ serialized_message = json .dumps (message )
173+ self .__call_client .send_app_message (serialized_message )
174+ except Exception as e :
175+ print (f"Failed to send app message: { e } " )
Original file line number Diff line number Diff line change @@ -62,3 +62,34 @@ def start(
6262 def stop (self ):
6363 self .__client .leave ()
6464 self .__client = None
65+
66+ def send (self , message ):
67+ """
68+ Send a generic message to the assistant.
69+
70+ :param message: A dictionary containing the message type and content.
71+ """
72+ if not self .__client :
73+ raise Exception ("Call not started. Please start the call first." )
74+
75+ # Check message format here instead of serialization
76+ if not isinstance (message , dict ) or 'type' not in message :
77+ raise ValueError ("Invalid message format." )
78+
79+ try :
80+ self .__client .send_app_message (message ) # Send dictionary directly
81+ except Exception as e :
82+ print (f"Failed to send message: { e } " )
83+
84+ def add_message (self , role , content ):
85+ """
86+ method to send text messages with specific parameters.
87+ """
88+ message = {
89+ 'type' : 'add-message' ,
90+ 'message' : {
91+ 'role' : role ,
92+ 'content' : content
93+ }
94+ }
95+ self .send (message )
You can’t perform that action at this time.
0 commit comments