"I need a Python program that allows me to communicate with local Ollama models (e.g., llama3.2:3b) using voice input and text-to-speech output. The app should run smoothly and efficiently with minimal error correction required after execution. Here's a detailed breakdown of the required functionality:
Core Features:

    Speech-to-Text:
        Use a reliable library (such as speech_recognition) to convert my voice into text.
        Implement handling for noisy environments by adjusting ambient_noise and applying a reasonable timeout/phrase limit to avoid premature cutoffs.
    Text-to-Speech:
        After retrieving the response from the local Ollama model, convert the text to speech using Microsoft’s SpeechT5 or another suitable TTS engine. Ensure it plays back clearly and naturally.
    Ollama Model Integration:
        Transcribe the input text and send it to the local Ollama model (running on localhost). Retrieve the AI’s response and convert it back to speech for playback.
        Implement robust error handling for issues such as model unavailability, bad requests, or response timeouts. If the Ollama server is unavailable, notify the user gracefully.

Memory Management:

    In-Session Memory:
        Track the conversation within the current session to maintain context. Handle memory pruning to avoid token limit errors.
    Persistent Memory:
        Save the conversation history across sessions. Implement this so that the model can recall previous interactions and build on prior context. Ensure that the app can handle starting a session with no previous memory.

Commands:

    Stop Command:
        Include a stop command that halts ongoing speech output (e.g., using a flag to control when playback should be interrupted).
    Exit Command:
        Implement an exit command to end the session and save the current conversation to persistent memory.

Error Handling:

    Robust Error Handling:
        Implement try-except blocks for all critical operations (speech recognition, TTS, API calls). If an error occurs (such as a bad request or speech recognition failure), provide clear feedback to the user and continue the conversation smoothly without crashing the app.
        Specifically handle situations such as:
            Empty conversation history: Ensure the app doesn't crash when starting with no previous memory.
            SpeechRecognitionError: Handle invalid input gracefully, skipping to the next recognition attempt.
            Ollama API Issues: Provide informative error messages if the server is unreachable or responds with an invalid request.
    Suppress Unnecessary Logs:
        Suppress all system-level logs, such as ALSA warnings or Pygame initialization messages. The terminal should display only user input, AI responses, and critical errors or session status updates.

Additional Improvements:

    Conversation Summarization:
        Auto-generate a summary of each session when it ends and store it in a memory log for quick loading in future sessions.
    Memory Pruning:
        Implement a mechanism to prune older parts of the conversation history to prevent token limit issues during long conversations.
    Snappy Response Times:
        Prioritize fast speech-to-text and text-to-speech operations to ensure smooth, snappy conversation flow with minimal delay. Fine-tune timeouts to balance performance and input capture.

Make sure the code is highly reliable and able to run without needing manual fixes or extensive debugging. Please also provide clear explanations for key components and suggestions on any further refinements."