experiments/babel/app/pages/explore.py [51:121]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    voices: list[Voice] = field(default_factory=lambda: [])

    is_loading: bool = False
    statement: str = ""
    audio_output_uri: str = ""
    audio_output_infos: list[str] = field(default_factory=lambda: [])
    audio_output_metadata: list[BabelMetadata] = field(default_factory=lambda: [])
    audio_status: str = ""
    loaded: bool = False
    # pylint: disable=invalid-field-call


def get_chosen_voices():
    """
    Filters a list of Voice dictionaries, keeping only those whose name contains "Puck" or "Leda".

    Args:
        voices: A list of Voice dictionaries.

    Returns:
        A new list of Voice dictionaries, filtered based on the name.
    """
    app_state = me.state(AppState)
    print(f"there are {len(app_state.voices)} total voices")
    voices = app_state.voices

    filtered_voices = [
        voice for voice in voices if "Puck" in voice["name"] or "Leda" in voice["name"]
    ]
    return filtered_voices


def filter_babel_metadata(filepath: str) -> list[BabelMetadata]:
    """
    Reads a JSON file, filters the 'audio_metadata' list to keep only entries
    with voice_name containing "Puck" or "Leda", and returns the filtered data as a List[BabelMetadata].

    Args:
        filepath: The path to the JSON file.

    Returns:
        A List[BabelMetadata] containing the filtered data.
    """
    try:
        with open(filepath, "r") as f:
            data = json.load(f)
    except FileNotFoundError:
        print(f"Error: File '{filepath}' not found.")
        return []
    except json.JSONDecodeError:
        print(f"Error: Invalid JSON format in '{filepath}'.")
        return []

    if "audio_metadata" not in data or not isinstance(data["audio_metadata"], list):
        print(f"Warning: 'audio_metadata' key not found or not a list in '{filepath}'.")
        return []

    filtered_metadata: list[BabelMetadata] = [
        {
            "voice_name": item["voice_name"],
            "language_code": item["language_code"],
            "gender": item["gender"],
            "text": item["text"],
            "audio_path": item["audio_path"],
        }
        for item in data["audio_metadata"]
        if "voice_name" in item
        and ("Puck" in item["voice_name"] or "Leda" in item["voice_name"])
    ]

    return filtered_metadata
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



experiments/babel/app/pages/welcome.py [50:120]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    voices: list[Voice] = field(default_factory=lambda: [])

    is_loading: bool = False
    statement: str = ""
    audio_output_uri: str = ""
    audio_output_infos: list[str] = field(default_factory=lambda: [])
    audio_output_metadata: list[BabelMetadata] = field(default_factory=lambda: [])
    audio_status: str = ""
    loaded: bool = False
    # pylint: disable=invalid-field-call


def get_chosen_voices():
    """
    Filters a list of Voice dictionaries, keeping only those whose name contains "Puck" or "Leda".

    Args:
        voices: A list of Voice dictionaries.

    Returns:
        A new list of Voice dictionaries, filtered based on the name.
    """
    app_state = me.state(AppState)
    print(f"there are {len(app_state.voices)} total voices")
    voices = app_state.voices

    filtered_voices = [
        voice for voice in voices if "Puck" in voice["name"] or "Leda" in voice["name"]
    ]
    return filtered_voices


def filter_babel_metadata(filepath: str) -> list[BabelMetadata]:
    """
    Reads a JSON file, filters the 'audio_metadata' list to keep only entries
    with voice_name containing "Puck" or "Leda", and returns the filtered data as a List[BabelMetadata].

    Args:
        filepath: The path to the JSON file.

    Returns:
        A List[BabelMetadata] containing the filtered data.
    """
    try:
        with open(filepath, "r") as f:
            data = json.load(f)
    except FileNotFoundError:
        print(f"Error: File '{filepath}' not found.")
        return []
    except json.JSONDecodeError:
        print(f"Error: Invalid JSON format in '{filepath}'.")
        return []

    if "audio_metadata" not in data or not isinstance(data["audio_metadata"], list):
        print(f"Warning: 'audio_metadata' key not found or not a list in '{filepath}'.")
        return []

    filtered_metadata: list[BabelMetadata] = [
        {
            "voice_name": item["voice_name"],
            "language_code": item["language_code"],
            "gender": item["gender"],
            "text": item["text"],
            "audio_path": item["audio_path"],
        }
        for item in data["audio_metadata"]
        if "voice_name" in item
        and ("Puck" in item["voice_name"] or "Leda" in item["voice_name"])
    ]

    return filtered_metadata
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



