Please help me with Issue with AGI Commands for audio play and record in Python Voice Bot

Issue Description

Currently, I am trying to build voice call bot with python3.10 and asterisk.
There is STT and TTS step.
I use AGI code EXEC Playback {filename} to play audio file and RECORD FILE {recording_base} wav # {timeout} 0 BEEP s={silence} in the python to record user input.
I confirmed that I hear the audio file that is generated from TTS and recorded user speech into targeted path and file by using above command, SEVERAL TIMES.
But in the python log, the result of the above commands is 510 Invalid or unknown command.
That is the problem.
There are multiple turns and steps that needs to be run in order, but due to above results, bots moves forwards to the next step without waiting the result.
But in the asterisk log (sudo asterisk -rvvv), it shows in order.
For example, I am on the turn 1 but python log shows until turn 5, but asterisk log is on the turn 1.
I attached python bot codes.

agi_handler.py

https://github.com/user-attachments/files/22733805/agi_handler.py

dhub_voice_bot.py

https://github.com/user-attachments/files/22733806/dhub_voice_bot.py

I also attached the python log(agi.log) and it reflects the turn 1 step (15s after connect the call)

Not sure if this is any help, but an AGI response can consist of multiple lines. Continuation of the response is indicated by a “-” character in column 4, immediately after the numeric response code.

In short, your AGI request/response handling seems a bit simple-minded.

Also, you may want to use FastAGI instead of regular AGI, since that gives you more control over process activation, logging etc.

See the send_request() and get_response() methods in the Gateway class from my Seaskirt API wrapper for Asterisk.

Thank you @ldo
May I have a one more question?

How to improve the audio quality (playback audio file that is result of the TTS)