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.

Files changed (104) hide show
  1. nexaai/__init__.py +95 -95
  2. nexaai/_stub.cp313-win_arm64.pyd +0 -0
  3. nexaai/_version.py +4 -1
  4. nexaai/asr.py +68 -65
  5. nexaai/asr_impl/mlx_asr_impl.py +92 -92
  6. nexaai/asr_impl/pybind_asr_impl.py +127 -44
  7. nexaai/base.py +39 -39
  8. nexaai/binds/__init__.py +6 -5
  9. nexaai/binds/asr_bind.cp313-win_arm64.pyd +0 -0
  10. nexaai/binds/common_bind.cp313-win_arm64.pyd +0 -0
  11. nexaai/binds/cpu_gpu/ggml-base.dll +0 -0
  12. nexaai/binds/cpu_gpu/ggml-cpu.dll +0 -0
  13. nexaai/binds/cpu_gpu/ggml-opencl.dll +0 -0
  14. nexaai/binds/cpu_gpu/ggml.dll +0 -0
  15. nexaai/binds/cpu_gpu/mtmd.dll +0 -0
  16. nexaai/binds/cpu_gpu/nexa_cpu_gpu.dll +0 -0
  17. nexaai/binds/cpu_gpu/nexa_plugin.dll +0 -0
  18. nexaai/binds/embedder_bind.cp313-win_arm64.pyd +0 -0
  19. nexaai/binds/libcrypto-3-arm64.dll +0 -0
  20. nexaai/binds/libssl-3-arm64.dll +0 -0
  21. nexaai/binds/llm_bind.cp313-win_arm64.pyd +0 -0
  22. nexaai/binds/nexa_bridge.dll +0 -0
  23. nexaai/binds/npu/convnext-sdk.dll +0 -0
  24. nexaai/binds/npu/embed-gemma-sdk.dll +0 -0
  25. nexaai/binds/npu/ggml-base.dll +0 -0
  26. nexaai/binds/npu/ggml-cpu.dll +0 -0
  27. nexaai/binds/{nexaml → npu}/ggml-opencl.dll +0 -0
  28. nexaai/binds/npu/ggml.dll +0 -0
  29. nexaai/binds/npu/granite-nano-sdk.dll +0 -0
  30. nexaai/binds/npu/granite4-sdk.dll +0 -0
  31. nexaai/binds/npu/jina-rerank-sdk.dll +0 -0
  32. nexaai/binds/npu/liquid-sdk.dll +0 -0
  33. nexaai/binds/npu/llama3-3b-sdk.dll +0 -0
  34. nexaai/binds/npu/nexa-mm-process.dll +0 -0
  35. nexaai/binds/npu/nexa-sampling.dll +0 -0
  36. nexaai/binds/npu/nexa_plugin.dll +0 -0
  37. nexaai/binds/npu/omni-neural-sdk.dll +0 -0
  38. nexaai/binds/npu/openblas.dll +0 -0
  39. nexaai/binds/npu/paddleocr-sdk.dll +0 -0
  40. nexaai/binds/npu/parakeet-sdk.dll +0 -0
  41. nexaai/binds/npu/phi3-5-sdk.dll +0 -0
  42. nexaai/binds/npu/phi4-sdk.dll +0 -0
  43. nexaai/binds/npu/pyannote-sdk.dll +0 -0
  44. nexaai/binds/npu/qwen3-4b-sdk.dll +0 -0
  45. nexaai/binds/npu/qwen3vl-sdk.dll +0 -0
  46. nexaai/binds/npu/qwen3vl-vision.dll +0 -0
  47. nexaai/binds/npu/yolov12-sdk.dll +0 -0
  48. nexaai/binds/npu/zlib1.dll +0 -0
  49. nexaai/binds/rerank_bind.cp313-win_arm64.pyd +0 -0
  50. nexaai/binds/vlm_bind.cp313-win_arm64.pyd +0 -0
  51. nexaai/common.py +105 -105
  52. nexaai/cv.py +93 -93
  53. nexaai/cv_impl/mlx_cv_impl.py +89 -89
  54. nexaai/cv_impl/pybind_cv_impl.py +32 -32
  55. nexaai/embedder.py +73 -73
  56. nexaai/embedder_impl/mlx_embedder_impl.py +118 -118
  57. nexaai/embedder_impl/pybind_embedder_impl.py +96 -96
  58. nexaai/image_gen.py +141 -141
  59. nexaai/image_gen_impl/mlx_image_gen_impl.py +292 -292
  60. nexaai/image_gen_impl/pybind_image_gen_impl.py +85 -85
  61. nexaai/llm.py +98 -98
  62. nexaai/llm_impl/mlx_llm_impl.py +271 -271
  63. nexaai/llm_impl/pybind_llm_impl.py +220 -220
  64. nexaai/log.py +92 -92
  65. nexaai/rerank.py +57 -57
  66. nexaai/rerank_impl/mlx_rerank_impl.py +94 -94
  67. nexaai/rerank_impl/pybind_rerank_impl.py +136 -136
  68. nexaai/runtime.py +68 -68
  69. nexaai/runtime_error.py +24 -24
  70. nexaai/tts.py +75 -75
  71. nexaai/tts_impl/mlx_tts_impl.py +94 -94
  72. nexaai/tts_impl/pybind_tts_impl.py +43 -43
  73. nexaai/utils/decode.py +17 -17
  74. nexaai/utils/manifest_utils.py +531 -531
  75. nexaai/utils/model_manager.py +1562 -1562
  76. nexaai/utils/model_types.py +49 -49
  77. nexaai/utils/progress_tracker.py +384 -384
  78. nexaai/utils/quantization_utils.py +245 -245
  79. nexaai/vlm.py +129 -129
  80. nexaai/vlm_impl/mlx_vlm_impl.py +258 -258
  81. nexaai/vlm_impl/pybind_vlm_impl.py +256 -256
  82. {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/METADATA +1 -1
  83. nexaai-1.0.21rc16.dist-info/RECORD +154 -0
  84. nexaai/binds/nexaml/FLAC.dll +0 -0
  85. nexaai/binds/nexaml/fftw3.dll +0 -0
  86. nexaai/binds/nexaml/fftw3f.dll +0 -0
  87. nexaai/binds/nexaml/ggml-base.dll +0 -0
  88. nexaai/binds/nexaml/ggml-cpu.dll +0 -0
  89. nexaai/binds/nexaml/ggml.dll +0 -0
  90. nexaai/binds/nexaml/libmp3lame.DLL +0 -0
  91. nexaai/binds/nexaml/mpg123.dll +0 -0
  92. nexaai/binds/nexaml/nexa-mm-process.dll +0 -0
  93. nexaai/binds/nexaml/nexa-sampling.dll +0 -0
  94. nexaai/binds/nexaml/nexa_plugin.dll +0 -0
  95. nexaai/binds/nexaml/nexaproc.dll +0 -0
  96. nexaai/binds/nexaml/ogg.dll +0 -0
  97. nexaai/binds/nexaml/opus.dll +0 -0
  98. nexaai/binds/nexaml/qwen3-vl.dll +0 -0
  99. nexaai/binds/nexaml/qwen3vl-vision.dll +0 -0
  100. nexaai/binds/nexaml/vorbis.dll +0 -0
  101. nexaai/binds/nexaml/vorbisenc.dll +0 -0
  102. nexaai-1.0.21rc5.dist-info/RECORD +0 -162
  103. {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/WHEEL +0 -0
  104. {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
+
Binary file
nexaai/_version.py CHANGED
@@ -1 +1,4 @@
1
- __version__ = "1.0.21rc5"
1
+ # This file is generated by CMake from _version.py.in
2
+ # Do not modify this file manually - it will be overwritten
3
+
4
+ __version__ = "1.0.21rc16"
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
- pass
31
-
32
- @classmethod
33
- def _load_from(cls,
34
- model_path: str,
35
- tokenizer_path: Optional[str] = None,
36
- language: Optional[str] = None,
37
- plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
38
- device_id: Optional[str] = None,
39
- **kwargs
40
- ) -> 'ASR':
41
- """Load ASR model from local path, routing to appropriate implementation."""
42
- # Check plugin_id value for routing - handle both enum and string
43
- plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
44
-
45
- if plugin_value == "mlx":
46
- from nexaai.asr_impl.mlx_asr_impl import MLXASRImpl
47
- return MLXASRImpl._load_from(model_path, tokenizer_path, language, plugin_id, device_id)
48
- else:
49
- from nexaai.asr_impl.pybind_asr_impl import PyBindASRImpl
50
- return PyBindASRImpl._load_from(model_path, tokenizer_path, language, plugin_id, device_id)
51
-
52
- @abstractmethod
53
- def transcribe(
54
- self,
55
- audio_path: str,
56
- language: Optional[str] = None,
57
- config: Optional[ASRConfig] = None,
58
- ) -> ASRResult:
59
- """Transcribe audio file to text."""
60
- pass
61
-
62
- @abstractmethod
63
- def list_supported_languages(self) -> List[str]:
64
- """List supported languages."""
65
- pass
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
@@ -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
+