# Sonauto V2

> Replace sections of an existing audio with newly generated content


## Overview

- **Endpoint**: `https://fal.run/sonauto/v2/inpaint`
- **Model ID**: `sonauto/v2/inpaint`
- **Category**: text-to-audio
- **Kind**: inference
**Tags**: music, text-to-music, text-to-audio



## Pricing

- **Price**: $0.075 per generations

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:


- **`tags`** (`list<string>`, _optional_):
  Tags/styles of the music to generate. You can view a list of all available tags at https://sonauto.ai/tag-explorer.
  - Array of string
  - Examples: ["2020s","dance pop","pop rock","indie pop","bubblegum pop","synthpop","teen pop","electropop"]

- **`lyrics_prompt`** (`string`, _required_):
  The lyrics sung in the generated song. An empty string will generate an instrumental track.
  - Examples: "[Chorus]\nPigs are soaring in the sky\nWings of bacon flying by\n"

- **`seed`** (`integer`, _optional_):
  The seed to use for generation. Will pick a random seed if not provided. Repeating a request with identical parameters (must use lyrics and tags, not prompt) and the same seed will generate the same song.
  - Range: `-9223372036854776000` to `9223372036854776000`

- **`prompt_strength`** (`float`, _optional_):
  Controls how strongly your prompt influences the output. Greater values adhere more to the prompt but sound less natural. (This is CFG.) Default value: `2`
  - Default: `2`
  - Range: `1.4` to `3.1`

- **`balance_strength`** (`float`, _optional_):
  Greater means more natural vocals. Lower means sharper instrumentals. We recommend 0.7. Default value: `0.7`
  - Default: `0.7`
  - Range: `0` to `1`

- **`num_songs`** (`integer`, _optional_):
  Generating 2 songs costs 1.5x the price of generating 1 song. Also, note that using the same seed may not result in identical songs if the number of songs generated is changed. Default value: `1`
  - Default: `1`
  - Range: `1` to `2`

- **`output_format`** (`OutputFormatEnum`, _optional_):
   Default value: `"wav"`
  - Default: `"wav"`
  - Options: `"flac"`, `"mp3"`, `"wav"`, `"ogg"`, `"m4a"`

- **`output_bit_rate`** (`Enum`, _optional_):
  The bit rate to use for mp3 and m4a formats. Not available for other formats.
  - Options: `128`, `192`, `256`, `320`

- **`audio_url`** (`string`, _required_):
  The URL of the audio file to alter. Must be a valid publicly accessible URL.
  - Examples: "https://cdn.sonauto.ai/generations2_altformats/audio_c5e63f7c-fc79-4322-808d-c09911af4713.wav"

- **`sections`** (`list<InpaintSection>`, _required_):
  List of sections to inpaint. Currently, only one section is supported so the list length must be 1.
  - Array of InpaintSection
  - Examples: [{"end":9.45,"start":0}]

- **`selection_crop`** (`boolean`, _optional_):
  Crop to the selected region
  - Default: `false`



**Required Parameters Example**:

```json
{
  "lyrics_prompt": "[Chorus]\nPigs are soaring in the sky\nWings of bacon flying by\n",
  "audio_url": "https://cdn.sonauto.ai/generations2_altformats/audio_c5e63f7c-fc79-4322-808d-c09911af4713.wav",
  "sections": [
    {
      "end": 9.45,
      "start": 0
    }
  ]
}
```

**Full Example**:

```json
{
  "tags": [
    "2020s",
    "dance pop",
    "pop rock",
    "indie pop",
    "bubblegum pop",
    "synthpop",
    "teen pop",
    "electropop"
  ],
  "lyrics_prompt": "[Chorus]\nPigs are soaring in the sky\nWings of bacon flying by\n",
  "prompt_strength": 2,
  "balance_strength": 0.7,
  "num_songs": 1,
  "output_format": "wav",
  "audio_url": "https://cdn.sonauto.ai/generations2_altformats/audio_c5e63f7c-fc79-4322-808d-c09911af4713.wav",
  "sections": [
    {
      "end": 9.45,
      "start": 0
    }
  ]
}
```


### Output Schema

The API returns the following output format:

- **`audio`** (`list<File>`, _required_):
  The generated audio files.
  - Array of File
  - Examples: {"file_size":16777294,"file_name":"sonauto.wav","content_type":"audio/wav","url":"https://cdn.sonauto.ai/generations2_altformats/audio_9a480c86-a3c0-46e5-bfb0-c0cd6e2fdbc6.wav"}

- **`seed`** (`integer`, _required_):
  The seed used for generation. This can be used to generate an identical song by passing the same parameters with this seed in a future request.
  - Examples: 42



**Example Response**:

```json
{
  "audio": {
    "file_size": 16777294,
    "file_name": "sonauto.wav",
    "content_type": "audio/wav",
    "url": "https://cdn.sonauto.ai/generations2_altformats/audio_9a480c86-a3c0-46e5-bfb0-c0cd6e2fdbc6.wav"
  },
  "seed": 42
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/sonauto/v2/inpaint \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "lyrics_prompt": "[Chorus]\nPigs are soaring in the sky\nWings of bacon flying by\n",
     "audio_url": "https://cdn.sonauto.ai/generations2_altformats/audio_c5e63f7c-fc79-4322-808d-c09911af4713.wav",
     "sections": [
       {
         "end": 9.45,
         "start": 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(
    "sonauto/v2/inpaint",
    arguments={
        "lyrics_prompt": "[Chorus]
    Pigs are soaring in the sky
    Wings of bacon flying by
    ",
        "audio_url": "https://cdn.sonauto.ai/generations2_altformats/audio_c5e63f7c-fc79-4322-808d-c09911af4713.wav",
        "sections": [{
            "end": 9.45,
            "start": 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("sonauto/v2/inpaint", {
  input: {
    lyrics_prompt: "[Chorus]
  Pigs are soaring in the sky
  Wings of bacon flying by
  ",
    audio_url: "https://cdn.sonauto.ai/generations2_altformats/audio_c5e63f7c-fc79-4322-808d-c09911af4713.wav",
    sections: [{
      end: 9.45,
      start: 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/sonauto/v2/inpaint)
- [API Documentation](https://fal.ai/models/sonauto/v2/inpaint/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=sonauto/v2/inpaint)

### 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)
