### Running the CSM Conversational Quickstart (Bash) Source: https://github.com/sesameailabs/csm/blob/main/README.md This simple Bash command executes the run_csm.py script, which is designed to demonstrate CSM's ability to generate a conversation between two characters. It serves as a rapid test to confirm the environment setup and basic model functionality. ```bash python run_csm.py ``` -------------------------------- ### Setting Up the CSM Development Environment (Bash) Source: https://github.com/sesameailabs/csm/blob/main/README.md This snippet provides the necessary Bash commands to prepare the local development environment for the CSM project. It includes cloning the repository, creating and activating a Python virtual environment, installing required packages from requirements.txt, disabling lazy compilation for the Mimi library, and logging into Hugging Face CLI to access model checkpoints. ```bash git clone git@github.com: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 ``` -------------------------------- ### Generating Context-Aware Speech with CSM (Python) Source: https://github.com/sesameailabs/csm/blob/main/README.md This Python example illustrates how to leverage conversational context to generate more coherent speech with CSM. It constructs a list of Segment objects, each encapsulating a previous utterance's text, speaker, and audio, which are then passed to the generate method. This allows the model to condition its output on the preceding dialogue, though the example's audio files are instructional placeholders. ```python 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) ``` -------------------------------- ### Generating a Single Sentence Audio with CSM (Python) Source: https://github.com/sesameailabs/csm/blob/main/README.md This Python code demonstrates how to generate speech for a given text using the CSM model without any prior conversational context. It automatically detects and utilizes the best available device (MPS, CUDA, or CPU), loads the csm_1b generator, and saves the synthesized audio to a WAV file. ```python 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) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.