nexaai 1.0.29__cp310-cp310-macosx_14_0_universal2.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.
- nexaai/__init__.py +99 -0
- nexaai/_stub.cpython-310-darwin.so +0 -0
- nexaai/_version.py +4 -0
- nexaai/asr.py +68 -0
- nexaai/asr_impl/__init__.py +0 -0
- nexaai/asr_impl/mlx_asr_impl.py +93 -0
- nexaai/asr_impl/pybind_asr_impl.py +127 -0
- nexaai/base.py +39 -0
- nexaai/binds/__init__.py +7 -0
- nexaai/binds/asr_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/common_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/cpu_gpu/libggml-base.dylib +0 -0
- nexaai/binds/cpu_gpu/libggml-cpu.so +0 -0
- nexaai/binds/cpu_gpu/libggml-metal.so +0 -0
- nexaai/binds/cpu_gpu/libggml.dylib +0 -0
- nexaai/binds/cpu_gpu/libmtmd.dylib +0 -0
- nexaai/binds/cpu_gpu/libnexa_cpu_gpu.dylib +0 -0
- nexaai/binds/cpu_gpu/libnexa_plugin.dylib +0 -0
- nexaai/binds/cv_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/diarize_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/embedder_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/libnexa_bridge.dylib +0 -0
- nexaai/binds/llm_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/metal/libnexa_plugin.dylib +0 -0
- nexaai/binds/metal/py-lib/ml.py +888 -0
- nexaai/binds/metal/py-lib/mlx_audio/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/__init__.py +5 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/activation.py +51 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/amp.py +96 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/bigvgan.py +149 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/conv.py +114 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/bigvgan/resample.py +177 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/base.py +228 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/dac.py +285 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/nn/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/nn/layers.py +129 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/descript/nn/quantize.py +149 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/encodec/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/encodec/encodec.py +777 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/mimi.py +286 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/__init__.py +20 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/conv.py +398 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/kv_cache.py +199 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/quantization.py +179 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/seanet.py +314 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/mimi/modules/transformer.py +256 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/model.py +260 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/model_v2.py +383 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/s3/utils.py +122 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/attention.py +97 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/layers.py +306 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/snac.py +154 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/snac/vq.py +135 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/vocos/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/vocos/mel.py +33 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/models/vocos/vocos.py +359 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_bigvgan.py +54 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_descript.py +109 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_encodec.py +58 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_mimi.py +22 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_s3.py +25 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_snac.py +40 -0
- nexaai/binds/metal/py-lib/mlx_audio/codec/tests/test_vocos.py +93 -0
- nexaai/binds/metal/py-lib/mlx_audio/server.py +525 -0
- nexaai/binds/metal/py-lib/mlx_audio/sts/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/sts/tests/test_voice_pipeline.py +156 -0
- nexaai/binds/metal/py-lib/mlx_audio/sts/voice_pipeline.py +327 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/generate.py +174 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/alignment.py +248 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/attention.py +187 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/audio.py +76 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/conformer.py +331 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/ctc.py +34 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/parakeet.py +604 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/rnnt.py +157 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/parakeet/tokenizer.py +2 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/wav2vec/feature_extractor.py +757 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/wav2vec/wav2vec.py +738 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/audio.py +82 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/decoding.py +742 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/timing.py +329 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/tokenizer.py +398 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/whisper.py +862 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/models/whisper/writers.py +268 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/tests/test_models.py +381 -0
- nexaai/binds/metal/py-lib/mlx_audio/stt/utils.py +195 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/audio_player.py +120 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/convert.py +71 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/generate.py +449 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/__init__.py +4 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/bark.py +528 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/isftnet.py +12 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/bark/pipeline.py +442 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/base.py +84 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/audio.py +287 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/config.py +256 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/dia.py +592 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/dia/layers.py +870 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/__init__.py +3 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/attention.py +180 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/bigvgan.py +124 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/conformer.py +247 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/asp.py +59 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/ecapa_tdnn.py +91 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/se_res2net.py +132 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/ecapa_tdnn/tdnn.py +42 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/gpt2.py +38 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/indextts.py +412 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/mel.py +37 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/normalize.py +294 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/indextts/perceiver.py +62 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/interpolate.py +108 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/__init__.py +4 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/istftnet.py +979 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/kokoro.py +331 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/modules.py +659 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/pipeline.py +453 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/kokoro/voice.py +113 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/llama/__init__.py +3 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/llama/llama.py +324 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/audio_processor.py +351 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/dac_interface.py +162 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/outetts.py +255 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/prompt_processor.py +181 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/outetts/tokens.py +36 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/__init__.py +3 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/attention.py +195 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/sesame.py +633 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/sesame/watermarking.py +105 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/audio_tokenizer.py +138 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/bicodec.py +269 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/blocks/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/blocks/sampler.py +111 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_decoder.py +120 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_encoder.py +136 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/encoder_decoder/wave_generator.py +113 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/finite_scalar_quantization.py +238 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/residual.py +209 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/residual_fsq.py +309 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/__init__.py +1 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/ecapa_tdnn.py +283 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/perceiver_encoder.py +326 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/pooling_layers.py +297 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/modules/speaker/speaker_encoder.py +155 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/spark.py +382 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/utils/audio.py +220 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/utils/file.py +221 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/models/spark/utils/token_parser.py +181 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/__init__.py +0 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_base.py +66 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_convert.py +173 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_interpolate.py +88 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/tests/test_models.py +974 -0
- nexaai/binds/metal/py-lib/mlx_audio/tts/utils.py +337 -0
- nexaai/binds/metal/py-lib/mlx_audio/utils.py +237 -0
- nexaai/binds/metal/py-lib/mlx_audio/version.py +1 -0
- nexaai/binds/metal/py-lib/profiling.py +239 -0
- nexaai/binds/nexaml/libfftw3.3.dylib +0 -0
- nexaai/binds/nexaml/libfftw3f.3.dylib +0 -0
- nexaai/binds/nexaml/libggml-base.dylib +0 -0
- nexaai/binds/nexaml/libggml-cpu.so +0 -0
- nexaai/binds/nexaml/libggml-metal.so +0 -0
- nexaai/binds/nexaml/libggml.dylib +0 -0
- nexaai/binds/nexaml/libmp3lame.0.dylib +0 -0
- nexaai/binds/nexaml/libmpg123.0.dylib +0 -0
- nexaai/binds/nexaml/libnexa-mm-process.dylib +0 -0
- nexaai/binds/nexaml/libnexa-sampling.dylib +0 -0
- nexaai/binds/nexaml/libnexa_plugin.dylib +0 -0
- nexaai/binds/nexaml/libnexaproc.dylib +0 -0
- nexaai/binds/nexaml/libomp.dylib +0 -0
- nexaai/binds/nexaml/libqwen3-vl.dylib +0 -0
- nexaai/binds/nexaml/libqwen3vl-vision.dylib +0 -0
- nexaai/binds/rerank_bind.cpython-310-darwin.so +0 -0
- nexaai/binds/vlm_bind.cpython-310-darwin.so +0 -0
- nexaai/common.py +106 -0
- nexaai/cv.py +95 -0
- nexaai/cv_impl/__init__.py +0 -0
- nexaai/cv_impl/mlx_cv_impl.py +91 -0
- nexaai/cv_impl/pybind_cv_impl.py +124 -0
- nexaai/diarize.py +80 -0
- nexaai/diarize_impl/__init__.py +1 -0
- nexaai/diarize_impl/pybind_diarize_impl.py +125 -0
- nexaai/embedder.py +73 -0
- nexaai/embedder_impl/__init__.py +0 -0
- nexaai/embedder_impl/mlx_embedder_impl.py +118 -0
- nexaai/embedder_impl/pybind_embedder_impl.py +96 -0
- nexaai/image_gen.py +141 -0
- nexaai/image_gen_impl/__init__.py +0 -0
- nexaai/image_gen_impl/mlx_image_gen_impl.py +292 -0
- nexaai/image_gen_impl/pybind_image_gen_impl.py +85 -0
- nexaai/llm.py +98 -0
- nexaai/llm_impl/__init__.py +0 -0
- nexaai/llm_impl/mlx_llm_impl.py +271 -0
- nexaai/llm_impl/pybind_llm_impl.py +238 -0
- nexaai/log.py +92 -0
- nexaai/mlx_backend/asr/__init__.py +12 -0
- nexaai/mlx_backend/asr/interface.py +122 -0
- nexaai/mlx_backend/common/__init__.py +0 -0
- nexaai/mlx_backend/common/utils.py +25 -0
- nexaai/mlx_backend/cv/__init__.py +0 -0
- nexaai/mlx_backend/cv/generate.py +195 -0
- nexaai/mlx_backend/cv/interface.py +162 -0
- nexaai/mlx_backend/cv/main.py +81 -0
- nexaai/mlx_backend/cv/modeling/pp_ocr_v4.py +1736 -0
- nexaai/mlx_backend/embedding/__init__.py +0 -0
- nexaai/mlx_backend/embedding/generate.py +333 -0
- nexaai/mlx_backend/embedding/interface.py +617 -0
- nexaai/mlx_backend/embedding/main.py +173 -0
- nexaai/mlx_backend/embedding/modeling/__init__.py +0 -0
- nexaai/mlx_backend/embedding/modeling/nexa_jina_v2.py +399 -0
- nexaai/mlx_backend/image_gen/__init__.py +1 -0
- nexaai/mlx_backend/image_gen/generate_sd.py +244 -0
- nexaai/mlx_backend/image_gen/interface.py +82 -0
- nexaai/mlx_backend/image_gen/main.py +281 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/__init__.py +306 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/clip.py +116 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/config.py +65 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/model_io.py +386 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/sampler.py +105 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/tokenizer.py +100 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/unet.py +460 -0
- nexaai/mlx_backend/image_gen/stable_diffusion/vae.py +274 -0
- nexaai/mlx_backend/llm/__init__.py +0 -0
- nexaai/mlx_backend/llm/generate.py +149 -0
- nexaai/mlx_backend/llm/interface.py +764 -0
- nexaai/mlx_backend/llm/main.py +68 -0
- nexaai/mlx_backend/ml.py +888 -0
- nexaai/mlx_backend/mlx_audio/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/codec/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/__init__.py +5 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/activation.py +51 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/amp.py +96 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/bigvgan.py +149 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/conv.py +114 -0
- nexaai/mlx_backend/mlx_audio/codec/models/bigvgan/resample.py +177 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/base.py +228 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/dac.py +285 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/nn/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/nn/layers.py +129 -0
- nexaai/mlx_backend/mlx_audio/codec/models/descript/nn/quantize.py +149 -0
- nexaai/mlx_backend/mlx_audio/codec/models/encodec/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/encodec/encodec.py +777 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/mimi.py +286 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/__init__.py +20 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/conv.py +398 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/kv_cache.py +199 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/quantization.py +179 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/seanet.py +314 -0
- nexaai/mlx_backend/mlx_audio/codec/models/mimi/modules/transformer.py +256 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/model.py +260 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/model_v2.py +383 -0
- nexaai/mlx_backend/mlx_audio/codec/models/s3/utils.py +122 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/attention.py +97 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/layers.py +306 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/snac.py +154 -0
- nexaai/mlx_backend/mlx_audio/codec/models/snac/vq.py +135 -0
- nexaai/mlx_backend/mlx_audio/codec/models/vocos/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/codec/models/vocos/mel.py +33 -0
- nexaai/mlx_backend/mlx_audio/codec/models/vocos/vocos.py +359 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_bigvgan.py +54 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_descript.py +109 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_encodec.py +58 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_mimi.py +22 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_s3.py +25 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_snac.py +40 -0
- nexaai/mlx_backend/mlx_audio/codec/tests/test_vocos.py +93 -0
- nexaai/mlx_backend/mlx_audio/server.py +525 -0
- nexaai/mlx_backend/mlx_audio/sts/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/sts/tests/test_voice_pipeline.py +156 -0
- nexaai/mlx_backend/mlx_audio/sts/voice_pipeline.py +327 -0
- nexaai/mlx_backend/mlx_audio/stt/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/stt/generate.py +174 -0
- nexaai/mlx_backend/mlx_audio/stt/models/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/alignment.py +248 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/attention.py +187 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/audio.py +76 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/conformer.py +331 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/ctc.py +34 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/parakeet.py +604 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/rnnt.py +157 -0
- nexaai/mlx_backend/mlx_audio/stt/models/parakeet/tokenizer.py +2 -0
- nexaai/mlx_backend/mlx_audio/stt/models/wav2vec/feature_extractor.py +757 -0
- nexaai/mlx_backend/mlx_audio/stt/models/wav2vec/wav2vec.py +738 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/audio.py +82 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/decoding.py +742 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/timing.py +329 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/tokenizer.py +398 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/whisper.py +862 -0
- nexaai/mlx_backend/mlx_audio/stt/models/whisper/writers.py +268 -0
- nexaai/mlx_backend/mlx_audio/stt/tests/test_models.py +381 -0
- nexaai/mlx_backend/mlx_audio/stt/utils.py +195 -0
- nexaai/mlx_backend/mlx_audio/tts/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/audio_player.py +120 -0
- nexaai/mlx_backend/mlx_audio/tts/convert.py +71 -0
- nexaai/mlx_backend/mlx_audio/tts/generate.py +449 -0
- nexaai/mlx_backend/mlx_audio/tts/models/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/__init__.py +4 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/bark.py +528 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/isftnet.py +12 -0
- nexaai/mlx_backend/mlx_audio/tts/models/bark/pipeline.py +442 -0
- nexaai/mlx_backend/mlx_audio/tts/models/base.py +84 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/audio.py +287 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/config.py +256 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/dia.py +592 -0
- nexaai/mlx_backend/mlx_audio/tts/models/dia/layers.py +870 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/__init__.py +3 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/attention.py +180 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/bigvgan.py +124 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/conformer.py +247 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/asp.py +59 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/ecapa_tdnn.py +91 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/se_res2net.py +132 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/ecapa_tdnn/tdnn.py +42 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/gpt2.py +38 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/indextts.py +412 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/mel.py +37 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/normalize.py +294 -0
- nexaai/mlx_backend/mlx_audio/tts/models/indextts/perceiver.py +62 -0
- nexaai/mlx_backend/mlx_audio/tts/models/interpolate.py +108 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/__init__.py +4 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/istftnet.py +979 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/kokoro.py +331 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/modules.py +659 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/pipeline.py +453 -0
- nexaai/mlx_backend/mlx_audio/tts/models/kokoro/voice.py +113 -0
- nexaai/mlx_backend/mlx_audio/tts/models/llama/__init__.py +3 -0
- nexaai/mlx_backend/mlx_audio/tts/models/llama/llama.py +324 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/audio_processor.py +351 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/dac_interface.py +162 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/default_speaker.json +461 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/outetts.py +255 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/prompt_processor.py +181 -0
- nexaai/mlx_backend/mlx_audio/tts/models/outetts/tokens.py +36 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/__init__.py +3 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/attention.py +195 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/sesame.py +633 -0
- nexaai/mlx_backend/mlx_audio/tts/models/sesame/watermarking.py +105 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/audio_tokenizer.py +138 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/bicodec.py +269 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/blocks/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/blocks/sampler.py +111 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_decoder.py +120 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/feat_encoder.py +136 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/encoder_decoder/wave_generator.py +113 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/finite_scalar_quantization.py +238 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/residual.py +209 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/residual_fsq.py +309 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/__init__.py +1 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/ecapa_tdnn.py +283 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/perceiver_encoder.py +326 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/pooling_layers.py +297 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/modules/speaker/speaker_encoder.py +155 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/spark.py +382 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/utils/audio.py +220 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/utils/file.py +221 -0
- nexaai/mlx_backend/mlx_audio/tts/models/spark/utils/token_parser.py +181 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/__init__.py +0 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_base.py +66 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_convert.py +173 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_interpolate.py +88 -0
- nexaai/mlx_backend/mlx_audio/tts/tests/test_models.py +974 -0
- nexaai/mlx_backend/mlx_audio/tts/utils.py +337 -0
- nexaai/mlx_backend/mlx_audio/utils.py +237 -0
- nexaai/mlx_backend/mlx_audio/version.py +1 -0
- nexaai/mlx_backend/profiling.py +239 -0
- nexaai/mlx_backend/rerank/__init__.py +0 -0
- nexaai/mlx_backend/rerank/generate.py +174 -0
- nexaai/mlx_backend/rerank/interface.py +287 -0
- nexaai/mlx_backend/rerank/main.py +127 -0
- nexaai/mlx_backend/rerank/modeling/__init__.py +0 -0
- nexaai/mlx_backend/rerank/modeling/nexa_jina_rerank.py +330 -0
- nexaai/mlx_backend/sd/__init__.py +1 -0
- nexaai/mlx_backend/sd/interface.py +362 -0
- nexaai/mlx_backend/sd/main.py +286 -0
- nexaai/mlx_backend/sd/modeling/__init__.py +306 -0
- nexaai/mlx_backend/sd/modeling/clip.py +116 -0
- nexaai/mlx_backend/sd/modeling/config.py +65 -0
- nexaai/mlx_backend/sd/modeling/model_io.py +385 -0
- nexaai/mlx_backend/sd/modeling/sampler.py +105 -0
- nexaai/mlx_backend/sd/modeling/tokenizer.py +100 -0
- nexaai/mlx_backend/sd/modeling/unet.py +460 -0
- nexaai/mlx_backend/sd/modeling/vae.py +274 -0
- nexaai/mlx_backend/tts/__init__.py +12 -0
- nexaai/mlx_backend/tts/interface.py +276 -0
- nexaai/mlx_backend/vlm/__init__.py +3 -0
- nexaai/mlx_backend/vlm/generate.py +572 -0
- nexaai/mlx_backend/vlm/generate_qwen3_vl.py +374 -0
- nexaai/mlx_backend/vlm/generate_qwen3_vl_moe.py +259 -0
- nexaai/mlx_backend/vlm/interface.py +559 -0
- nexaai/mlx_backend/vlm/main.py +365 -0
- nexaai/mlx_backend/vlm/modeling/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/convert.py +68 -0
- nexaai/mlx_backend/vlm/modeling/models/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/aya_vision.py +193 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/interpolate.py +186 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/language.py +233 -0
- nexaai/mlx_backend/vlm/modeling/models/aya_vision/vision.py +503 -0
- nexaai/mlx_backend/vlm/modeling/models/base.py +202 -0
- nexaai/mlx_backend/vlm/modeling/models/cache.py +230 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/__init__.py +10 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/conversation.py +264 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/deepseek_vl_v2.py +472 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/language.py +591 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/processing_deepsek_vl_v2.py +526 -0
- nexaai/mlx_backend/vlm/modeling/models/deepseek_vl_v2/vision.py +356 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/florence2.py +366 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/language.py +488 -0
- nexaai/mlx_backend/vlm/modeling/models/florence2/vision.py +591 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/gemma3.py +213 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/language.py +315 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3/vision.py +238 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/__init__.py +2 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/audio.py +1038 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/config.py +139 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/gemma3n.py +322 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/language.py +629 -0
- nexaai/mlx_backend/vlm/modeling/models/gemma3n/vision.py +1022 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/idefics2.py +294 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/language.py +191 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics2/vision.py +267 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/idefics3.py +175 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/language.py +192 -0
- nexaai/mlx_backend/vlm/modeling/models/idefics3/vision.py +233 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/internvl_chat.py +140 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/language.py +220 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/processor.py +393 -0
- nexaai/mlx_backend/vlm/modeling/models/internvl_chat/vision.py +293 -0
- nexaai/mlx_backend/vlm/modeling/models/kernels.py +307 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/kimi_vl.py +143 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/language.py +509 -0
- nexaai/mlx_backend/vlm/modeling/models/kimi_vl/vision.py +522 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/language.py +386 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/llama4.py +138 -0
- nexaai/mlx_backend/vlm/modeling/models/llama4/vision.py +560 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/language.py +240 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/llava.py +153 -0
- nexaai/mlx_backend/vlm/modeling/models/llava/vision.py +259 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/language.py +236 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/llava_bunny.py +256 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_bunny/vision.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/language.py +230 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/llava_next.py +160 -0
- nexaai/mlx_backend/vlm/modeling/models/llava_next/vision.py +243 -0
- nexaai/mlx_backend/vlm/modeling/models/mistral3/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/mistral3/mistral3.py +283 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/language.py +416 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/mllama.py +172 -0
- nexaai/mlx_backend/vlm/modeling/models/mllama/vision.py +499 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/language.py +243 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/molmo.py +133 -0
- nexaai/mlx_backend/vlm/modeling/models/molmo/vision.py +465 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/__init__.py +10 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/language.py +230 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/multi_modality.py +385 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/sam.py +557 -0
- nexaai/mlx_backend/vlm/modeling/models/multi_modality/vision.py +526 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/language.py +282 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/paligemma.py +160 -0
- nexaai/mlx_backend/vlm/modeling/models/paligemma/vision.py +242 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/language.py +21 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/phi3_v.py +243 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/su_rope.py +71 -0
- nexaai/mlx_backend/vlm/modeling/models/phi3_v/vision.py +324 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/language.py +229 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/pixtral.py +161 -0
- nexaai/mlx_backend/vlm/modeling/models/pixtral/vision.py +320 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/__init__.py +2 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/config.py +108 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/language.py +490 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/qwen2_5_vl.py +168 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_5_vl/vision.py +414 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/__init__.py +2 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/config.py +104 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/language.py +490 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/qwen2_vl.py +167 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen2_vl/vision.py +312 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/base.py +117 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/cache.py +531 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/generate.py +701 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/rope_utils.py +255 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/sample_utils.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/llm_common/tokenizer_utils.py +407 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/processor.py +476 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3_vl/qwen3vl.py +1262 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/base.py +117 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/cache.py +531 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/generate.py +701 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/rope_utils.py +255 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/sample_utils.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/tokenizer_utils.py +407 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/processor.py +476 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/qwen3vl_moe.py +1308 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/switch_layers.py +210 -0
- nexaai/mlx_backend/vlm/modeling/models/smolvlm/__init__.py +8 -0
- nexaai/mlx_backend/vlm/modeling/models/smolvlm/smolvlm.py +62 -0
- nexaai/mlx_backend/vlm/modeling/processing_qwen2_5_vl.py +209 -0
- nexaai/mlx_backend/vlm/modeling/processing_qwen2_vl.py +215 -0
- nexaai/mlx_backend/vlm/modeling/prompt_utils.py +474 -0
- nexaai/mlx_backend/vlm/modeling/sample_utils.py +39 -0
- nexaai/mlx_backend/vlm/modeling/tokenizer_utils.py +344 -0
- nexaai/mlx_backend/vlm/modeling/trainer/__init__.py +9 -0
- nexaai/mlx_backend/vlm/modeling/trainer/lora.py +70 -0
- nexaai/mlx_backend/vlm/modeling/trainer/trainer.py +296 -0
- nexaai/mlx_backend/vlm/modeling/trainer/utils.py +160 -0
- nexaai/mlx_backend/vlm/modeling/utils.py +928 -0
- nexaai/rerank.py +57 -0
- nexaai/rerank_impl/__init__.py +0 -0
- nexaai/rerank_impl/mlx_rerank_impl.py +94 -0
- nexaai/rerank_impl/pybind_rerank_impl.py +136 -0
- nexaai/runtime.py +68 -0
- nexaai/runtime_error.py +24 -0
- nexaai/tts.py +75 -0
- nexaai/tts_impl/__init__.py +0 -0
- nexaai/tts_impl/mlx_tts_impl.py +94 -0
- nexaai/tts_impl/pybind_tts_impl.py +43 -0
- nexaai/utils/decode.py +18 -0
- nexaai/utils/manifest_utils.py +531 -0
- nexaai/utils/model_manager.py +1745 -0
- nexaai/utils/model_types.py +49 -0
- nexaai/utils/progress_tracker.py +389 -0
- nexaai/utils/quantization_utils.py +245 -0
- nexaai/vlm.py +130 -0
- nexaai/vlm_impl/__init__.py +0 -0
- nexaai/vlm_impl/mlx_vlm_impl.py +259 -0
- nexaai/vlm_impl/pybind_vlm_impl.py +275 -0
- nexaai-1.0.29.dist-info/METADATA +35 -0
- nexaai-1.0.29.dist-info/RECORD +580 -0
- nexaai-1.0.29.dist-info/WHEEL +5 -0
- nexaai-1.0.29.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
import mlx.core as mx
|
|
6
|
+
from mlx_lm.generate import stream_generate
|
|
7
|
+
from mlx_lm.models.llama import Model as LlamaModel
|
|
8
|
+
from mlx_lm.models.llama import ModelArgs as LlamaModelConfig
|
|
9
|
+
from mlx_lm.sample_utils import make_logits_processors, make_sampler
|
|
10
|
+
from tqdm import tqdm
|
|
11
|
+
from transformers import AutoTokenizer
|
|
12
|
+
|
|
13
|
+
from mlx_audio.codec.models.snac import SNAC
|
|
14
|
+
|
|
15
|
+
from ..base import GenerationResult
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class ModelConfig(LlamaModelConfig):
|
|
20
|
+
tokenizer_name: str = "mlx-community/orpheus-3b-0.1-ft-bf16"
|
|
21
|
+
sample_rate: int = 24000
|
|
22
|
+
|
|
23
|
+
def __post_init__(self):
|
|
24
|
+
if self.num_key_value_heads is None:
|
|
25
|
+
self.num_key_value_heads = self.num_attention_heads
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
snac_model = SNAC.from_pretrained("mlx-community/snac_24khz").eval()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def decode_audio_from_codes(code_list):
|
|
32
|
+
layer_1 = []
|
|
33
|
+
layer_2 = []
|
|
34
|
+
layer_3 = []
|
|
35
|
+
for i in range((len(code_list) + 1) // 7):
|
|
36
|
+
layer_1.append(code_list[7 * i])
|
|
37
|
+
layer_2.append(code_list[7 * i + 1] - 4096)
|
|
38
|
+
layer_3.append(code_list[7 * i + 2] - (2 * 4096))
|
|
39
|
+
layer_3.append(code_list[7 * i + 3] - (3 * 4096))
|
|
40
|
+
layer_2.append(code_list[7 * i + 4] - (4 * 4096))
|
|
41
|
+
layer_3.append(code_list[7 * i + 5] - (5 * 4096))
|
|
42
|
+
layer_3.append(code_list[7 * i + 6] - (6 * 4096))
|
|
43
|
+
codes = [
|
|
44
|
+
mx.expand_dims(mx.array(layer_1), 0),
|
|
45
|
+
mx.expand_dims(mx.array(layer_2), 0),
|
|
46
|
+
mx.expand_dims(mx.array(layer_3), 0),
|
|
47
|
+
]
|
|
48
|
+
audio_hat = snac_model.decode(codes).squeeze(-1)
|
|
49
|
+
return audio_hat
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def encode_audio_to_codes(audio):
|
|
53
|
+
audio = audio[None, None, :]
|
|
54
|
+
|
|
55
|
+
codes = snac_model.encode(audio)
|
|
56
|
+
|
|
57
|
+
layer_1 = codes[0].squeeze(0).tolist()
|
|
58
|
+
layer_2 = codes[1].squeeze(0).tolist()
|
|
59
|
+
layer_3 = codes[2].squeeze(0).tolist()
|
|
60
|
+
|
|
61
|
+
code_list = []
|
|
62
|
+
num_groups = len(layer_1)
|
|
63
|
+
for i in range(num_groups):
|
|
64
|
+
code_list.append(layer_1[i])
|
|
65
|
+
code_list.append(layer_2[2 * i] + 4096)
|
|
66
|
+
code_list.append(layer_3[4 * i] + 2 * 4096)
|
|
67
|
+
code_list.append(layer_3[4 * i + 1] + 3 * 4096)
|
|
68
|
+
code_list.append(layer_2[2 * i + 1] + 4 * 4096)
|
|
69
|
+
code_list.append(layer_3[4 * i + 2] + 5 * 4096)
|
|
70
|
+
code_list.append(layer_3[4 * i + 3] + 6 * 4096)
|
|
71
|
+
|
|
72
|
+
return mx.array(code_list)[None, :]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Model(LlamaModel):
|
|
76
|
+
def __init__(self, config: ModelConfig, **kwargs):
|
|
77
|
+
super().__init__(config)
|
|
78
|
+
self.config = config
|
|
79
|
+
self.model_type = config.model_type
|
|
80
|
+
self.tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name)
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def layers(self):
|
|
84
|
+
return self.model.layers
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def sample_rate(self):
|
|
88
|
+
return self.config.sample_rate
|
|
89
|
+
|
|
90
|
+
def parse_output(self, input_ids):
|
|
91
|
+
token_to_find = 128257
|
|
92
|
+
token_to_remove = 128258
|
|
93
|
+
|
|
94
|
+
# MLX doesn't have nonzero, so we need to create indices manually
|
|
95
|
+
mask = input_ids == token_to_find
|
|
96
|
+
indices = []
|
|
97
|
+
for i in range(mask.shape[0]):
|
|
98
|
+
for j in range(mask.shape[1]):
|
|
99
|
+
if mask[i, j]:
|
|
100
|
+
indices.append((i, j))
|
|
101
|
+
token_indices = [[], []]
|
|
102
|
+
for i, j in indices:
|
|
103
|
+
token_indices[0].append(i)
|
|
104
|
+
token_indices[1].append(j)
|
|
105
|
+
|
|
106
|
+
token_indices = mx.array(token_indices)
|
|
107
|
+
|
|
108
|
+
if len(token_indices[1]) > 0:
|
|
109
|
+
last_occurrence_idx = int(token_indices[1][-1])
|
|
110
|
+
cropped_tensor = input_ids[:, last_occurrence_idx + 1 :]
|
|
111
|
+
else:
|
|
112
|
+
cropped_tensor = input_ids
|
|
113
|
+
|
|
114
|
+
mask = cropped_tensor != token_to_remove
|
|
115
|
+
|
|
116
|
+
processed_rows = []
|
|
117
|
+
|
|
118
|
+
for row in cropped_tensor:
|
|
119
|
+
# Create a mask and filter manually since boolean indexing isn't supported
|
|
120
|
+
row_list = row.tolist()
|
|
121
|
+
masked_row = mx.array([val for val in row_list if val != token_to_remove])
|
|
122
|
+
processed_rows.append(masked_row)
|
|
123
|
+
|
|
124
|
+
code_lists = []
|
|
125
|
+
|
|
126
|
+
for row in processed_rows:
|
|
127
|
+
row_length = row.shape[0]
|
|
128
|
+
new_length = (row_length // 7) * 7
|
|
129
|
+
trimmed_row = row[:new_length]
|
|
130
|
+
trimmed_row = [t - 128266 for t in trimmed_row]
|
|
131
|
+
code_lists.append(trimmed_row)
|
|
132
|
+
|
|
133
|
+
return code_lists
|
|
134
|
+
|
|
135
|
+
def prepare_input_ids(
|
|
136
|
+
self,
|
|
137
|
+
prompts: List[str],
|
|
138
|
+
voice: Optional[str] = None,
|
|
139
|
+
ref_audio: Optional[mx.array] = None,
|
|
140
|
+
ref_text: Optional[str] = None,
|
|
141
|
+
):
|
|
142
|
+
audio_input_ids = None
|
|
143
|
+
if ref_audio is not None and ref_text is not None:
|
|
144
|
+
print(
|
|
145
|
+
"\033[93mWARNING: Audio cloning doesn't work reliably on Orpheus.\033[0m \nA known issue affecting Torch and MLX versions. \nWill be fixed once the Canopy labs repo update their code or the model."
|
|
146
|
+
)
|
|
147
|
+
audio_input_ids = encode_audio_to_codes(ref_audio) + 128266
|
|
148
|
+
audio_transcript_ids = self.tokenizer(
|
|
149
|
+
ref_text, return_tensors="mlx"
|
|
150
|
+
).input_ids
|
|
151
|
+
elif voice is not None:
|
|
152
|
+
prompts = [f"{voice}: " + p for p in prompts]
|
|
153
|
+
|
|
154
|
+
start_token = mx.array([[128259]], dtype=mx.int64) # Start of human
|
|
155
|
+
end_tokens = mx.array(
|
|
156
|
+
[[128009, 128260]], dtype=mx.int64
|
|
157
|
+
) # End of text, End of human
|
|
158
|
+
|
|
159
|
+
prompt_input_ids = []
|
|
160
|
+
for prompt in prompts:
|
|
161
|
+
prompt_input_ids.append(
|
|
162
|
+
self.tokenizer(prompt, return_tensors="mlx").input_ids
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
batch_input_ids = []
|
|
166
|
+
pad_token = mx.array([128263], dtype=mx.int64)
|
|
167
|
+
max_len = max([p.shape[1] for p in prompt_input_ids])
|
|
168
|
+
|
|
169
|
+
for input_ids in prompt_input_ids:
|
|
170
|
+
modified_input_ids = []
|
|
171
|
+
|
|
172
|
+
padding_len = max_len - input_ids.shape[1]
|
|
173
|
+
if padding_len > 0:
|
|
174
|
+
modified_input_ids.append(mx.repeat(pad_token, padding_len)[None, :])
|
|
175
|
+
|
|
176
|
+
# reference audio and transcript
|
|
177
|
+
if audio_input_ids is not None:
|
|
178
|
+
audio_start_tokens = mx.array([[128261, 128257]], dtype=mx.int64)
|
|
179
|
+
audio_end_tokens = mx.array([[128258, 128262]], dtype=mx.int64)
|
|
180
|
+
ref_input_ids = mx.concatenate(
|
|
181
|
+
[
|
|
182
|
+
start_token,
|
|
183
|
+
audio_transcript_ids,
|
|
184
|
+
end_tokens,
|
|
185
|
+
audio_start_tokens,
|
|
186
|
+
audio_input_ids,
|
|
187
|
+
audio_end_tokens,
|
|
188
|
+
],
|
|
189
|
+
axis=1,
|
|
190
|
+
)
|
|
191
|
+
modified_input_ids.append(ref_input_ids)
|
|
192
|
+
|
|
193
|
+
# prompt
|
|
194
|
+
one_prompt_input_ids = mx.concatenate(
|
|
195
|
+
[start_token, input_ids, end_tokens], axis=1
|
|
196
|
+
) # SOH SOT Text EOT EOH
|
|
197
|
+
modified_input_ids.append(one_prompt_input_ids)
|
|
198
|
+
|
|
199
|
+
batch_input_ids.append(mx.concatenate(modified_input_ids, axis=1))
|
|
200
|
+
|
|
201
|
+
batch_input_ids = mx.concatenate(batch_input_ids, axis=0)
|
|
202
|
+
batch_mask = mx.where(batch_input_ids == pad_token, False, True)
|
|
203
|
+
|
|
204
|
+
return batch_input_ids, batch_mask
|
|
205
|
+
|
|
206
|
+
def generate(
|
|
207
|
+
self,
|
|
208
|
+
text,
|
|
209
|
+
voice: str,
|
|
210
|
+
temperature: float = 0.6,
|
|
211
|
+
top_p: float = 0.8,
|
|
212
|
+
split_pattern: str = "\n",
|
|
213
|
+
max_tokens: int = 1200,
|
|
214
|
+
verbose: bool = False,
|
|
215
|
+
ref_audio: mx.array = None,
|
|
216
|
+
ref_text: Optional[str] = None,
|
|
217
|
+
**kwargs,
|
|
218
|
+
):
|
|
219
|
+
prompt = text.replace("\\n", "\n").replace("\\t", "\t")
|
|
220
|
+
prompts = prompt.split(split_pattern)
|
|
221
|
+
|
|
222
|
+
input_ids, _ = self.prepare_input_ids(
|
|
223
|
+
prompts,
|
|
224
|
+
voice,
|
|
225
|
+
ref_audio,
|
|
226
|
+
ref_text,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
sampler = make_sampler(temperature, top_p, top_k=kwargs.get("top_k", -1))
|
|
230
|
+
logits_processors = make_logits_processors(
|
|
231
|
+
kwargs.get("logit_bias", None),
|
|
232
|
+
kwargs.get("repetition_penalty", 1.3),
|
|
233
|
+
kwargs.get("repetition_context_size", 20),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
time_start = time.time()
|
|
237
|
+
# TODO: Support batch processing as in the Colab: https://github.com/canopyai/Orpheus-TTS
|
|
238
|
+
for i, response in enumerate(
|
|
239
|
+
tqdm(
|
|
240
|
+
stream_generate(
|
|
241
|
+
self,
|
|
242
|
+
tokenizer=self.tokenizer,
|
|
243
|
+
prompt=input_ids.squeeze(0),
|
|
244
|
+
max_tokens=max_tokens,
|
|
245
|
+
sampler=sampler,
|
|
246
|
+
logits_processors=logits_processors,
|
|
247
|
+
),
|
|
248
|
+
total=max_tokens,
|
|
249
|
+
disable=not verbose,
|
|
250
|
+
)
|
|
251
|
+
):
|
|
252
|
+
next_token = mx.array([response.token])
|
|
253
|
+
input_ids = mx.concatenate([input_ids, next_token[None, :]], axis=1)
|
|
254
|
+
if i % 50 == 0:
|
|
255
|
+
mx.clear_cache()
|
|
256
|
+
|
|
257
|
+
if next_token == 128258:
|
|
258
|
+
break
|
|
259
|
+
|
|
260
|
+
code_lists = self.parse_output(input_ids)
|
|
261
|
+
|
|
262
|
+
my_samples = []
|
|
263
|
+
for code_list in code_lists:
|
|
264
|
+
samples = decode_audio_from_codes(code_list)
|
|
265
|
+
my_samples.append(samples)
|
|
266
|
+
|
|
267
|
+
time_end = time.time()
|
|
268
|
+
|
|
269
|
+
if len(prompts) != len(my_samples):
|
|
270
|
+
raise Exception("Number of prompts and samples do not match")
|
|
271
|
+
else:
|
|
272
|
+
for i in range(len(my_samples)):
|
|
273
|
+
audio = my_samples[i][0]
|
|
274
|
+
|
|
275
|
+
samples = audio.shape[0] if audio is not None else 0
|
|
276
|
+
assert samples > 0, "No audio generated"
|
|
277
|
+
|
|
278
|
+
# Calculate token count
|
|
279
|
+
token_count = input_ids.shape[1] if input_ids is not None else 0
|
|
280
|
+
|
|
281
|
+
# Calculate audio duration in seconds
|
|
282
|
+
sample_rate = self.config.sample_rate
|
|
283
|
+
audio_duration_seconds = samples / sample_rate
|
|
284
|
+
|
|
285
|
+
# Calculate real-time factor (RTF)
|
|
286
|
+
rtf = audio_duration_seconds / (time_end - time_start)
|
|
287
|
+
|
|
288
|
+
# Format duration as HH:MM:SS.mmm
|
|
289
|
+
duration_mins = int(audio_duration_seconds // 60)
|
|
290
|
+
duration_secs = int(audio_duration_seconds % 60)
|
|
291
|
+
duration_ms = int((audio_duration_seconds % 1) * 1000)
|
|
292
|
+
duration_hours = int(audio_duration_seconds // 3600)
|
|
293
|
+
duration_str = f"{duration_hours:02d}:{duration_mins:02d}:{duration_secs:02d}.{duration_ms:03d}"
|
|
294
|
+
|
|
295
|
+
yield GenerationResult(
|
|
296
|
+
audio=audio,
|
|
297
|
+
samples=samples,
|
|
298
|
+
sample_rate=sample_rate,
|
|
299
|
+
segment_idx=i,
|
|
300
|
+
token_count=token_count,
|
|
301
|
+
audio_duration=duration_str,
|
|
302
|
+
real_time_factor=rtf,
|
|
303
|
+
prompt={
|
|
304
|
+
"tokens": token_count,
|
|
305
|
+
"tokens-per-sec": (
|
|
306
|
+
round(token_count / audio_duration_seconds, 2)
|
|
307
|
+
if audio_duration_seconds > 0
|
|
308
|
+
else 0
|
|
309
|
+
),
|
|
310
|
+
},
|
|
311
|
+
audio_samples={
|
|
312
|
+
"samples": samples,
|
|
313
|
+
"samples-per-sec": (
|
|
314
|
+
round(samples / audio_duration_seconds, 2)
|
|
315
|
+
if audio_duration_seconds > 0
|
|
316
|
+
else 0
|
|
317
|
+
),
|
|
318
|
+
},
|
|
319
|
+
processing_time_seconds=time_end - time_start,
|
|
320
|
+
peak_memory_usage=mx.get_peak_memory() / 1e9,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
# Clear cache after each segment to avoid memory leaks
|
|
324
|
+
mx.clear_cache()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .outetts import Model, ModelConfig
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from dataclasses import asdict
|
|
5
|
+
from typing import Union
|
|
6
|
+
|
|
7
|
+
import mlx.core as mx
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from mlx_audio.stt.utils import SAMPLE_RATE as WHISPER_SAMPLE_RATE
|
|
11
|
+
from mlx_audio.stt.utils import load_model, resample_audio
|
|
12
|
+
|
|
13
|
+
from .dac_interface import DacInterface
|
|
14
|
+
from .prompt_processor import PromptProcessor
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def calculate_pitch(
|
|
18
|
+
audio_array: mx.array,
|
|
19
|
+
sr: int,
|
|
20
|
+
min_freq: float = 75.0,
|
|
21
|
+
max_freq: float = 600.0,
|
|
22
|
+
frame_length: int = 400,
|
|
23
|
+
hop_length: int = 160,
|
|
24
|
+
threshold: float = 0.3,
|
|
25
|
+
) -> mx.array:
|
|
26
|
+
"""
|
|
27
|
+
Calculate pitch frequencies for short audio clips using autocorrelation.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
audio_array: Input audio array (1D or 2D [channels, samples])
|
|
31
|
+
sr: Sampling rate
|
|
32
|
+
min_freq: Minimum detectable frequency (Hz)
|
|
33
|
+
max_freq: Maximum detectable frequency (Hz)
|
|
34
|
+
frame_length: Analysis frame length in samples
|
|
35
|
+
hop_length: Hop size in samples
|
|
36
|
+
threshold: Voicing threshold (0.0-1.0)
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Array of pitch values (Hz) per frame
|
|
40
|
+
"""
|
|
41
|
+
audio_np = np.array(audio_array)
|
|
42
|
+
|
|
43
|
+
# convert to mono and ensure 1D
|
|
44
|
+
if len(audio_np.shape) > 1:
|
|
45
|
+
audio_np = np.mean(audio_np, axis=0)
|
|
46
|
+
audio_np = np.squeeze(audio_np)
|
|
47
|
+
|
|
48
|
+
num_samples = audio_np.shape[-1]
|
|
49
|
+
pad_len = (frame_length - (num_samples % hop_length)) % hop_length
|
|
50
|
+
audio_np = np.pad(audio_np, (0, pad_len))
|
|
51
|
+
|
|
52
|
+
num_frames = (len(audio_np) - frame_length) // hop_length + 1
|
|
53
|
+
frames = np.zeros((num_frames, frame_length))
|
|
54
|
+
for i in range(num_frames):
|
|
55
|
+
frames[i] = audio_np[i * hop_length : i * hop_length + frame_length]
|
|
56
|
+
|
|
57
|
+
window = np.hanning(frame_length)
|
|
58
|
+
frames_windowed = frames * window
|
|
59
|
+
|
|
60
|
+
# compute autocorrelation using FFT
|
|
61
|
+
fft_frames = np.fft.rfft(frames_windowed, n=2 * frame_length, axis=1)
|
|
62
|
+
power_spectrum = fft_frames.real**2 + fft_frames.imag**2
|
|
63
|
+
autocorr = np.fft.irfft(power_spectrum, axis=1)[:, :frame_length]
|
|
64
|
+
|
|
65
|
+
# find valid frequency range indices
|
|
66
|
+
min_idx = max(1, int(sr / max_freq))
|
|
67
|
+
max_idx = min(frame_length, int(sr / min_freq))
|
|
68
|
+
|
|
69
|
+
# find peak indices in valid range
|
|
70
|
+
relevant_autocorr = autocorr[:, min_idx:max_idx]
|
|
71
|
+
peak_indices = np.argmax(relevant_autocorr, axis=1) + min_idx
|
|
72
|
+
peak_values = np.array([autocorr[i, peak_indices[i]] for i in range(num_frames)])
|
|
73
|
+
|
|
74
|
+
# parabolic interpolation for sub-sample accuracy
|
|
75
|
+
indices = np.clip(peak_indices, 1, frame_length - 2)
|
|
76
|
+
alpha = np.array([autocorr[i, indices[i] - 1] for i in range(num_frames)])
|
|
77
|
+
beta = np.array([autocorr[i, indices[i]] for i in range(num_frames)])
|
|
78
|
+
gamma = np.array([autocorr[i, indices[i] + 1] for i in range(num_frames)])
|
|
79
|
+
|
|
80
|
+
delta = 0.5 * (alpha - gamma) / (alpha - 2 * beta + gamma + 1e-8)
|
|
81
|
+
valid_mask = (peak_indices > 0) & (peak_indices < frame_length - 1)
|
|
82
|
+
delta = np.where(valid_mask, delta, 0.0)
|
|
83
|
+
|
|
84
|
+
# calculate final periods and pitches
|
|
85
|
+
best_period = (peak_indices + delta) / sr
|
|
86
|
+
pitch = np.where(best_period > 0, 1.0 / best_period, 0.0)
|
|
87
|
+
|
|
88
|
+
# apply voicing threshold
|
|
89
|
+
autocorr_0 = autocorr[:, 0]
|
|
90
|
+
voiced = (peak_values / (autocorr_0 + 1e-8)) > threshold
|
|
91
|
+
pitch = np.where(voiced, pitch, 0.0)
|
|
92
|
+
|
|
93
|
+
# clamp valid frequencies
|
|
94
|
+
pitch = np.clip(pitch, min_freq, max_freq)
|
|
95
|
+
|
|
96
|
+
return mx.array(pitch)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def extract_single_pitch_value(
|
|
100
|
+
audio_array: mx.array,
|
|
101
|
+
sr: int,
|
|
102
|
+
min_freq: float = 75.0,
|
|
103
|
+
max_freq: float = 600.0,
|
|
104
|
+
frame_length: int = 400,
|
|
105
|
+
hop_length: int = 160,
|
|
106
|
+
threshold: float = 0.3,
|
|
107
|
+
) -> float:
|
|
108
|
+
"""
|
|
109
|
+
Calculates the average pitch of an audio array and normalizes it to 0-1 range.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
audio_array: Input audio array (1D or 2D [channels, samples])
|
|
113
|
+
sr: Sampling rate
|
|
114
|
+
min_freq: Minimum detectable frequency (Hz)
|
|
115
|
+
max_freq: Maximum detectable frequency (Hz)
|
|
116
|
+
frame_length: Analysis frame length in samples
|
|
117
|
+
hop_length: Hop size in samples
|
|
118
|
+
threshold: Voicing threshold (0.0-1.0)
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
A single float value representing the normalized average pitch (0.0-1.0).
|
|
122
|
+
"""
|
|
123
|
+
pitch_array = calculate_pitch(
|
|
124
|
+
audio_array, sr, min_freq, max_freq, frame_length, hop_length, threshold
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# calculate the average pitch across frames
|
|
128
|
+
average_pitch = float(mx.mean(pitch_array))
|
|
129
|
+
|
|
130
|
+
# normalize to 0-1 range
|
|
131
|
+
normalized_pitch = (average_pitch - min_freq) / (max_freq - min_freq)
|
|
132
|
+
|
|
133
|
+
# clamp to ensure it's strictly within 0-1
|
|
134
|
+
normalized_pitch = min(max(normalized_pitch, 0.0), 1.0)
|
|
135
|
+
|
|
136
|
+
return normalized_pitch
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class Features:
|
|
140
|
+
def __init__(self):
|
|
141
|
+
self.eps = 1e-10
|
|
142
|
+
|
|
143
|
+
def scale_values(self, value: float) -> int:
|
|
144
|
+
"""
|
|
145
|
+
Scale a value from [0,1] to [0,100] and round to nearest integer
|
|
146
|
+
"""
|
|
147
|
+
return round(value * 100)
|
|
148
|
+
|
|
149
|
+
def features_to_tokens(self, features: dict) -> list:
|
|
150
|
+
"""
|
|
151
|
+
Convert features to token strings in format <|feature_value|>
|
|
152
|
+
"""
|
|
153
|
+
return [f"<|{name}_{value}|>" for name, value in features.items()]
|
|
154
|
+
|
|
155
|
+
def validate_audio(self, audio: mx.array) -> bool:
|
|
156
|
+
if audio is None or not isinstance(audio, mx.array):
|
|
157
|
+
return False
|
|
158
|
+
if audio.size == 0: # Check if array is empty
|
|
159
|
+
return False
|
|
160
|
+
audio_np = np.array(audio)
|
|
161
|
+
if np.isnan(audio_np).any() or np.isinf(audio_np).any():
|
|
162
|
+
return False
|
|
163
|
+
return True
|
|
164
|
+
|
|
165
|
+
def get_default_features(self) -> dict:
|
|
166
|
+
"""
|
|
167
|
+
Return default feature values when audio is invalid
|
|
168
|
+
"""
|
|
169
|
+
return {"energy": 0, "spectral_centroid": 0, "pitch": 0}
|
|
170
|
+
|
|
171
|
+
def extract_audio_features(self, audio: mx.array, sr: int) -> dict:
|
|
172
|
+
"""
|
|
173
|
+
Extract fast-to-compute features from audio segments.
|
|
174
|
+
Each feature is normalized to [0, 1] range.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
audio: Audio array of shape [channels, samples]
|
|
178
|
+
sr: Sample rate
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
Dictionary of features, each as a single float value
|
|
182
|
+
"""
|
|
183
|
+
if not self.validate_audio(audio):
|
|
184
|
+
return self.get_default_features()
|
|
185
|
+
|
|
186
|
+
audio_np = np.array(audio)
|
|
187
|
+
|
|
188
|
+
# convert to mono if stereo
|
|
189
|
+
if len(audio_np.shape) == 2 and audio_np.shape[0] > 1:
|
|
190
|
+
audio_np = np.mean(audio_np, axis=0, keepdims=True)
|
|
191
|
+
|
|
192
|
+
audio = mx.array(audio_np)
|
|
193
|
+
|
|
194
|
+
features = {}
|
|
195
|
+
|
|
196
|
+
# rms energy (loudness) - normalized to [0, 1]
|
|
197
|
+
features["energy"] = float(mx.sqrt(mx.mean(audio**2)))
|
|
198
|
+
|
|
199
|
+
# spectral centroid - normalized to [0, 1]
|
|
200
|
+
spec_np = np.abs(np.fft.rfft(audio_np))
|
|
201
|
+
freqs_np = np.linspace(0, sr / 2, spec_np.shape[-1])
|
|
202
|
+
spec_sum = np.sum(spec_np) + self.eps
|
|
203
|
+
centroid = np.sum(freqs_np * spec_np.squeeze()) / spec_sum
|
|
204
|
+
features["spectral_centroid"] = float(centroid / (sr / 2))
|
|
205
|
+
|
|
206
|
+
# pitch - normalized to [0, 1]
|
|
207
|
+
features["pitch"] = extract_single_pitch_value(audio, sr)
|
|
208
|
+
|
|
209
|
+
# scale values to 0-100 range
|
|
210
|
+
for name, value in features.items():
|
|
211
|
+
features[name] = self.scale_values(value)
|
|
212
|
+
|
|
213
|
+
return features
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class AudioProcessor:
|
|
217
|
+
def __init__(
|
|
218
|
+
self, audio_codec_path: str = "mlx-community/dac-speech-24khz-1.5kbps"
|
|
219
|
+
):
|
|
220
|
+
self.features = Features()
|
|
221
|
+
self.audio_codec = DacInterface(audio_codec_path)
|
|
222
|
+
|
|
223
|
+
def create_speaker_from_whisper(
|
|
224
|
+
self,
|
|
225
|
+
audio: str,
|
|
226
|
+
whisper_model: str = "mlx-community/whisper-large-v3-turbo",
|
|
227
|
+
):
|
|
228
|
+
if isinstance(audio, str):
|
|
229
|
+
audio = self.audio_codec.load_audio(audio)
|
|
230
|
+
else:
|
|
231
|
+
# resample audio to 16000 for whisper
|
|
232
|
+
resampled_audio = resample_audio(
|
|
233
|
+
audio[..., None], self.audio_codec.sr, WHISPER_SAMPLE_RATE
|
|
234
|
+
)
|
|
235
|
+
resampled_audio = mx.array(resampled_audio, dtype=mx.float32).mean(axis=1)
|
|
236
|
+
|
|
237
|
+
# convert to 2d array
|
|
238
|
+
audio = audio[None, None, ...]
|
|
239
|
+
|
|
240
|
+
seconds = audio.flatten().shape[0] / self.audio_codec.sr
|
|
241
|
+
if seconds > 20:
|
|
242
|
+
print(
|
|
243
|
+
"Speaker audio is longer than 20 seconds. Use a shorter clip for best results."
|
|
244
|
+
)
|
|
245
|
+
if seconds > 15:
|
|
246
|
+
print(
|
|
247
|
+
"Speaker audio is longer than 15 seconds. For best results, consider using an audio clip up to 15 seconds."
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
# load whisper model
|
|
251
|
+
whisper_model = load_model(whisper_model)
|
|
252
|
+
|
|
253
|
+
# transcribe audio
|
|
254
|
+
data = whisper_model.generate(resampled_audio.flatten(), word_timestamps=True)
|
|
255
|
+
data = asdict(data)
|
|
256
|
+
|
|
257
|
+
# clear memory
|
|
258
|
+
del whisper_model
|
|
259
|
+
mx.clear_cache()
|
|
260
|
+
|
|
261
|
+
text = PromptProcessor.text_normalizations(data["text"])
|
|
262
|
+
words = []
|
|
263
|
+
for s in data["segments"]:
|
|
264
|
+
words.extend(
|
|
265
|
+
[
|
|
266
|
+
{
|
|
267
|
+
"word": i["word"].strip(),
|
|
268
|
+
"start": float(i["start"]),
|
|
269
|
+
"end": float(i["end"]),
|
|
270
|
+
}
|
|
271
|
+
for i in s["words"]
|
|
272
|
+
]
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
return self.create_speaker_from_dict(
|
|
276
|
+
{"audio": {"bytes": audio}, "text": text, "words": words}
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
def create_speaker_from_dict(self, data: dict):
|
|
280
|
+
audio = data["audio"]["bytes"]
|
|
281
|
+
if isinstance(audio, str):
|
|
282
|
+
audio = io.BytesIO(audio)
|
|
283
|
+
audio = self.audio_codec.load_audio(audio)
|
|
284
|
+
|
|
285
|
+
full_codes = self.audio_codec.encode(audio, verbose=True).tolist()[0]
|
|
286
|
+
|
|
287
|
+
c1 = full_codes[0]
|
|
288
|
+
c2 = full_codes[1]
|
|
289
|
+
|
|
290
|
+
sr = self.audio_codec.sr
|
|
291
|
+
text = data["text"]
|
|
292
|
+
words = data["words"]
|
|
293
|
+
|
|
294
|
+
tps = 75
|
|
295
|
+
|
|
296
|
+
audio = audio.squeeze(0)
|
|
297
|
+
global_features = self.features.extract_audio_features(audio, sr)
|
|
298
|
+
|
|
299
|
+
start = None
|
|
300
|
+
word_codes = []
|
|
301
|
+
max_extension = 20
|
|
302
|
+
|
|
303
|
+
for idx, i in enumerate(words):
|
|
304
|
+
if start is None:
|
|
305
|
+
start = max(0, int(i["start"] * tps) - max_extension)
|
|
306
|
+
word = i["word"].strip()
|
|
307
|
+
if idx == len(words) - 1:
|
|
308
|
+
end = min(len(c1), int(i["end"] * tps) + max_extension)
|
|
309
|
+
else:
|
|
310
|
+
end = int(i["end"] * tps)
|
|
311
|
+
|
|
312
|
+
word_c1 = c1[start:end]
|
|
313
|
+
word_c2 = c2[start:end]
|
|
314
|
+
|
|
315
|
+
word_audio = audio[:, int(i["start"] * sr) : int(i["end"] * sr)]
|
|
316
|
+
features = self.features.extract_audio_features(word_audio, sr)
|
|
317
|
+
|
|
318
|
+
start = end
|
|
319
|
+
|
|
320
|
+
word_codes.append(
|
|
321
|
+
{
|
|
322
|
+
"word": word,
|
|
323
|
+
"duration": round(len(word_c1) / tps, 2),
|
|
324
|
+
"c1": word_c1,
|
|
325
|
+
"c2": word_c2,
|
|
326
|
+
"features": features,
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
return {"text": text, "words": word_codes, "global_features": global_features}
|
|
331
|
+
|
|
332
|
+
def save_speaker(self, speaker: dict, path: str):
|
|
333
|
+
# Expand ~ to home directory to save in ~/.cache/mlx_audio/voices
|
|
334
|
+
path = os.path.expanduser(path)
|
|
335
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
336
|
+
|
|
337
|
+
with open(path, "w") as f:
|
|
338
|
+
json.dump(speaker, f)
|
|
339
|
+
|
|
340
|
+
print(f"Speaker saved to: {path}")
|
|
341
|
+
|
|
342
|
+
def load_speaker(self, path: str):
|
|
343
|
+
# Expand ~ to home directory to load from ~/.cache/mlx_audio/voices
|
|
344
|
+
path = os.path.expanduser(path)
|
|
345
|
+
if not os.path.exists(path):
|
|
346
|
+
raise FileNotFoundError(f"Speaker file not found: {path}")
|
|
347
|
+
|
|
348
|
+
with open(path, "r") as f:
|
|
349
|
+
return json.load(f)
|
|
350
|
+
|
|
351
|
+
print(f"Speaker loaded from: {path}")
|