csm README

The project's README from github.com/SesameAILabs/csm. As one markdown file: README.md.

CSM

2025/05/20 - CSM is availabile natively in Hugging Face Transformers 🤗 as of version 4.52.1, more info available in our model repo

2025/03/13 - We are releasing the 1B CSM variant. The checkpoint is hosted on Hugging Face.


CSM (Conversational Speech Model) is a speech generation model from Sesame that generates RVQ audio codes from text and audio inputs. The model architecture employs a Llama backbone and a smaller audio decoder that produces Mimi audio codes.

A fine-tuned variant of CSM powers the interactive voice demo shown in our blog post.

A hosted Hugging Face space is also available for testing audio generation.

Requirements

Setup

git clone [email protected]:SesameAILabs/csm.git
cd csm
python3.10 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Disable lazy compilation in Mimi
export NO_TORCH_COMPILE=1

# You will need access to CSM-1B and Llama-3.2-1B
huggingface-cli login

Windows Setup

The triton package cannot be installed in Windows. Instead use pip install triton-windows.

Quickstart

This script will generate a conversation between 2 characters, using a prompt for each character.

python run_csm.py

Usage

If you want to write your own applications with CSM, the following examples show basic usage.

Generate a sentence

This will use a random speaker identity, as no prompt or context is provided.

from generator import load_csm_1b
import torchaudio
import torch

if torch.backends.mps.is_available():
    device = "mps"
elif torch.cuda.is_available():
    device = "cuda"
else:
    device = "cpu"

generator = load_csm_1b(device=device)

audio = generator.generate(
    text="Hello from Sesame.",
    speaker=0,
    context=[],
    max_audio_length_ms=10_000,
)

torchaudio.save("audio.wav", audio.unsqueeze(0).cpu(), generator.sample_rate)

Generate with context

CSM sounds best when provided with context. You can prompt or provide context to the model using a Segment for each speaker's utterance.

NOTE: The following example is instructional and the audio files do not exist. It is intended as an example for using context with CSM.

from generator import Segment

speakers = [0, 1, 0, 0]
transcripts = [
    "Hey how are you doing.",
    "Pretty good, pretty good.",
    "I'm great.",
    "So happy to be speaking to you.",
]
audio_paths = [
    "utterance_0.wav",
    "utterance_1.wav",
    "utterance_2.wav",
    "utterance_3.wav",
]

def load_audio(audio_path):
    audio_tensor, sample_rate = torchaudio.load(audio_path)
    audio_tensor = torchaudio.functional.resample(
        audio_tensor.squeeze(0), orig_freq=sample_rate, new_freq=generator.sample_rate
    )
    return audio_tensor

segments = [
    Segment(text=transcript, speaker=speaker, audio=load_audio(audio_path))
    for transcript, speaker, audio_path in zip(transcripts, speakers, audio_paths)
]
audio = generator.generate(
    text="Me too, this is some cool stuff huh?",
    speaker=1,
    context=segments,
    max_audio_length_ms=10_000,
)

torchaudio.save("audio.wav", audio.unsqueeze(0).cpu(), generator.sample_rate)

FAQ

Does this model come with any voices?

The model open-sourced here is a base generation model. It is capable of producing a variety of voices, but it has not been fine-tuned on any specific voice.

Can I converse with the model?

CSM is trained to be an audio generation model and not a general-purpose multimodal LLM. It cannot generate text. We suggest using a separate LLM for text generation.

Does it support other languages?

The model has some capacity for non-English languages due to data contamination in the training data, but it likely won't do well.

Misuse and abuse ⚠️

This project provides a high-quality speech generation model for research and educational purposes. While we encourage responsible and ethical use, we explicitly prohibit the following:

By using this model, you agree to comply with all applicable laws and ethical guidelines. We are not responsible for any misuse, and we strongly condemn unethical applications of this technology.


Authors

Johan Schalkwyk, Ankit Kumar, Dan Lyth, Sefik Emre Eskimez, Zack Hodari, Cinjon Resnick, Ramon Sanabria, Raven Jiang, and the Sesame team.

csm (SesameAILabs/csm)

Searching Database…

14.7K ·GitHub
这是什么?CSM(对话式语音模型)是 Sesame 推出的语音生成模型,它接收文本和音频输入,通过生成 RVQ 音频编码输出语音,采用 Llama 主干网络加上一个较小的音频解码器。
这是聊天机器人,还是只是一个语音生成器?它纯粹是一个语音生成模型,不是对话式聊天机器人:它无法生成文字,因此如果想实现真正的对话,需要搭配一个单独的大语言模型(LLM)。
我该如何让它运行起来?克隆代码仓库并运行快速入门脚本,脚本会根据文本提示生成两个角色之间的对话;如需自定义使用,可以直接调用模型生成单句,或通过 Segment 对象添加上下文来生成语音。
运行它之前需要准备什么?一块兼容 CUDA 的 GPU(已在 CUDA 12.4/12.6 上测试)、推荐使用 Python 3.10、部分音频操作需要 ffmpeg,以及 Hugging Face 对 Llama-3.2-1B 和 CSM-1B 检查点的访问权限。在 Windows 上,必须使用 pip install triton-windows 代替常规的 triton 包。
它自带现成的声音吗?支持其他语言吗?都没有。它是一个未针对任何特定声音微调的基础模型,因此除非提供提示词或上下文,否则会得到随机声音;非英语语言只能勉强处理,原因是训练数据中偶然混入了少量相关内容,而非有意训练。
它真的需要独立 GPU 才能运行吗?是的,该项目需要兼容 CUDA 的 GPU;目前仅在 CUDA 12.4 和 12.6 上验证过。
为什么 CSM 在音频生成中使用 Llama 主干网络?CSM 将基于 Llama 的主干网络与一个较小的音频解码器结合,后者输出 Mimi 音频编码,使其能够像语言模型预测词元一样,基于文本和此前的音频上下文来生成语音。
我能用 CSM 克隆真人的声音吗?不能。该项目明确禁止冒充或欺诈,也就是说,未经本人同意生成模仿真实个人的语音,违反了其明确声明的使用政策。
不用在本地安装任何东西,也能试用 CSM 吗?可以。有一个托管在 Hugging Face 上的 Space 可供测试音频生成;另外,Sesame 博客文章中展示的互动语音演示,由 CSM 的一个微调版本驱动。
What are similar projects?bark, dia, ChatTTS, Speech, fish-speech, DramaBox, FireRedAudio, VoxCPM
Size
<0.1 MB
Stars
14.7K
Updated
CommitMay 27
Age
1y
Commits · 90 Days