Receiving the answer
This commit is contained in:
@@ -60,27 +60,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
||||
# Returning the answer
|
||||
if isinstance(transport, SmallWebRTCTransport):
|
||||
yield {"status": "ANSWER:START"}
|
||||
answer_dict = transport._client._webrtc_connection.get_answer()
|
||||
answer_json_str = json.dumps(answer_dict)
|
||||
answer_bytes = answer_json_str.encode("utf-8")
|
||||
encoded_answer = base64.b64encode(answer_bytes).decode("ascii")
|
||||
|
||||
# Break encoded_answer into multiple messages
|
||||
chunk_size = 1000 # Adjust this size based on your needs
|
||||
total_chunks = (
|
||||
len(encoded_answer) + chunk_size - 1
|
||||
) // chunk_size # Calculate total chunks
|
||||
|
||||
for i in range(0, len(encoded_answer), chunk_size):
|
||||
chunk = encoded_answer[i : i + chunk_size]
|
||||
chunk_index = i // chunk_size
|
||||
yield {
|
||||
"answer_chunk": chunk,
|
||||
"chunk_index": chunk_index,
|
||||
"total_chunks": total_chunks,
|
||||
"is_last_chunk": chunk_index == total_chunks - 1,
|
||||
}
|
||||
|
||||
yield {"answer": transport._client._webrtc_connection.get_answer()}
|
||||
yield {"status": "ANSWER:END"}
|
||||
|
||||
stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
|
||||
|
||||
Reference in New Issue
Block a user