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,382 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import time
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Optional, Tuple, Union
|
|
6
|
+
|
|
7
|
+
import mlx.core as mx
|
|
8
|
+
import mlx.nn as nn
|
|
9
|
+
from mlx_lm.generate import stream_generate
|
|
10
|
+
from mlx_lm.models.qwen2 import Model as Qwen2Model
|
|
11
|
+
from mlx_lm.sample_utils import make_logits_processors, make_sampler
|
|
12
|
+
from mlx_lm.tokenizer_utils import load_tokenizer
|
|
13
|
+
from tqdm import tqdm
|
|
14
|
+
|
|
15
|
+
from mlx_audio.tts.models.base import BaseModelArgs, GenerationResult
|
|
16
|
+
from mlx_audio.tts.utils import get_model_path
|
|
17
|
+
|
|
18
|
+
from .audio_tokenizer import BiCodecTokenizer
|
|
19
|
+
from .utils.token_parser import GENDER_MAP, LEVELS_MAP, TASK_TOKEN_MAP
|
|
20
|
+
|
|
21
|
+
PITCH_MAP = SPEED_MAP = {
|
|
22
|
+
0.0: "very_low",
|
|
23
|
+
0.5: "low",
|
|
24
|
+
1.0: "moderate",
|
|
25
|
+
1.5: "high",
|
|
26
|
+
2.0: "very_high",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class ModelConfig(BaseModelArgs):
|
|
32
|
+
model_path: Path = None
|
|
33
|
+
sample_rate: int = 16000
|
|
34
|
+
bos_token_id: int = 151643
|
|
35
|
+
eos_token_id: int = 151645
|
|
36
|
+
hidden_act: str = "silu"
|
|
37
|
+
hidden_size: int = 896
|
|
38
|
+
initializer_range: float = 0.02
|
|
39
|
+
intermediate_size: int = 4864
|
|
40
|
+
max_position_embeddings: int = 32768
|
|
41
|
+
max_window_layers: int = 21
|
|
42
|
+
model_type: str = "qwen2"
|
|
43
|
+
num_attention_heads: int = 14
|
|
44
|
+
num_hidden_layers: int = 24
|
|
45
|
+
num_key_value_heads: int = 2
|
|
46
|
+
rms_norm_eps: float = 1e-06
|
|
47
|
+
rope_theta: float = 1000000.0
|
|
48
|
+
sliding_window: int = 32768
|
|
49
|
+
tie_word_embeddings: bool = True
|
|
50
|
+
torch_dtype: str = "bfloat16"
|
|
51
|
+
transformers_version: str = "4.43.1"
|
|
52
|
+
use_sliding_window: bool = False
|
|
53
|
+
vocab_size: int = 166000
|
|
54
|
+
rope_traditional: bool = False
|
|
55
|
+
rope_scaling: Optional[Dict[str, Union[float, str]]] = None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class Model(nn.Module):
|
|
59
|
+
"""
|
|
60
|
+
Spark-TTS for text-to-speech generation.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(self, config: ModelConfig):
|
|
64
|
+
"""
|
|
65
|
+
Initializes the SparkTTS model with the provided configurations and device.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
config (ModelConfig): The configuration for the model.
|
|
69
|
+
"""
|
|
70
|
+
self.config = config
|
|
71
|
+
|
|
72
|
+
model_dir = config.model_path
|
|
73
|
+
|
|
74
|
+
self.model = Qwen2Model(config)
|
|
75
|
+
self.tokenizer = load_tokenizer(model_dir, eos_token_ids=config.eos_token_id)
|
|
76
|
+
|
|
77
|
+
self._audio_tokenizer = BiCodecTokenizer(model_dir)
|
|
78
|
+
|
|
79
|
+
def load_weights(self, weights, strict=True):
|
|
80
|
+
self.model.load_weights(weights, strict=strict)
|
|
81
|
+
|
|
82
|
+
def parameters(self):
|
|
83
|
+
return self.model.parameters()
|
|
84
|
+
|
|
85
|
+
def model_type(self):
|
|
86
|
+
return "spark"
|
|
87
|
+
|
|
88
|
+
def sanitize(self, weights):
|
|
89
|
+
return self.model.sanitize(weights)
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def sample_rate(self):
|
|
93
|
+
return self.config.sample_rate
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def layers(self):
|
|
97
|
+
return self.model.layers
|
|
98
|
+
|
|
99
|
+
def model_quant_predicate(self, p, m, config):
|
|
100
|
+
"""
|
|
101
|
+
Model modules to skip during quantization
|
|
102
|
+
"""
|
|
103
|
+
return not p.startswith("_audio_tokenizer")
|
|
104
|
+
|
|
105
|
+
def process_prompt(
|
|
106
|
+
self,
|
|
107
|
+
text: str,
|
|
108
|
+
ref_audio: Path,
|
|
109
|
+
ref_text: str,
|
|
110
|
+
) -> Tuple[str, mx.array]:
|
|
111
|
+
"""
|
|
112
|
+
Process input for voice cloning.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
text (str): The text input to be converted to speech.
|
|
116
|
+
ref_audio (Path): Path to the audio file used as a reference.
|
|
117
|
+
ref_text (str, optional): Transcript of the reference audio.
|
|
118
|
+
|
|
119
|
+
Return:
|
|
120
|
+
Tuple[str, mx.array]: Input prompt; global tokens
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
global_token_ids, semantic_token_ids = self._audio_tokenizer.tokenize(ref_audio)
|
|
124
|
+
global_tokens = "".join(
|
|
125
|
+
[f"<|bicodec_global_{i}|>" for i in global_token_ids.squeeze()]
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# Prepare the input tokens for the model
|
|
129
|
+
if ref_text is not None:
|
|
130
|
+
semantic_tokens = "".join(
|
|
131
|
+
[f"<|bicodec_semantic_{i}|>" for i in semantic_token_ids.squeeze()]
|
|
132
|
+
)
|
|
133
|
+
inputs = [
|
|
134
|
+
TASK_TOKEN_MAP["tts"],
|
|
135
|
+
"<|start_content|>",
|
|
136
|
+
ref_text,
|
|
137
|
+
text,
|
|
138
|
+
"<|end_content|>",
|
|
139
|
+
"<|start_global_token|>",
|
|
140
|
+
global_tokens,
|
|
141
|
+
"<|end_global_token|>",
|
|
142
|
+
"<|start_semantic_token|>",
|
|
143
|
+
semantic_tokens,
|
|
144
|
+
]
|
|
145
|
+
else:
|
|
146
|
+
inputs = [
|
|
147
|
+
TASK_TOKEN_MAP["tts"],
|
|
148
|
+
"<|start_content|>",
|
|
149
|
+
text,
|
|
150
|
+
"<|end_content|>",
|
|
151
|
+
"<|start_global_token|>",
|
|
152
|
+
global_tokens,
|
|
153
|
+
"<|end_global_token|>",
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
inputs = "".join(inputs)
|
|
157
|
+
|
|
158
|
+
return inputs, global_token_ids
|
|
159
|
+
|
|
160
|
+
def process_prompt_control(
|
|
161
|
+
self,
|
|
162
|
+
gender: str,
|
|
163
|
+
pitch: str,
|
|
164
|
+
speed: str,
|
|
165
|
+
text: str,
|
|
166
|
+
):
|
|
167
|
+
"""
|
|
168
|
+
Process input for voice creation.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
gender (str): female | male.
|
|
172
|
+
pitch (str): very_low | low | moderate | high | very_high
|
|
173
|
+
speed (str): very_low | low | moderate | high | very_high
|
|
174
|
+
text (str): The text input to be converted to speech.
|
|
175
|
+
|
|
176
|
+
Return:
|
|
177
|
+
str: Input prompt
|
|
178
|
+
"""
|
|
179
|
+
assert gender in GENDER_MAP.keys()
|
|
180
|
+
assert pitch in LEVELS_MAP.keys()
|
|
181
|
+
assert speed in LEVELS_MAP.keys()
|
|
182
|
+
|
|
183
|
+
gender_id = GENDER_MAP[gender]
|
|
184
|
+
pitch_level_id = LEVELS_MAP[pitch]
|
|
185
|
+
speed_level_id = LEVELS_MAP[speed]
|
|
186
|
+
|
|
187
|
+
pitch_label_tokens = f"<|pitch_label_{pitch_level_id}|>"
|
|
188
|
+
speed_label_tokens = f"<|speed_label_{speed_level_id}|>"
|
|
189
|
+
gender_tokens = f"<|gender_{gender_id}|>"
|
|
190
|
+
|
|
191
|
+
attribte_tokens = "".join(
|
|
192
|
+
[gender_tokens, pitch_label_tokens, speed_label_tokens]
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
control_tts_inputs = [
|
|
196
|
+
TASK_TOKEN_MAP["controllable_tts"],
|
|
197
|
+
"<|start_content|>",
|
|
198
|
+
text,
|
|
199
|
+
"<|end_content|>",
|
|
200
|
+
"<|start_style_label|>",
|
|
201
|
+
attribte_tokens,
|
|
202
|
+
"<|end_style_label|>",
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
return "".join(control_tts_inputs)
|
|
206
|
+
|
|
207
|
+
def generate(
|
|
208
|
+
self,
|
|
209
|
+
text: str,
|
|
210
|
+
ref_audio: Path = None,
|
|
211
|
+
ref_text: str = None,
|
|
212
|
+
gender: str = "male",
|
|
213
|
+
pitch: float = 1.0,
|
|
214
|
+
speed: float = 1.0,
|
|
215
|
+
temperature: float = 0.8,
|
|
216
|
+
top_k: float = 50,
|
|
217
|
+
top_p: float = 0.95,
|
|
218
|
+
max_tokens: int = 3000,
|
|
219
|
+
verbose: bool = False,
|
|
220
|
+
split_pattern: str = "\n",
|
|
221
|
+
**kwargs,
|
|
222
|
+
) -> GenerationResult:
|
|
223
|
+
"""
|
|
224
|
+
Performs inference to generate speech from text, incorporating prompt audio and/or text.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
text (str): The text input to be converted to speech.
|
|
228
|
+
ref_audio (Path): Path to the audio file used as a reference.
|
|
229
|
+
ref_text (str, optional): Transcript of the reference audio.
|
|
230
|
+
gender (str): female | male.
|
|
231
|
+
pitch (str): very_low | low | moderate | high | very_high
|
|
232
|
+
speed (str): very_low | low | moderate | high | very_high
|
|
233
|
+
temperature (float, optional): Sampling temperature for controlling randomness. Default is 0.8.
|
|
234
|
+
top_k (float, optional): Top-k sampling parameter. Default is 50.
|
|
235
|
+
top_p (float, optional): Top-p (nucleus) sampling parameter. Default is 0.95.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
GenerationResult: Generated waveform as a tensor.
|
|
239
|
+
"""
|
|
240
|
+
|
|
241
|
+
speed_factor = SPEED_MAP[speed]
|
|
242
|
+
pitch_factor = PITCH_MAP[pitch]
|
|
243
|
+
|
|
244
|
+
if ref_audio is not None: # voice cloning
|
|
245
|
+
gender = None
|
|
246
|
+
|
|
247
|
+
text_splits = text.split(split_pattern)
|
|
248
|
+
|
|
249
|
+
for text_split in text_splits:
|
|
250
|
+
if gender is not None:
|
|
251
|
+
prompt = self.process_prompt_control(
|
|
252
|
+
gender, pitch_factor, speed_factor, text_split
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
else:
|
|
256
|
+
prompt, global_token_ids = self.process_prompt(
|
|
257
|
+
text_split, ref_audio, ref_text
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
inputs = self.tokenizer._tokenizer([prompt], return_tensors="pt")
|
|
261
|
+
|
|
262
|
+
input_ids = mx.array(inputs.input_ids)
|
|
263
|
+
|
|
264
|
+
sampler = make_sampler(temperature, top_p=top_p, top_k=top_k)
|
|
265
|
+
logits_processors = make_logits_processors(
|
|
266
|
+
kwargs.get("logit_bias", None),
|
|
267
|
+
kwargs.get("repetition_penalty", 1.3),
|
|
268
|
+
kwargs.get("repetition_context_size", 20),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
time_start = time.time()
|
|
272
|
+
|
|
273
|
+
generated_ids = []
|
|
274
|
+
|
|
275
|
+
# Generate speech using the model
|
|
276
|
+
for i, response in enumerate(
|
|
277
|
+
tqdm(
|
|
278
|
+
stream_generate(
|
|
279
|
+
self.model,
|
|
280
|
+
tokenizer=self.tokenizer,
|
|
281
|
+
prompt=input_ids.squeeze(0),
|
|
282
|
+
max_tokens=max_tokens,
|
|
283
|
+
sampler=sampler,
|
|
284
|
+
logits_processors=logits_processors,
|
|
285
|
+
),
|
|
286
|
+
total=max_tokens,
|
|
287
|
+
disable=not verbose,
|
|
288
|
+
)
|
|
289
|
+
):
|
|
290
|
+
next_token = mx.array([response.token])
|
|
291
|
+
input_ids = mx.concatenate([input_ids, next_token[None, :]], axis=1)
|
|
292
|
+
if i % 50 == 0:
|
|
293
|
+
mx.clear_cache()
|
|
294
|
+
|
|
295
|
+
if next_token == 128258:
|
|
296
|
+
break
|
|
297
|
+
|
|
298
|
+
time_end = time.time()
|
|
299
|
+
# Trim the output tokens to remove the input tokens
|
|
300
|
+
generated_ids = mx.array(
|
|
301
|
+
[
|
|
302
|
+
output[len(input) :]
|
|
303
|
+
for input, output in zip(inputs.input_ids, input_ids)
|
|
304
|
+
]
|
|
305
|
+
).tolist()
|
|
306
|
+
|
|
307
|
+
# Decode the generated tokens into text
|
|
308
|
+
predicts = self.tokenizer._tokenizer.batch_decode(
|
|
309
|
+
generated_ids, skip_special_tokens=True
|
|
310
|
+
)[0]
|
|
311
|
+
|
|
312
|
+
# Extract semantic token IDs from the generated text
|
|
313
|
+
pred_semantic_ids = mx.array(
|
|
314
|
+
[
|
|
315
|
+
int(token)
|
|
316
|
+
for token in re.findall(r"bicodec_semantic_(\d+)", predicts)
|
|
317
|
+
]
|
|
318
|
+
)[None, ...]
|
|
319
|
+
|
|
320
|
+
if gender is not None:
|
|
321
|
+
global_token_ids = mx.array(
|
|
322
|
+
[
|
|
323
|
+
int(token)
|
|
324
|
+
for token in re.findall(r"bicodec_global_(\d+)", predicts)
|
|
325
|
+
]
|
|
326
|
+
)[None, ...]
|
|
327
|
+
|
|
328
|
+
# Convert semantic tokens back to waveform
|
|
329
|
+
audio = self._audio_tokenizer.detokenize(
|
|
330
|
+
global_token_ids.astype(mx.int32),
|
|
331
|
+
pred_semantic_ids.astype(mx.int32),
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
# Clear cache
|
|
335
|
+
mx.clear_cache()
|
|
336
|
+
|
|
337
|
+
audio_samples = len(audio)
|
|
338
|
+
audio_duration_seconds = audio_samples / self.config.sample_rate
|
|
339
|
+
|
|
340
|
+
# Format duration as HH:MM:SS.mmm
|
|
341
|
+
duration_mins = int(audio_duration_seconds // 60)
|
|
342
|
+
duration_secs = int(audio_duration_seconds % 60)
|
|
343
|
+
duration_ms = int((audio_duration_seconds % 1) * 1000)
|
|
344
|
+
duration_hours = int(audio_duration_seconds // 3600)
|
|
345
|
+
duration_str = f"{duration_hours:02d}:{duration_mins:02d}:{duration_secs:02d}.{duration_ms:03d}"
|
|
346
|
+
|
|
347
|
+
yield GenerationResult(
|
|
348
|
+
audio=audio,
|
|
349
|
+
sample_rate=self.config.sample_rate,
|
|
350
|
+
samples=audio_samples,
|
|
351
|
+
segment_idx=0, # Default segment index
|
|
352
|
+
token_count=len(pred_semantic_ids.squeeze()),
|
|
353
|
+
audio_samples={
|
|
354
|
+
"samples": audio_samples,
|
|
355
|
+
"samples-per-sec": (
|
|
356
|
+
round(audio_samples / audio_duration_seconds, 2)
|
|
357
|
+
if audio_duration_seconds > 0
|
|
358
|
+
else 0
|
|
359
|
+
),
|
|
360
|
+
},
|
|
361
|
+
audio_duration=duration_str,
|
|
362
|
+
real_time_factor=(
|
|
363
|
+
audio_duration_seconds / (time_end - time_start)
|
|
364
|
+
if (time_end - time_start) > 0
|
|
365
|
+
else 0
|
|
366
|
+
),
|
|
367
|
+
prompt={
|
|
368
|
+
"tokens": len(pred_semantic_ids.squeeze()),
|
|
369
|
+
"tokens-per-sec": (
|
|
370
|
+
round(
|
|
371
|
+
len(pred_semantic_ids.squeeze()) / audio_duration_seconds, 2
|
|
372
|
+
)
|
|
373
|
+
if audio_duration_seconds > 0
|
|
374
|
+
else 0
|
|
375
|
+
),
|
|
376
|
+
},
|
|
377
|
+
processing_time_seconds=time_end - time_start,
|
|
378
|
+
peak_memory_usage=mx.get_peak_memory() / 1e9,
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
# Clear cache after each segment to avoid memory leaks
|
|
382
|
+
mx.clear_cache()
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Copyright (c) 2025 SparkAudio
|
|
2
|
+
# 2025 Xinsheng Wang (w.xinshawn@gmail.com)
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
Description:
|
|
17
|
+
This script contains a collection of functions designed to handle various
|
|
18
|
+
audio processing.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import random
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Tuple
|
|
24
|
+
|
|
25
|
+
import mlx.core as mx
|
|
26
|
+
import numpy as np
|
|
27
|
+
import soundfile
|
|
28
|
+
import soxr
|
|
29
|
+
from numpy.lib.stride_tricks import sliding_window_view
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def audio_volume_normalize(audio: np.ndarray, coeff: float = 0.2) -> np.ndarray:
|
|
33
|
+
"""
|
|
34
|
+
Normalize the volume of an audio signal.
|
|
35
|
+
|
|
36
|
+
Parameters:
|
|
37
|
+
audio (numpy array): Input audio signal array.
|
|
38
|
+
coeff (float): Target coefficient for normalization, default is 0.2.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
numpy array: The volume-normalized audio signal.
|
|
42
|
+
"""
|
|
43
|
+
# Sort the absolute values of the audio signal
|
|
44
|
+
temp = np.sort(np.abs(audio))
|
|
45
|
+
|
|
46
|
+
# If the maximum value is less than 0.1, scale the array to have a maximum of 0.1
|
|
47
|
+
if temp[-1] < 0.1:
|
|
48
|
+
scaling_factor = max(
|
|
49
|
+
temp[-1], 1e-3
|
|
50
|
+
) # Prevent division by zero with a small constant
|
|
51
|
+
audio = audio / scaling_factor * 0.1
|
|
52
|
+
|
|
53
|
+
# Filter out values less than 0.01 from temp
|
|
54
|
+
temp = temp[temp > 0.01]
|
|
55
|
+
L = temp.shape[0] # Length of the filtered array
|
|
56
|
+
|
|
57
|
+
# If there are fewer than or equal to 10 significant values, return the audio without further processing
|
|
58
|
+
if L <= 10:
|
|
59
|
+
return audio
|
|
60
|
+
|
|
61
|
+
# Compute the average of the top 10% to 1% of values in temp
|
|
62
|
+
volume = np.mean(temp[int(0.9 * L) : int(0.99 * L)])
|
|
63
|
+
|
|
64
|
+
# Normalize the audio to the target coefficient level, clamping the scale factor between 0.1 and 10
|
|
65
|
+
audio = audio * np.clip(coeff / volume, a_min=0.1, a_max=10)
|
|
66
|
+
|
|
67
|
+
# Ensure the maximum absolute value in the audio does not exceed 1
|
|
68
|
+
max_value = np.max(np.abs(audio))
|
|
69
|
+
if max_value > 1:
|
|
70
|
+
audio = audio / max_value
|
|
71
|
+
|
|
72
|
+
return audio
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def load_audio(
|
|
76
|
+
adfile: Path,
|
|
77
|
+
sampling_rate: int = None,
|
|
78
|
+
length: int = None,
|
|
79
|
+
volume_normalize: bool = False,
|
|
80
|
+
segment_duration: int = None,
|
|
81
|
+
) -> np.ndarray:
|
|
82
|
+
r"""Load audio file with target sampling rate and lsength
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
adfile (Path): path to audio file.
|
|
86
|
+
sampling_rate (int, optional): target sampling rate. Defaults to None.
|
|
87
|
+
length (int, optional): target audio length. Defaults to None.
|
|
88
|
+
volume_normalize (bool, optional): whether perform volume normalization. Defaults to False.
|
|
89
|
+
segment_duration (int): random select a segment with duration of {segment_duration}s.
|
|
90
|
+
Defualt to None which means the whole audio will be used.
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
audio (np.ndarray): audio
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
audio, sr = soundfile.read(adfile)
|
|
97
|
+
if len(audio.shape) > 1:
|
|
98
|
+
audio = audio[:, 0]
|
|
99
|
+
|
|
100
|
+
if sampling_rate is not None and sr != sampling_rate:
|
|
101
|
+
audio = soxr.resample(audio, sr, sampling_rate, quality="VHQ")
|
|
102
|
+
sr = sampling_rate
|
|
103
|
+
|
|
104
|
+
if segment_duration is not None:
|
|
105
|
+
seg_length = int(sr * segment_duration)
|
|
106
|
+
audio = random_select_audio_segment(audio, seg_length)
|
|
107
|
+
|
|
108
|
+
# Audio volume normalize
|
|
109
|
+
if volume_normalize:
|
|
110
|
+
audio = audio_volume_normalize(audio)
|
|
111
|
+
# check the audio length
|
|
112
|
+
if length is not None:
|
|
113
|
+
assert abs(audio.shape[0] - length) < 1000
|
|
114
|
+
if audio.shape[0] > length:
|
|
115
|
+
audio = audio[:length]
|
|
116
|
+
else:
|
|
117
|
+
audio = np.pad(audio, (0, int(length - audio.shape[0])))
|
|
118
|
+
return audio
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def random_select_audio_segment(audio: np.ndarray, length: int) -> np.ndarray:
|
|
122
|
+
"""get an audio segment given the length
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
audio (np.ndarray):
|
|
126
|
+
length (int): audio length = sampling_rate * duration
|
|
127
|
+
"""
|
|
128
|
+
if audio.shape[0] < length:
|
|
129
|
+
audio = np.pad(audio, (0, int(length - audio.shape[0])))
|
|
130
|
+
start_index = random.randint(0, audio.shape[0] - length)
|
|
131
|
+
end_index = int(start_index + length)
|
|
132
|
+
|
|
133
|
+
return audio[start_index:end_index]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def detect_speech_boundaries(
|
|
137
|
+
wav: np.ndarray,
|
|
138
|
+
sample_rate: int,
|
|
139
|
+
window_duration: float = 0.1,
|
|
140
|
+
energy_threshold: float = 0.01,
|
|
141
|
+
margin_factor: int = 2,
|
|
142
|
+
) -> Tuple[int, int]:
|
|
143
|
+
"""Detect the start and end points of speech in an audio signal using RMS energy.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
wav: Input audio signal array with values in [-1, 1]
|
|
147
|
+
sample_rate: Audio sample rate in Hz
|
|
148
|
+
window_duration: Duration of detection window in seconds
|
|
149
|
+
energy_threshold: RMS energy threshold for speech detection
|
|
150
|
+
margin_factor: Factor to determine extra margin around detected boundaries
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
tuple: (start_index, end_index) of speech segment
|
|
154
|
+
|
|
155
|
+
Raises:
|
|
156
|
+
ValueError: If the audio contains only silence
|
|
157
|
+
"""
|
|
158
|
+
window_size = int(window_duration * sample_rate)
|
|
159
|
+
margin = margin_factor * window_size
|
|
160
|
+
step_size = window_size // 10
|
|
161
|
+
|
|
162
|
+
# Create sliding windows using stride tricks to avoid loops
|
|
163
|
+
windows = sliding_window_view(wav, window_size)[::step_size]
|
|
164
|
+
|
|
165
|
+
# Calculate RMS energy for each window
|
|
166
|
+
energy = np.sqrt(np.mean(windows**2, axis=1))
|
|
167
|
+
speech_mask = energy >= energy_threshold
|
|
168
|
+
|
|
169
|
+
if not np.any(speech_mask):
|
|
170
|
+
raise ValueError("No speech detected in audio (only silence)")
|
|
171
|
+
|
|
172
|
+
start = max(0, np.argmax(speech_mask) * step_size - margin)
|
|
173
|
+
end = min(
|
|
174
|
+
len(wav),
|
|
175
|
+
(len(speech_mask) - 1 - np.argmax(speech_mask[::-1])) * step_size + margin,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
return start, end
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def remove_silence_on_both_ends(
|
|
182
|
+
wav: np.ndarray,
|
|
183
|
+
sample_rate: int,
|
|
184
|
+
window_duration: float = 0.1,
|
|
185
|
+
volume_threshold: float = 0.01,
|
|
186
|
+
) -> np.ndarray:
|
|
187
|
+
"""Remove silence from both ends of an audio signal.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
wav: Input audio signal array
|
|
191
|
+
sample_rate: Audio sample rate in Hz
|
|
192
|
+
window_duration: Duration of detection window in seconds
|
|
193
|
+
volume_threshold: Amplitude threshold for silence detection
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
np.ndarray: Audio signal with silence removed from both ends
|
|
197
|
+
|
|
198
|
+
Raises:
|
|
199
|
+
ValueError: If the audio contains only silence
|
|
200
|
+
"""
|
|
201
|
+
start, end = detect_speech_boundaries(
|
|
202
|
+
wav, sample_rate, window_duration, volume_threshold
|
|
203
|
+
)
|
|
204
|
+
return wav[start:end]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def hertz_to_mel(pitch: float) -> float:
|
|
208
|
+
"""
|
|
209
|
+
Converts a frequency from the Hertz scale to the Mel scale.
|
|
210
|
+
|
|
211
|
+
Parameters:
|
|
212
|
+
- pitch: float or ndarray
|
|
213
|
+
Frequency in Hertz.
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
- mel: float or ndarray
|
|
217
|
+
Frequency in Mel scale.
|
|
218
|
+
"""
|
|
219
|
+
mel = 2595 * np.log10(1 + pitch / 700)
|
|
220
|
+
return mel
|