File size: 2,011 Bytes
51e84d2
 
 
 
 
 
 
 
fc1dcbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# License: Apache-2.0 License
# Created by: Patrick Lumbantobing, VertoX-AI
# Copyright (c) 2026 VertoX-AI. All rights reserved.
#
# This work is licensed under the Apache-2.0 License.
# To view a copy of this license, visit
# https://www.apache.org/licenses/LICENSE-2.0

"""Define structural backend contracts consumed by application services."""

from __future__ import annotations

from collections.abc import Sequence
from typing import Protocol, runtime_checkable

from speech_text_data_aligners.core.models import (
    AlignmentOutcome,
    AlignmentRequest,
    AlignmentResult,
)


@runtime_checkable
class AlignmentBackend(Protocol):
    """Expose interchangeable single and ordered batch forced alignment."""

    @property
    def name(self) -> str:
        """Return the backend's stable registry/report name."""
        ...

    def align(self, request: AlignmentRequest) -> AlignmentResult:
        """Align one authoritative transcript against its WAV.

        Parameters
        ----------
            request: Fully populated backend-neutral alignment request.

        Returns
        -------
            A complete backend-neutral alignment result.

        Raises
        ------
            SpeechTextAlignerError: If configuration, execution, parsing, mapping, or
                validation fails. Concrete backends document the precise subclasses.

        """
        ...

    def align_batch(
        self,
        requests: Sequence[AlignmentRequest],
    ) -> tuple[AlignmentOutcome, ...]:
        """Align requests in order and return exactly one outcome per request.

        Parameters
        ----------
            requests: Ordered, fully populated requests.

        Returns
        -------
            Ordered outcomes matching request count and identities.

        Raises
        ------
            SpeechTextAlignerError: For whole-provider or configuration failures that
                cannot be represented as independent per-request outcomes.

        """
        ...