From a91c26785f7ec407d053e867f65c14a2446256d8 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Thu, 6 Mar 2025 18:31:48 -0500 Subject: [PATCH] Store recording in a folder --- examples/chatbot-audio-recording/bot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/chatbot-audio-recording/bot.py b/examples/chatbot-audio-recording/bot.py index 2dd87449c..2162ed5e2 100644 --- a/examples/chatbot-audio-recording/bot.py +++ b/examples/chatbot-audio-recording/bot.py @@ -32,11 +32,15 @@ load_dotenv(override=True) logger.remove(0) logger.add(sys.stderr, level="DEBUG") +# Create the recordings directory if it doesn't exist +os.makedirs("recordings", exist_ok=True) + async def save_audio(audio: bytes, sample_rate: int, num_channels: int, name: str): if len(audio) > 0: - filename = ( - f"{name}_conversation_recording{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.wav" + filename = os.path.join( + "recordings", + f"{name}_conversation_recording{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.wav", ) with io.BytesIO() as buffer: with wave.open(buffer, "wb") as wf: