nexaai 1.0.21rc5__cp313-cp313-win_arm64.whl → 1.0.21rc16__cp313-cp313-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nexaai might be problematic. Click here for more details.
- nexaai/__init__.py +95 -95
- nexaai/_stub.cp313-win_arm64.pyd +0 -0
- nexaai/_version.py +4 -1
- nexaai/asr.py +68 -65
- nexaai/asr_impl/mlx_asr_impl.py +92 -92
- nexaai/asr_impl/pybind_asr_impl.py +127 -44
- nexaai/base.py +39 -39
- nexaai/binds/__init__.py +6 -5
- nexaai/binds/asr_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/common_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/cpu_gpu/ggml-base.dll +0 -0
- nexaai/binds/cpu_gpu/ggml-cpu.dll +0 -0
- nexaai/binds/cpu_gpu/ggml-opencl.dll +0 -0
- nexaai/binds/cpu_gpu/ggml.dll +0 -0
- nexaai/binds/cpu_gpu/mtmd.dll +0 -0
- nexaai/binds/cpu_gpu/nexa_cpu_gpu.dll +0 -0
- nexaai/binds/cpu_gpu/nexa_plugin.dll +0 -0
- nexaai/binds/embedder_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/libcrypto-3-arm64.dll +0 -0
- nexaai/binds/libssl-3-arm64.dll +0 -0
- nexaai/binds/llm_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/nexa_bridge.dll +0 -0
- nexaai/binds/npu/convnext-sdk.dll +0 -0
- nexaai/binds/npu/embed-gemma-sdk.dll +0 -0
- nexaai/binds/npu/ggml-base.dll +0 -0
- nexaai/binds/npu/ggml-cpu.dll +0 -0
- nexaai/binds/{nexaml → npu}/ggml-opencl.dll +0 -0
- nexaai/binds/npu/ggml.dll +0 -0
- nexaai/binds/npu/granite-nano-sdk.dll +0 -0
- nexaai/binds/npu/granite4-sdk.dll +0 -0
- nexaai/binds/npu/jina-rerank-sdk.dll +0 -0
- nexaai/binds/npu/liquid-sdk.dll +0 -0
- nexaai/binds/npu/llama3-3b-sdk.dll +0 -0
- nexaai/binds/npu/nexa-mm-process.dll +0 -0
- nexaai/binds/npu/nexa-sampling.dll +0 -0
- nexaai/binds/npu/nexa_plugin.dll +0 -0
- nexaai/binds/npu/omni-neural-sdk.dll +0 -0
- nexaai/binds/npu/openblas.dll +0 -0
- nexaai/binds/npu/paddleocr-sdk.dll +0 -0
- nexaai/binds/npu/parakeet-sdk.dll +0 -0
- nexaai/binds/npu/phi3-5-sdk.dll +0 -0
- nexaai/binds/npu/phi4-sdk.dll +0 -0
- nexaai/binds/npu/pyannote-sdk.dll +0 -0
- nexaai/binds/npu/qwen3-4b-sdk.dll +0 -0
- nexaai/binds/npu/qwen3vl-sdk.dll +0 -0
- nexaai/binds/npu/qwen3vl-vision.dll +0 -0
- nexaai/binds/npu/yolov12-sdk.dll +0 -0
- nexaai/binds/npu/zlib1.dll +0 -0
- nexaai/binds/rerank_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/vlm_bind.cp313-win_arm64.pyd +0 -0
- nexaai/common.py +105 -105
- nexaai/cv.py +93 -93
- nexaai/cv_impl/mlx_cv_impl.py +89 -89
- nexaai/cv_impl/pybind_cv_impl.py +32 -32
- nexaai/embedder.py +73 -73
- nexaai/embedder_impl/mlx_embedder_impl.py +118 -118
- nexaai/embedder_impl/pybind_embedder_impl.py +96 -96
- nexaai/image_gen.py +141 -141
- nexaai/image_gen_impl/mlx_image_gen_impl.py +292 -292
- nexaai/image_gen_impl/pybind_image_gen_impl.py +85 -85
- nexaai/llm.py +98 -98
- nexaai/llm_impl/mlx_llm_impl.py +271 -271
- nexaai/llm_impl/pybind_llm_impl.py +220 -220
- nexaai/log.py +92 -92
- nexaai/rerank.py +57 -57
- nexaai/rerank_impl/mlx_rerank_impl.py +94 -94
- nexaai/rerank_impl/pybind_rerank_impl.py +136 -136
- nexaai/runtime.py +68 -68
- nexaai/runtime_error.py +24 -24
- nexaai/tts.py +75 -75
- nexaai/tts_impl/mlx_tts_impl.py +94 -94
- nexaai/tts_impl/pybind_tts_impl.py +43 -43
- nexaai/utils/decode.py +17 -17
- nexaai/utils/manifest_utils.py +531 -531
- nexaai/utils/model_manager.py +1562 -1562
- nexaai/utils/model_types.py +49 -49
- nexaai/utils/progress_tracker.py +384 -384
- nexaai/utils/quantization_utils.py +245 -245
- nexaai/vlm.py +129 -129
- nexaai/vlm_impl/mlx_vlm_impl.py +258 -258
- nexaai/vlm_impl/pybind_vlm_impl.py +256 -256
- {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/METADATA +1 -1
- nexaai-1.0.21rc16.dist-info/RECORD +154 -0
- nexaai/binds/nexaml/FLAC.dll +0 -0
- nexaai/binds/nexaml/fftw3.dll +0 -0
- nexaai/binds/nexaml/fftw3f.dll +0 -0
- nexaai/binds/nexaml/ggml-base.dll +0 -0
- nexaai/binds/nexaml/ggml-cpu.dll +0 -0
- nexaai/binds/nexaml/ggml.dll +0 -0
- nexaai/binds/nexaml/libmp3lame.DLL +0 -0
- nexaai/binds/nexaml/mpg123.dll +0 -0
- nexaai/binds/nexaml/nexa-mm-process.dll +0 -0
- nexaai/binds/nexaml/nexa-sampling.dll +0 -0
- nexaai/binds/nexaml/nexa_plugin.dll +0 -0
- nexaai/binds/nexaml/nexaproc.dll +0 -0
- nexaai/binds/nexaml/ogg.dll +0 -0
- nexaai/binds/nexaml/opus.dll +0 -0
- nexaai/binds/nexaml/qwen3-vl.dll +0 -0
- nexaai/binds/nexaml/qwen3vl-vision.dll +0 -0
- nexaai/binds/nexaml/vorbis.dll +0 -0
- nexaai/binds/nexaml/vorbisenc.dll +0 -0
- nexaai-1.0.21rc5.dist-info/RECORD +0 -162
- {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/WHEEL +0 -0
- {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/top_level.txt +0 -0
nexaai/__init__.py
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
"""
|
|
2
|
-
NexaAI Python bindings for NexaSDK C-lib backend.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import sys
|
|
6
|
-
import os
|
|
7
|
-
|
|
8
|
-
# Add mlx_backend to Python path as individual module (only if it exists)
|
|
9
|
-
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
10
|
-
_mlx_backend_path = os.path.join(_current_dir, "mlx_backend")
|
|
11
|
-
# Only add to path if the directory exists (it won't on Windows)
|
|
12
|
-
if os.path.exists(_mlx_backend_path) and _mlx_backend_path not in sys.path:
|
|
13
|
-
sys.path.insert(0, _mlx_backend_path)
|
|
14
|
-
|
|
15
|
-
try:
|
|
16
|
-
from ._version import __version__
|
|
17
|
-
except ImportError:
|
|
18
|
-
# Fallback for development or when version file hasn't been generated yet
|
|
19
|
-
__version__ = "0.0.1"
|
|
20
|
-
|
|
21
|
-
# Import common configuration classes first (no external dependencies)
|
|
22
|
-
from .common import ModelConfig, GenerationConfig, ChatMessage, SamplerConfig, PluginID
|
|
23
|
-
|
|
24
|
-
# Import logging functionality
|
|
25
|
-
from .log import set_logger, get_error_message
|
|
26
|
-
|
|
27
|
-
# Import runtime errors
|
|
28
|
-
from .runtime_error import (
|
|
29
|
-
NexaRuntimeError,
|
|
30
|
-
ContextLengthExceededError,
|
|
31
|
-
GenerationError
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
# Create alias for PluginID to be accessible as plugin_id
|
|
35
|
-
plugin_id = PluginID
|
|
36
|
-
|
|
37
|
-
# Import new feature classes (no external dependencies in base classes)
|
|
38
|
-
from .llm import LLM
|
|
39
|
-
from .embedder import Embedder, EmbeddingConfig
|
|
40
|
-
from .vlm import VLM
|
|
41
|
-
from .asr import ASR, ASRConfig, ASRResult
|
|
42
|
-
from .cv import CVModel, CVModelConfig, CVResult, CVResults, CVCapabilities, BoundingBox
|
|
43
|
-
from .rerank import Reranker, RerankConfig
|
|
44
|
-
from .image_gen import ImageGen, ImageGenerationConfig, ImageSamplerConfig, SchedulerConfig, Image
|
|
45
|
-
from .tts import TTS, TTSConfig, TTSSamplerConfig, TTSResult
|
|
46
|
-
|
|
47
|
-
# Build __all__ list dynamically
|
|
48
|
-
__all__ = [
|
|
49
|
-
"__version__",
|
|
50
|
-
# Common configurations (always available)
|
|
51
|
-
"ModelConfig",
|
|
52
|
-
"GenerationConfig",
|
|
53
|
-
"ChatMessage",
|
|
54
|
-
"SamplerConfig",
|
|
55
|
-
"EmbeddingConfig",
|
|
56
|
-
"PluginID",
|
|
57
|
-
"plugin_id",
|
|
58
|
-
|
|
59
|
-
# Logging functionality
|
|
60
|
-
"set_logger",
|
|
61
|
-
"get_error_message",
|
|
62
|
-
|
|
63
|
-
# Runtime errors
|
|
64
|
-
"NexaRuntimeError",
|
|
65
|
-
"ContextLengthExceededError",
|
|
66
|
-
"GenerationError",
|
|
67
|
-
|
|
68
|
-
"LLM",
|
|
69
|
-
"Embedder",
|
|
70
|
-
"VLM",
|
|
71
|
-
"ASR",
|
|
72
|
-
"CVModel",
|
|
73
|
-
"Reranker",
|
|
74
|
-
"ImageGen",
|
|
75
|
-
"TTS",
|
|
76
|
-
|
|
77
|
-
"ASRConfig",
|
|
78
|
-
"ASRResult",
|
|
79
|
-
"CVModelConfig",
|
|
80
|
-
"CVResult",
|
|
81
|
-
"CVResults",
|
|
82
|
-
"CVCapabilities",
|
|
83
|
-
"BoundingBox",
|
|
84
|
-
"RerankConfig",
|
|
85
|
-
"ImageGenerationConfig",
|
|
86
|
-
"ImageSamplerConfig",
|
|
87
|
-
"SchedulerConfig",
|
|
88
|
-
"Image",
|
|
89
|
-
"TTSConfig",
|
|
90
|
-
"TTSSamplerConfig",
|
|
91
|
-
"TTSResult",
|
|
92
|
-
]
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
"""
|
|
2
|
+
NexaAI Python bindings for NexaSDK C-lib backend.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
# Add mlx_backend to Python path as individual module (only if it exists)
|
|
9
|
+
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
10
|
+
_mlx_backend_path = os.path.join(_current_dir, "mlx_backend")
|
|
11
|
+
# Only add to path if the directory exists (it won't on Windows)
|
|
12
|
+
if os.path.exists(_mlx_backend_path) and _mlx_backend_path not in sys.path:
|
|
13
|
+
sys.path.insert(0, _mlx_backend_path)
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from ._version import __version__
|
|
17
|
+
except ImportError:
|
|
18
|
+
# Fallback for development or when version file hasn't been generated yet
|
|
19
|
+
__version__ = "0.0.1"
|
|
20
|
+
|
|
21
|
+
# Import common configuration classes first (no external dependencies)
|
|
22
|
+
from .common import ModelConfig, GenerationConfig, ChatMessage, SamplerConfig, PluginID
|
|
23
|
+
|
|
24
|
+
# Import logging functionality
|
|
25
|
+
from .log import set_logger, get_error_message
|
|
26
|
+
|
|
27
|
+
# Import runtime errors
|
|
28
|
+
from .runtime_error import (
|
|
29
|
+
NexaRuntimeError,
|
|
30
|
+
ContextLengthExceededError,
|
|
31
|
+
GenerationError
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Create alias for PluginID to be accessible as plugin_id
|
|
35
|
+
plugin_id = PluginID
|
|
36
|
+
|
|
37
|
+
# Import new feature classes (no external dependencies in base classes)
|
|
38
|
+
from .llm import LLM
|
|
39
|
+
from .embedder import Embedder, EmbeddingConfig
|
|
40
|
+
from .vlm import VLM
|
|
41
|
+
from .asr import ASR, ASRConfig, ASRResult
|
|
42
|
+
from .cv import CVModel, CVModelConfig, CVResult, CVResults, CVCapabilities, BoundingBox
|
|
43
|
+
from .rerank import Reranker, RerankConfig
|
|
44
|
+
from .image_gen import ImageGen, ImageGenerationConfig, ImageSamplerConfig, SchedulerConfig, Image
|
|
45
|
+
from .tts import TTS, TTSConfig, TTSSamplerConfig, TTSResult
|
|
46
|
+
|
|
47
|
+
# Build __all__ list dynamically
|
|
48
|
+
__all__ = [
|
|
49
|
+
"__version__",
|
|
50
|
+
# Common configurations (always available)
|
|
51
|
+
"ModelConfig",
|
|
52
|
+
"GenerationConfig",
|
|
53
|
+
"ChatMessage",
|
|
54
|
+
"SamplerConfig",
|
|
55
|
+
"EmbeddingConfig",
|
|
56
|
+
"PluginID",
|
|
57
|
+
"plugin_id",
|
|
58
|
+
|
|
59
|
+
# Logging functionality
|
|
60
|
+
"set_logger",
|
|
61
|
+
"get_error_message",
|
|
62
|
+
|
|
63
|
+
# Runtime errors
|
|
64
|
+
"NexaRuntimeError",
|
|
65
|
+
"ContextLengthExceededError",
|
|
66
|
+
"GenerationError",
|
|
67
|
+
|
|
68
|
+
"LLM",
|
|
69
|
+
"Embedder",
|
|
70
|
+
"VLM",
|
|
71
|
+
"ASR",
|
|
72
|
+
"CVModel",
|
|
73
|
+
"Reranker",
|
|
74
|
+
"ImageGen",
|
|
75
|
+
"TTS",
|
|
76
|
+
|
|
77
|
+
"ASRConfig",
|
|
78
|
+
"ASRResult",
|
|
79
|
+
"CVModelConfig",
|
|
80
|
+
"CVResult",
|
|
81
|
+
"CVResults",
|
|
82
|
+
"CVCapabilities",
|
|
83
|
+
"BoundingBox",
|
|
84
|
+
"RerankConfig",
|
|
85
|
+
"ImageGenerationConfig",
|
|
86
|
+
"ImageSamplerConfig",
|
|
87
|
+
"SchedulerConfig",
|
|
88
|
+
"Image",
|
|
89
|
+
"TTSConfig",
|
|
90
|
+
"TTSSamplerConfig",
|
|
91
|
+
"TTSResult",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
nexaai/_stub.cp313-win_arm64.pyd
CHANGED
|
Binary file
|
nexaai/_version.py
CHANGED
nexaai/asr.py
CHANGED
|
@@ -1,65 +1,68 @@
|
|
|
1
|
-
from typing import List, Optional, Sequence, Tuple, Union
|
|
2
|
-
from abc import abstractmethod
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
|
|
5
|
-
from nexaai.base import BaseModel
|
|
6
|
-
from nexaai.common import PluginID
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@dataclass
|
|
10
|
-
class ASRConfig:
|
|
11
|
-
"""Configuration for ASR."""
|
|
12
|
-
timestamps: str = "none" # "none" | "segment" | "word"
|
|
13
|
-
beam_size: int = 5
|
|
14
|
-
stream: bool = False
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@dataclass
|
|
18
|
-
class ASRResult:
|
|
19
|
-
"""Result from ASR processing."""
|
|
20
|
-
transcript: str
|
|
21
|
-
confidence_scores: Sequence[float]
|
|
22
|
-
timestamps: Sequence[Tuple[float, float]]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ASR(BaseModel):
|
|
26
|
-
"""Abstract base class for Automatic Speech Recognition models."""
|
|
27
|
-
|
|
28
|
-
def __init__(self):
|
|
29
|
-
"""Initialize base ASR class."""
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@classmethod
|
|
33
|
-
def _load_from(cls,
|
|
34
|
-
model_path: str,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
from typing import List, Optional, Sequence, Tuple, Union
|
|
2
|
+
from abc import abstractmethod
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from nexaai.base import BaseModel
|
|
6
|
+
from nexaai.common import PluginID, ModelConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class ASRConfig:
|
|
11
|
+
"""Configuration for ASR."""
|
|
12
|
+
timestamps: str = "none" # "none" | "segment" | "word"
|
|
13
|
+
beam_size: int = 5
|
|
14
|
+
stream: bool = False
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ASRResult:
|
|
19
|
+
"""Result from ASR processing."""
|
|
20
|
+
transcript: str
|
|
21
|
+
confidence_scores: Sequence[float]
|
|
22
|
+
timestamps: Sequence[Tuple[float, float]]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ASR(BaseModel):
|
|
26
|
+
"""Abstract base class for Automatic Speech Recognition models."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, m_cfg: ModelConfig = ModelConfig()):
|
|
29
|
+
"""Initialize base ASR class."""
|
|
30
|
+
self._m_cfg = m_cfg
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def _load_from(cls,
|
|
34
|
+
model_path: str,
|
|
35
|
+
model_name: Optional[str] = None,
|
|
36
|
+
tokenizer_path: Optional[str] = None,
|
|
37
|
+
language: Optional[str] = None,
|
|
38
|
+
m_cfg: ModelConfig = ModelConfig(),
|
|
39
|
+
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
40
|
+
device_id: Optional[str] = None,
|
|
41
|
+
**kwargs
|
|
42
|
+
) -> 'ASR':
|
|
43
|
+
"""Load ASR model from local path, routing to appropriate implementation."""
|
|
44
|
+
# Check plugin_id value for routing - handle both enum and string
|
|
45
|
+
plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
|
|
46
|
+
|
|
47
|
+
if plugin_value == "mlx":
|
|
48
|
+
from nexaai.asr_impl.mlx_asr_impl import MLXASRImpl
|
|
49
|
+
return MLXASRImpl._load_from(model_path, model_name, tokenizer_path, language, m_cfg, plugin_id, device_id)
|
|
50
|
+
else:
|
|
51
|
+
from nexaai.asr_impl.pybind_asr_impl import PyBindASRImpl
|
|
52
|
+
return PyBindASRImpl._load_from(model_path, model_name, tokenizer_path, language, m_cfg, plugin_id, device_id)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@abstractmethod
|
|
56
|
+
def transcribe(
|
|
57
|
+
self,
|
|
58
|
+
audio_path: str,
|
|
59
|
+
language: Optional[str] = None,
|
|
60
|
+
config: Optional[ASRConfig] = None,
|
|
61
|
+
) -> ASRResult:
|
|
62
|
+
"""Transcribe audio file to text."""
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def list_supported_languages(self) -> List[str]:
|
|
67
|
+
"""List supported languages."""
|
|
68
|
+
pass
|
nexaai/asr_impl/mlx_asr_impl.py
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
# Note: This code is generated by Cursor, not tested yet.
|
|
2
|
-
|
|
3
|
-
from typing import List, Optional, Union
|
|
4
|
-
|
|
5
|
-
from nexaai.common import PluginID
|
|
6
|
-
from nexaai.asr import ASR, ASRConfig, ASRResult
|
|
7
|
-
from nexaai.mlx_backend.asr.interface import MlxAsr as MLXASRInterface
|
|
8
|
-
from nexaai.mlx_backend.ml import ModelConfig as MLXModelConfig, SamplerConfig as MLXSamplerConfig, GenerationConfig as MLXGenerationConfig, EmbeddingConfig
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class MLXASRImpl(ASR):
|
|
12
|
-
def __init__(self):
|
|
13
|
-
"""Initialize MLX ASR implementation."""
|
|
14
|
-
super().__init__()
|
|
15
|
-
self._mlx_asr = None
|
|
16
|
-
|
|
17
|
-
@classmethod
|
|
18
|
-
def _load_from(cls,
|
|
19
|
-
model_path: str,
|
|
20
|
-
tokenizer_path: Optional[str] = None,
|
|
21
|
-
language: Optional[str] = None,
|
|
22
|
-
plugin_id: Union[PluginID, str] = PluginID.MLX,
|
|
23
|
-
device_id: Optional[str] = None
|
|
24
|
-
) -> 'MLXASRImpl':
|
|
25
|
-
"""Load ASR model from local path using MLX backend."""
|
|
26
|
-
try:
|
|
27
|
-
# MLX ASR interface is already imported
|
|
28
|
-
|
|
29
|
-
# Create instance and load MLX ASR
|
|
30
|
-
instance = cls()
|
|
31
|
-
instance._mlx_asr = MLXASRInterface(
|
|
32
|
-
model_path=model_path,
|
|
33
|
-
tokenizer_path=tokenizer_path,
|
|
34
|
-
language=language,
|
|
35
|
-
device=device_id
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
return instance
|
|
39
|
-
except Exception as e:
|
|
40
|
-
raise RuntimeError(f"Failed to load MLX ASR: {str(e)}")
|
|
41
|
-
|
|
42
|
-
def eject(self):
|
|
43
|
-
"""Destroy the model and free resources."""
|
|
44
|
-
if self._mlx_asr:
|
|
45
|
-
self._mlx_asr.destroy()
|
|
46
|
-
self._mlx_asr = None
|
|
47
|
-
|
|
48
|
-
def transcribe(
|
|
49
|
-
self,
|
|
50
|
-
audio_path: str,
|
|
51
|
-
language: Optional[str] = None,
|
|
52
|
-
config: Optional[ASRConfig] = None,
|
|
53
|
-
) -> ASRResult:
|
|
54
|
-
"""Transcribe audio file to text."""
|
|
55
|
-
if not self._mlx_asr:
|
|
56
|
-
raise RuntimeError("MLX ASR not loaded")
|
|
57
|
-
|
|
58
|
-
try:
|
|
59
|
-
# Convert our config to MLX format if provided
|
|
60
|
-
mlx_config = None
|
|
61
|
-
if config:
|
|
62
|
-
from nexaai.mlx_backend.ml import ASRConfig as MLXASRConfig
|
|
63
|
-
|
|
64
|
-
mlx_config = MLXASRConfig()
|
|
65
|
-
mlx_config.timestamps = config.timestamps
|
|
66
|
-
mlx_config.beam_size = config.beam_size
|
|
67
|
-
mlx_config.stream = config.stream
|
|
68
|
-
|
|
69
|
-
# Use MLX ASR transcription
|
|
70
|
-
result = self._mlx_asr.transcribe(audio_path, language, mlx_config)
|
|
71
|
-
|
|
72
|
-
# Convert MLX result to our format
|
|
73
|
-
return ASRResult(
|
|
74
|
-
transcript=result.transcript,
|
|
75
|
-
confidence_scores=result.confidence_scores,
|
|
76
|
-
timestamps=result.timestamps
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
except Exception as e:
|
|
80
|
-
raise RuntimeError(f"Failed to transcribe audio: {str(e)}")
|
|
81
|
-
|
|
82
|
-
def list_supported_languages(self) -> List[str]:
|
|
83
|
-
"""List supported languages."""
|
|
84
|
-
if not self._mlx_asr:
|
|
85
|
-
raise RuntimeError("MLX ASR not loaded")
|
|
86
|
-
|
|
87
|
-
try:
|
|
88
|
-
return self._mlx_asr.list_supported_languages()
|
|
89
|
-
except Exception as e:
|
|
90
|
-
raise RuntimeError(f"Failed to list supported languages: {str(e)}")
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
# Note: This code is generated by Cursor, not tested yet.
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional, Union
|
|
4
|
+
|
|
5
|
+
from nexaai.common import PluginID
|
|
6
|
+
from nexaai.asr import ASR, ASRConfig, ASRResult
|
|
7
|
+
from nexaai.mlx_backend.asr.interface import MlxAsr as MLXASRInterface
|
|
8
|
+
from nexaai.mlx_backend.ml import ModelConfig as MLXModelConfig, SamplerConfig as MLXSamplerConfig, GenerationConfig as MLXGenerationConfig, EmbeddingConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MLXASRImpl(ASR):
|
|
12
|
+
def __init__(self):
|
|
13
|
+
"""Initialize MLX ASR implementation."""
|
|
14
|
+
super().__init__()
|
|
15
|
+
self._mlx_asr = None
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def _load_from(cls,
|
|
19
|
+
model_path: str,
|
|
20
|
+
tokenizer_path: Optional[str] = None,
|
|
21
|
+
language: Optional[str] = None,
|
|
22
|
+
plugin_id: Union[PluginID, str] = PluginID.MLX,
|
|
23
|
+
device_id: Optional[str] = None
|
|
24
|
+
) -> 'MLXASRImpl':
|
|
25
|
+
"""Load ASR model from local path using MLX backend."""
|
|
26
|
+
try:
|
|
27
|
+
# MLX ASR interface is already imported
|
|
28
|
+
|
|
29
|
+
# Create instance and load MLX ASR
|
|
30
|
+
instance = cls()
|
|
31
|
+
instance._mlx_asr = MLXASRInterface(
|
|
32
|
+
model_path=model_path,
|
|
33
|
+
tokenizer_path=tokenizer_path,
|
|
34
|
+
language=language,
|
|
35
|
+
device=device_id
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return instance
|
|
39
|
+
except Exception as e:
|
|
40
|
+
raise RuntimeError(f"Failed to load MLX ASR: {str(e)}")
|
|
41
|
+
|
|
42
|
+
def eject(self):
|
|
43
|
+
"""Destroy the model and free resources."""
|
|
44
|
+
if self._mlx_asr:
|
|
45
|
+
self._mlx_asr.destroy()
|
|
46
|
+
self._mlx_asr = None
|
|
47
|
+
|
|
48
|
+
def transcribe(
|
|
49
|
+
self,
|
|
50
|
+
audio_path: str,
|
|
51
|
+
language: Optional[str] = None,
|
|
52
|
+
config: Optional[ASRConfig] = None,
|
|
53
|
+
) -> ASRResult:
|
|
54
|
+
"""Transcribe audio file to text."""
|
|
55
|
+
if not self._mlx_asr:
|
|
56
|
+
raise RuntimeError("MLX ASR not loaded")
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
# Convert our config to MLX format if provided
|
|
60
|
+
mlx_config = None
|
|
61
|
+
if config:
|
|
62
|
+
from nexaai.mlx_backend.ml import ASRConfig as MLXASRConfig
|
|
63
|
+
|
|
64
|
+
mlx_config = MLXASRConfig()
|
|
65
|
+
mlx_config.timestamps = config.timestamps
|
|
66
|
+
mlx_config.beam_size = config.beam_size
|
|
67
|
+
mlx_config.stream = config.stream
|
|
68
|
+
|
|
69
|
+
# Use MLX ASR transcription
|
|
70
|
+
result = self._mlx_asr.transcribe(audio_path, language, mlx_config)
|
|
71
|
+
|
|
72
|
+
# Convert MLX result to our format
|
|
73
|
+
return ASRResult(
|
|
74
|
+
transcript=result.transcript,
|
|
75
|
+
confidence_scores=result.confidence_scores,
|
|
76
|
+
timestamps=result.timestamps
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
except Exception as e:
|
|
80
|
+
raise RuntimeError(f"Failed to transcribe audio: {str(e)}")
|
|
81
|
+
|
|
82
|
+
def list_supported_languages(self) -> List[str]:
|
|
83
|
+
"""List supported languages."""
|
|
84
|
+
if not self._mlx_asr:
|
|
85
|
+
raise RuntimeError("MLX ASR not loaded")
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
return self._mlx_asr.list_supported_languages()
|
|
89
|
+
except Exception as e:
|
|
90
|
+
raise RuntimeError(f"Failed to list supported languages: {str(e)}")
|
|
91
|
+
|
|
92
|
+
|