Moshi Documentation

repository·main·Indexed 27 days ago

https://github.com/kyutai-labs/moshi

Moshi is a speech-text foundation model for full-duplex, real-time spoken dialogue using the Mimi neural audio codec. The project provides multiple implementations, including PyTorch, MLX for Apple Silicon, and a production-ready Rust backend. It includes a web-based frontend with echo cancellation, a command-line interface, and programmatic access to the Mimi audio tokenizer and Moshi LM model.

Tokens
19.1K
Snippets
34
Records
141
Agent score
95%

What's inside Moshi

  1. Skip the queue for standalone worker use

    main

    If you want to use the moshi-client with a specific standalone worker instance instead of the default queue, append the worker_addr query parameter to the URL in your browser. The format is /?worker_addr={WORKER_ADDR}, where {WORKER_ADDR} is the address of your worker instance.

    Example: https://localhost:5173/?worker_addr=0.0.0.0:8088

    https://localhost:5173/?worker_addr=0.0.0.0:8088
  2. Install Moshi via pip

    main
    You can install the PyTorch and MLX clients using pip. Python 3.10 is required, but 3.12 is recommended. If you are not using Python 3.12, you may need to install the Rust toolchain to handle dependencies like rustymimi or moshi_mlx.
  3. Build the Moshi Web UI

    main

    To build the web client locally, you must have npm installed. The web UI provides additional echo cancellation which improves model quality. Once built, the files are located in the client/dist directory.

    cd client
    npm install
    npm run build
  4. Install rustymimi via pip or source

    main

    The rustymimi package provides a standalone Rust-based implementation of Mimi with Python bindings. It is used by moshi_mlx and can be installed independently.

    To install the pre-built package via pip:

    pip install rustymimi

    To compile the package from the repository root:

    maturin dev -r -m rust/mimi-pyo3/Cargo.toml
    pip install rustymimi
  5. Install Moshi for Development

    main

    If you are developing Moshi or its MLX implementation, install the packages in editable mode with development dependencies from the root of the repository clone.

    # From the root of the clone of the repo
    pip install -e 'moshi[dev]'
    pip install -e 'moshi_mlx[dev]'
    pre-commit install
  6. Run Moshi-MLX for local inference on macOS

    main

    For on-device inference on Mac (optimized for Apple Silicon), use the moshi_mlx package. You can run quantized versions (4-bit or 8-bit) or use the web UI.

    Important: When using the --hf-repo flag, ensure the repository matches the quantization level specified by -q.

  7. Set up and run the moshi-client frontend

    main

    The moshi-client is the frontend for the Moshi demo. To set it up, ensure you have Node.js installed (using nvm use is recommended to match the project's required version).

    Follow these steps to prepare the environment:

    1. Generate a public/private key pair named cert.pem and key.pem and place them in the root of the moshi-client package.
    2. Create an env.local file and define the VITE_QUEUE_API_PATH environment variable (the default value is /api).
    3. Install dependencies using npm install.

    To start the development server, use npm run dev. To create a production build, use npm run build.

  8. Run the PyTorch Moshi server

    main

    To run Moshi in interactive mode using PyTorch, start the server. You can then access the web UI at http://localhost:8998.

    If you need to access the server from a remote machine, use the --gradio-tunnel flag or use SSH port forwarding (ssh -L 8998:localhost:8998). Use --hf-repo to specify a different pretrained model from Hugging Face.

    python -m moshi.server [--gradio-tunnel] [--hf-repo kyutai/moshika-pytorch-bf16]
  9. Install Moshi (PyTorch implementation)

    main

    You can install the stable version of Moshi from PyPI or the bleeding edge version directly from GitHub.

    Requirements:

    • Python 3.10 or higher.
    • PyTorch 2.2 or 2.4 (ensure PyTorch is installed correctly if using specific CUDA versions).
    • For the PyTorch version, a GPU with significant memory (approx. 24GB) is recommended as quantization is not currently supported.

    Note for Python 3.14 users: If using Python 3.14, you must disable torch.compile() by setting the environment variable NO_TORCH_COMPILE=1.

  10. Install for development

    main

    To install the repository in editable mode for development, including development dependencies, run:

    pip install -e '.[dev]'
    pre-commit install

    Testing:

    • To test Mimi streaming (from the repository root): python scripts/mimi_streaming_test.py
    • To test Moshi (requires GPU): python scripts/moshi_benchmark.py