Here is a complete Python script to transcribe all voice memos in the `memos/` folder and save the transcripts into the `transcripts/` folder.

It uses standard HTTP multipart requests targeting the AI Builder Space audio transcription API (which follows the standard Whisper/audio transcription specification).

### Prerequisites

Install the `requests` library if you haven't already:

```bash
pip install requests
```

### Script (`transcribe.py`)

```python
import os
import sys
from pathlib import Path
import requests

# Base endpoint for AI Builder Space (adjust base URL if using a custom gateway)
API_URL = os.environ.get(
    "AI_BUILDER_BASE_URL", 
    "https://api.ai-builder.run/v1/audio/transcriptions"
)

# Supported audio extensions
SUPPORTED_EXTENSIONS = {".mp3", ".wav", ".m4a", ".aac", ".flac", ".ogg", ".webm"}


def transcribe_audio(file_path: Path, api_key: str) -> str:
    """Send an audio file to the transcription API and return the text."""
    headers = {
        "Authorization": f"Bearer {api_key}"
    }

    with open(file_path, "rb") as audio_file:
        files = {
            "file": (file_path.name, audio_file)
        }
        data = {
            "model": "whisper-1"  # Default Whisper model
        }

        response = requests.post(
            API_URL,
            headers=headers,
            files=files,
            data=data,
            timeout=120  # Allow time for longer memos
        )

    if response.status_code != 200:
        raise RuntimeError(
            f"API Error ({response.status_code}): {response.text}"
        )

    result = response.json()
    # The API returns {"text": "..."}
    return result.get("text", "")


def main():
    # 1. Retrieve API key
    api_key = os.environ.get("AI_BUILDER_TOKEN")
    if not api_key:
        print("Error: AI_BUILDER_TOKEN environment variable is not set.", file=sys.stderr)
        sys.exit(1)

    # 2. Setup input and output directories
    memos_dir = Path("memos")
    transcripts_dir = Path("transcripts")

    if not memos_dir.exists() or not memos_dir.is_dir():
        print(f"Error: Directory '{memos_dir}' does not exist.", file=sys.stderr)
        sys.exit(1)

    transcripts_dir.mkdir(parents=True, exist_ok=True)

    # 3. Gather audio files
    audio_files = [
        f for f in memos_dir.iterdir()
        if f.is_file() and f.suffix.lower() in SUPPORTED_EXTENSIONS
    ]

    if not audio_files:
        print(f"No supported audio files found in '{memos_dir}'.")
        return

    print(f"Found {len(audio_files)} voice memo(s) to process.\n")

    # 4. Process each file
    for file_path in sorted(audio_files):
        output_path = transcripts_dir / f"{file_path.stem}.txt"

        print(f"Transcribing: {file_path.name}...")
        try:
            transcript = transcribe_audio(file_path, api_key)

            # Save the result
            output_path.write_text(transcript.strip(), encoding="utf-8")
            print(f" -> Saved: {output_path}")

        except Exception as e:
            print(f" -> Failed to transcribe {file_path.name}: {e}", file=sys.stderr)

    print("\nProcessing complete.")


if __name__ == "__main__":
    main()
```

### Usage

1. Set your API key in your terminal:
   ```bash
   export AI_BUILDER_TOKEN="your_actual_token_here"
   ```
2. Run the script:
   ```bash
   python transcribe.py
   ```