SAO-Instruct is a model based on Stable Audio Open capable of editing audio clips using any free-form natural language instruction. To train our model, we create a dataset of audio editing triplets (input audio, edit instruction, output audio) using Prompt-to-Prompt, DDPM inversion, and a manual editing pipeline. Although partially trained on synthetic data, our model generalizes well to real in-the-wild audio clips and unseen edit instructions.
Inference
To get started, clone the repository and install the dependencies:
Use the following script to perform inference with SAO-Instruct weights from 🤗 Hugging Face. When
encode_audio
is set to
True
, the provided audio is encoded into the latent space and used as a starting point for generation. You can control the amount of noise added to the encoded audio using the
encoded_audio_noise
parameter. Experiment with different configurations to achieve optimal results.
import torch
from IPython.display import Audio, display
from model.sao_instruct import SAOInstruct
device = "cuda"if torch.cuda.is_available() else"cpu"
model = SAOInstruct.from_pretrained("disco-eth/sao-instruct").eval().to(device)
audio_path = "path/to/audio.wav"
edited_clips = model.edit_audio(
instructions=["add a cat meowing"],
audio_path=audio_path,
encode_audio=True,
cfg_scale=6,
encoded_audio_noise=4
)
display(Audio(audio_path))
for clip in edited_clips:
display(Audio(clip, rate=model.sample_rate, normalize=False))
Data Generation
The required files to generate audio editing triplets are in the
dataset/
folder.
Prompt Generation
The script
generate_prompts.py
can be used for prompt generation. It accepts a
.jsonl
file as input in the following form:
{"caption":"Audio Caption","metadata":{}}
This input
.jsonl
file can be created using the
prepare_captions.py
script for AudioCaps, WavCaps, and AudioSetSL. If you download audio clips from captioning datasets (e.g., if you want to use DDPM inversion for paired sample generation), the
metadata
field can be used to match them to their specific filename. The output of this script is a
.jsonl
file that includes processed prompts, containing the input caption, edit instruction, and output caption.
Paired Sample Generation
Prompt-to-Prompt
After generating prompts, you can use Prompt-to-Prompt to generate a synthetic dataset of edited audio pairs.
The Prompt-to-Prompt pipeline consists of two parts:
Candidate Search: Searching for ideal candidates (CFG, seed) for all prompts in the prompt file.
Sample Generation: Generating the edited audio pairs using the candidates found in the previous step.
Use the script
generate_candidates.py
for the candidate search.
The script
generate_samples.py
can be used for Prompt-to-Prompt sample generation (use the mode
p2p
).
We have included the source code of
Stable Audio Open
with the adaptations made for Prompt-to-Prompt in
audio_generation/p2p/stable-audio-tools
(particularly in
audio_generation/p2p/stable-audio-tools/models/transformer.py
).
You can install its requirements using:
Make sure that the
k_diffusion
package is configured to use the same starting noise. Change the function
sample_dpmpp_3m_sde
in the
k_diffusion/sampling.py
file to:
if eta:
noise = noise_sampler(sigmas[i], sigmas[i + 1])[0].unsqueeze(dim=0)
noise = noise.repeat(x.shape[0], 1, 1)
x = x + noise * sigmas[i + 1] * (-2 * h * eta).expm1().neg().sqrt() * s_noise
sao-instruct huggingface.co is an AI model on huggingface.co that provides sao-instruct's model effect (), which can be used instantly with this disco-eth sao-instruct model. huggingface.co supports a free trial of the sao-instruct model, and also provides paid use of the sao-instruct. Support call sao-instruct model through api, including Node.js, Python, http.
sao-instruct huggingface.co is an online trial and call api platform, which integrates sao-instruct's modeling effects, including api services, and provides a free online trial of sao-instruct, you can try sao-instruct online for free by clicking the link below.
disco-eth sao-instruct online free url in huggingface.co:
sao-instruct is an open source model from GitHub that offers a free installation service, and any user can find sao-instruct on GitHub to install. At the same time, huggingface.co provides the effect of sao-instruct install, users can directly use sao-instruct installed effect in huggingface.co for debugging and trial. It also supports api for free installation.