Here is a Python script to transcribe all voice memos in the `memos/` folder using the AI Builder Space API and save the outputs to `transcripts/`.

### Prerequisites

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

Make sure your token is set in your environment:
```bash
export AI_BUILDER_TOKEN="your_token_here"
```

### Python Script (`transcribe_memos.py`)

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

# Configuration
API_URL = "https://api.ai-builder.space/v1/audio/transcriptions"
TOKEN = os.environ.get("AI_BUILDER_TOKEN")

MEMOS_DIR = Path("memos")
TRANSCRIPTS_DIR = Path("transcripts")

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


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

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

        response = requests.post(API_URL, headers=headers, files=files, data=data)

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

    result = response.json()
    # The API returns either a JSON with a 'text' field or raw text depending on options
    return result.get("text", "")


def main():
    if not TOKEN:
        print("Error: AI_BUILDER_TOKEN environment variable is not set.", file=sys.stderr)
        sys.exit(1)

    if not MEMOS_DIR.exists():
        print(f"Error: Folder '{MEMOS_DIR}' does not exist.", file=sys.stderr)
        sys.exit(1)

    # Ensure output directory exists
    TRANSCRIPTS_DIR.mkdir(parents=True, exist_ok=True)

    # 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 audio files found in '{MEMOS_DIR}'.")
        return

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

    for file_path in audio_files:
        transcript_file = TRANSCRIPTS_DIR / f"{file_path.stem}.txt"

        print(f"Transcribing: {file_path.name} ...", end=" ", flush=True)

        try:
            transcript_text = transcribe_audio(file_path, TOKEN)

            # Save transcription
            transcript_file.write_text(transcript_text, encoding="utf-8")
            print(f"Done -> Saved to {transcript_file.name}")

        except Exception as e:
            print(f"FAILED\n  [!] {e}")


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

### Features
* **Format support**: Checks for standard audio formats (`.mp3`, `.wav`, `.m4a`, etc.).
* **Preserves names**: Voice memo `memos/meeting_notes.m4a` will be saved to `transcripts/meeting_notes.txt`.
* **Error handling**: If one file fails, it reports the error and continues to the remaining files.