MCPcopy Index your code
hub / github.com/FunAudioLLM/FunMusic

github.com/FunAudioLLM/FunMusic @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
856 symbols 2,331 edges 100 files 280 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

logo

Demo Code Model Space Space Paper

GitHub Repo stars Please support our community by starring it 感谢大家支持

| Highlight | Introduction | Installation | Quick Start | Tutorial | Models


InspireMusic focuses on music generation, song generation, and audio generation. - A unified toolkit designed for music, song, and audio generation. - Music generation tasks with high audio quality. - Long-form music generation.

Introduction

InspireMusic is a toolkit for music, song, and audio generation. It consists of an autoregressive transformer with a flow-matching based model. This toolkit is for users to generate music, song, and audio. InspireMusic can generate high-quality music in long-form with text-to-music and music continuation. InspireMusic incorporates audio tokenizers with autoregressive transformer and flow-matching modeling to generate music, song, and audio with text and music prompts. The toolkit currently supports music generation.

InspireMusic

Light
Figure 1: An overview of the InspireMusic. We introduce InspireMusic, a toolkit designed for music, song, audio generation capable of producing high-quality long-form music. InspireMusic consists of the following three key components. Audio Tokenizers convert the raw audio waveform into discrete audio tokens that can be efficiently processed and trained by the autoregressive transformer model. Audio waveform of lower sampling rate has converted to discrete tokens via a high bitrate compression audio tokenizer[1]. Autoregressive Transformer model is based on Qwen2.5[2] as the backbone model and is trained using a next-token prediction approach on both text and audio tokens, enabling it to generate coherent and contextually relevant token sequences. The audio and text tokens are the inputs of an autoregressive model with the next token prediction to generate tokens. Super-Resolution Flow-Matching Model based on flow modeling method, maps the generated tokens to latent features with high-resolution fine-grained acoustic details[3] obtained from a higher sampling rate of audio to ensure the acoustic information flow connected with high fidelity through models. A vocoder then generates the final audio waveform from these enhanced latent features. InspireMusic supports a range of tasks including text-to-music, music continuation, music reconstruction and super resolution..

Installation

Clone

  • Clone the repo
git clone --recursive https://github.com/FunAudioLLM/InspireMusic.git
# If you failed to clone submodule due to network failures, please run the following command until success
cd InspireMusic
git submodule update --recursive
# or you can download the third_party repo Matcha-TTS manually
cd third_party && git clone https://github.com/shivammehta25/Matcha-TTS.git

Install from Source

InspireMusic requires Python>=3.8, PyTorch>=2.0.1, flash attention==2.6.2/2.6.3, CUDA>=11.8. You can install the dependencies with the following commands:

  • Install Conda: please see https://docs.conda.io/en/latest/miniconda.html
  • Create Conda env:
conda create -n inspiremusic python=3.8
conda activate inspiremusic
cd InspireMusic
# pynini is required by WeTextProcessing, use conda to install it as it can be executed on all platforms.
conda install -y -c conda-forge pynini==2.1.5
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
# install flash attention to speedup training
pip install flash-attn --no-build-isolation
  • Install within the package:
cd InspireMusic
# You can run to install the packages
python setup.py install
pip install flash-attn --no-build-isolation

We also recommend having sox or ffmpeg installed, either through your system or Anaconda:

# # Install sox
# ubuntu
sudo apt-get install sox libsox-dev
# centos
sudo yum install sox sox-devel

# Install ffmpeg
# ubuntu
sudo apt-get install ffmpeg
# centos
sudo yum install ffmpeg

Use Docker

Example command to build a docker image from Dockerfile provided.

docker build -t inspiremusic .

Example command to start the docker container in interactive mode.

docker run -ti --gpus all -v .:/workspace/InspireMusic inspiremusic

Use Docker Compose

Example command to build a docker compose environment and docker image from the docker-compose.yml file.

docker compose up -d --build

Example command to attach to the docker container in interactive mode.

docker exec -ti inspire-music bash

Quick Start

an example command for music generation infer.

cd InspireMusic
mkdir -p pretrained_models

# Download models
# ModelScope
git clone https://www.modelscope.cn/iic/InspireMusic-1.5B-Long.git pretrained_models/InspireMusic-1.5B-Long
# HuggingFace
git clone https://huggingface.co/FunAudioLLM/InspireMusic-1.5B-Long.git pretrained_models/InspireMusic-1.5B-Long

cd examples/music_generation
# run a quick inference example
sh infer_1.5b_long.sh

an example running script to run music generation task.

cd InspireMusic/examples/music_generation/
sh run.sh

Inference

Text-to-music Task

Example script for text-to-music task.

cd examples/music_generation
# with flow matching, use one-line command to get a quick try
python -m inspiremusic.cli.inference

# custom the config like the following one-line command
python -m inspiremusic.cli.inference --task text-to-music -m "InspireMusic-1.5B-Long" -g 0 -t "Experience soothing and sensual instrumental jazz with a touch of Bossa Nova, perfect for a relaxing restaurant or spa ambiance." -c intro -s 0.0 -e 30.0 -r "exp/inspiremusic" -o output -f wav 

# without flow matching, use one-line command to get a quick try
python -m inspiremusic.cli.inference --task text-to-music -g 0 -t "Experience soothing and sensual instrumental jazz with a touch of Bossa Nova, perfect for a relaxing restaurant or spa ambiance." --fast True
from inspiremusic.cli.inference import InspireMusicModel, env_variables
if __name__ == "__main__":
  env_variables()
  model = InspireMusicModel(model_name = "InspireMusic-Base")
  model.inference("text-to-music", "Experience soothing and sensual instrumental jazz with a touch of Bossa Nova, perfect for a relaxing restaurant or spa ambiance.")

Music Continuation Task

Example script for music continuation task.

cd examples/music_generation
# with flow matching
python -m inspiremusic.cli.inference --task continuation -g 0 -a audio_prompt.wav
# without flow matching
python -m inspiremusic.cli.inference --task continuation -g 0 -a audio_prompt.wav --fast True
from inspiremusic.cli.inference import InspireMusicModel
from inspiremusic.cli.inference import env_variables
if __name__ == "__main__":
  env_variables()
  model = InspireMusicModel(model_name = "InspireMusic-Base")
  # just use audio prompt
  model.inference("continuation", None, "audio_prompt.wav")
  # use both text prompt and audio prompt
  model.inference("continuation", "Continue to generate jazz music.", "audio_prompt.wav")

Models

You may download our pretrained InspireMusic models for music generation.

# use git to download models,please make sure git lfs is installed.
mkdir -p pretrained_models
git clone https://www.modelscope.cn/iic/InspireMusic.git pretrained_models/InspireMusic

Available Models

Currently, we open source the music generation models support 24KHz mono and 48KHz stereo audio. The table below presents the links to the ModelScope and Huggingface model hub.

Model name Model Links Remarks
InspireMusic-Base-24kHz model model Pre-trained Music Generation Model, 24kHz mono, 30s
InspireMusic-Base model model Pre-trained Music Generation Model, 48kHz, 30s
InspireMusic-1.5B-24kHz model model Pre-trained Music Generation 1.5B Model, 24kHz mono, 30s
InspireMusic-1.5B model model Pre-trained Music Generation 1.5B Model, 48kHz, 30s
InspireMusic-1.5B-Long model model Pre-trained Music Generation 1.5B Model, 48kHz, support long-form music generation up to several minutes
InspireSong-1.5B model model Pre-trained Song Generation 1.5B Model, 48kHz stereo
InspireAudio-1.5B model model Pre-trained Audio Generation 1.5B Model, 48kHz stereo
Wavtokenizer[1] (75Hz) [![model](https://img.shield

Core symbols most depended-on inside this repo

load
called by 44
inspiremusic/cli/model.py
close
called by 14
inspiremusic/utils/tokenizer_utils.py
update
called by 13
inspiremusic/dataset/dataset.py
get_padding
called by 12
inspiremusic/utils/tokenizer_utils.py
apply
called by 12
inspiremusic/dataset/dataset.py
WNConv2d
called by 12
inspiremusic/wavtokenizer/decoder/discriminator_dac.py
embed
called by 11
inspiremusic/music_tokenizer/models.py
make_pad_mask
called by 8
inspiremusic/utils/mask.py

Shape

Method 473
Function 229
Class 154

Languages

Python100%

Modules by API surface

inspiremusic/utils/scheduler.py53 symbols
inspiremusic/music_tokenizer/models.py39 symbols
inspiremusic/wavtokenizer/encoder/quantization/core_vq.py34 symbols
inspiremusic/wavtokenizer/encoder/modules/conv.py24 symbols
inspiremusic/utils/tokenizer_utils.py24 symbols
inspiremusic/transformer/subsampling.py24 symbols
inspiremusic/utils/audio_utils.py22 symbols
inspiremusic/transformer/embedding.py20 symbols
inspiremusic/wavtokenizer/encoder/model.py19 symbols
inspiremusic/hifigan/generator.py19 symbols
inspiremusic/wavtokenizer/decoder/models.py18 symbols
inspiremusic/wavtokenizer/decoder/experiment.py17 symbols

For agents

$ claude mcp add FunMusic \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact