# CSM-1B

> CSM (Conversational Speech Model) is a speech generation model from Sesame that generates RVQ audio codes from text and audio inputs.


## Overview

- **Endpoint**: `https://fal.run/fal-ai/csm-1b`
- **Model ID**: `fal-ai/csm-1b`
- **Category**: text-to-audio
- **Kind**: inference
**Tags**: conversational, text to speech



## Pricing

- **Price**: $0.03 per 1000 characters

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`scene`** (`list<Turn>`, _required_):
  The text to generate an audio from.
  - Array of Turn
  - Examples: [{"text":"Hey how are you doing.","speaker_id":0},{"text":"Pretty good, pretty good.","speaker_id":1},{"text":"I'm great, so happy to be speaking to you.","speaker_id":0}]

- **`context`** (`list<Speaker>`, _optional_):
  The context to generate an audio from.
  - Array of Speaker
  - Examples: [{"prompt":"like revising for an exam I'd have to try and like keep up the momentum because I'd start really early I'd be like okay I'm gonna start revising now and then like you're revising for ages and then I just like start losing steam I didn't do that for the exam we had recently to be fair that was a more of a last minute scenario but like yeah I'm trying to like yeah I noticed this yesterday that like Mondays I sort of start the day with this not like a panic but like a","audio_url":"https://huggingface.co/spaces/sesame/csm-1b/resolve/main/prompts/conversational_a.wav","speaker_id":0},{"prompt":"like a super Mario level. Like it's very like high detail. And like, once you get into the park, it just like, everything looks like a computer game and they have all these, like, you know, if, if there's like a, you know, like in a Mario game, they will have like a question block. And if you like, you know, punch it, a coin will come out. So like everyone, when they come into the park, they get like this little bracelet and then you can go punching question blocks around.","audio_url":"https://huggingface.co/spaces/sesame/csm-1b/resolve/main/prompts/conversational_b.wav","speaker_id":1}]



**Required Parameters Example**:

```json
{
  "scene": [
    {
      "text": "Hey how are you doing.",
      "speaker_id": 0
    },
    {
      "text": "Pretty good, pretty good.",
      "speaker_id": 1
    },
    {
      "text": "I'm great, so happy to be speaking to you.",
      "speaker_id": 0
    }
  ]
}
```

**Full Example**:

```json
{
  "scene": [
    {
      "text": "Hey how are you doing.",
      "speaker_id": 0
    },
    {
      "text": "Pretty good, pretty good.",
      "speaker_id": 1
    },
    {
      "text": "I'm great, so happy to be speaking to you.",
      "speaker_id": 0
    }
  ],
  "context": [
    {
      "prompt": "like revising for an exam I'd have to try and like keep up the momentum because I'd start really early I'd be like okay I'm gonna start revising now and then like you're revising for ages and then I just like start losing steam I didn't do that for the exam we had recently to be fair that was a more of a last minute scenario but like yeah I'm trying to like yeah I noticed this yesterday that like Mondays I sort of start the day with this not like a panic but like a",
      "audio_url": "https://huggingface.co/spaces/sesame/csm-1b/resolve/main/prompts/conversational_a.wav",
      "speaker_id": 0
    },
    {
      "prompt": "like a super Mario level. Like it's very like high detail. And like, once you get into the park, it just like, everything looks like a computer game and they have all these, like, you know, if, if there's like a, you know, like in a Mario game, they will have like a question block. And if you like, you know, punch it, a coin will come out. So like everyone, when they come into the park, they get like this little bracelet and then you can go punching question blocks around.",
      "audio_url": "https://huggingface.co/spaces/sesame/csm-1b/resolve/main/prompts/conversational_b.wav",
      "speaker_id": 1
    }
  ]
}
```


### Output Schema

The API returns the following output format:

- **`audio`** (`File | string`, _required_):
  The generated audio.
  - One of: File | string



**Example Response**:

```json
{
  "audio": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019
  }
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/csm-1b \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "scene": [
       {
         "text": "Hey how are you doing.",
         "speaker_id": 0
       },
       {
         "text": "Pretty good, pretty good.",
         "speaker_id": 1
       },
       {
         "text": "I'm great, so happy to be speaking to you.",
         "speaker_id": 0
       }
     ]
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/csm-1b",
    arguments={
        "scene": [{
            "text": "Hey how are you doing.",
            "speaker_id": 0
        }, {
            "text": "Pretty good, pretty good.",
            "speaker_id": 1
        }, {
            "text": "I'm great, so happy to be speaking to you.",
            "speaker_id": 0
        }]
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/csm-1b", {
  input: {
    scene: [{
      text: "Hey how are you doing.",
      speaker_id: 0
    }, {
      text: "Pretty good, pretty good.",
      speaker_id: 1
    }, {
      text: "I'm great, so happy to be speaking to you.",
      speaker_id: 0
    }]
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/csm-1b)
- [API Documentation](https://fal.ai/models/fal-ai/csm-1b/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/csm-1b)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
