# Sounds and music (/ink/sound)



The ***ink* + Pixi’VN integration** introduces a "# script" that allows you to use the <DynamicLink href="/start/sound">sounds and music</DynamicLink>.

<CodeBlockTabs defaultValue="ink/start.ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink/start.ink">
      ink/start.ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="src/assets/index.ts">
      src/assets/index.ts
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink/start.ink">
    ```ink
    # play sound sfx_whoosh delay 0.1
    # play sound bgm_cheerful loop true channel bgm
    Hello, I'm a cheerful background music that will loop forever until you stop me.
    # pause sound bgm_cheerful
    I'm paused, but I can be resumed.
    # resume sound bgm_cheerful
    I'm back!
    ```
  </CodeBlockTab>

  <CodeBlockTab value="src/assets/index.ts">
    ```ts
    import generatedManifestJson from "@/assets/manifest.gen.json";
    import type { AssetsManifest } from "@drincs/pixi-vn";

    export const manifest: AssetsManifest = {
        bundles: [
            ...generatedManifestJson.bundles,
            {
                name: "audio",
                assets: [
                    {
                        alias: "bgm_cheerful",
                        src: "https://raw.githubusercontent.com/DRincs-Productions/pixi-vn-bucket/refs/heads/main/audio/bgm_cheerful.wav",
                    },
                    {
                        alias: "sfx_whoosh",
                        src: "https://raw.githubusercontent.com/DRincs-Productions/pixi-vn-bucket/refs/heads/main/audio/sfx_whoosh.wav",
                    },
                ],
            },
        ],
    };
    ```
  </CodeBlockTab>
</CodeBlockTabs>

<PixiVnExample path="ink/sound" />

## Play [#play]

You can use the `play` to <DynamicLink href="/start/sound#play">play</DynamicLink&#x3E; a sound in &#x2A;**ink***. To do this, you need to use the following syntax:

<CodeBlockTabs defaultValue="ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink">
      ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink">
    ```ink
    # play sound sfx_whoosh volume 100
    ```
  </CodeBlockTab>

  <CodeBlockTab value="CLI">
    ```txt
    # play sound <alias> [<source>] [<parameters>]

    where:
        alias = the alias to identify the sound. Use double quotes if it contains spaces.
        source (Optional) = the alias or URL of the asset to use as the sound source. If not set, `alias` will be used as the source.
        parameters (Optional) = a space-separated list of property/value pairs. If a value is a string and includes spaces, you must use double quotes.
    ```
  </CodeBlockTab>
</CodeBlockTabs>

Available `parameters` (all optional) are the properties of [`PixiVNJsonSoundPlayProps`](/jsdoc/pixi-vn-json/index/interfaces/PixiVNJsonSoundPlayProps).

<CodeBlockTabs defaultValue="ink/start.ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink/start.ink">
      ink/start.ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="src/assets/index.ts">
      src/assets/index.ts
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink/start.ink">
    ```ink
    # play sound sfx_whoosh
    Now the sfx_whoosh is singing.
    # play sound sfx_whoosh volume 100
    Now the sfx_whoosh is singing louder.
    ```
  </CodeBlockTab>

  <CodeBlockTab value="src/assets/index.ts">
    ```ts
    import generatedManifestJson from "@/assets/manifest.gen.json";
    import type { AssetsManifest } from "@drincs/pixi-vn";

    export const manifest: AssetsManifest = {
        bundles: [
            ...generatedManifestJson.bundles,
            {
                name: "audio",
                assets: [
                    {
                        alias: "bgm_cheerful",
                        src: "https://raw.githubusercontent.com/DRincs-Productions/pixi-vn-bucket/refs/heads/main/audio/bgm_cheerful.wav",
                    },
                    {
                        alias: "sfx_whoosh",
                        src: "https://raw.githubusercontent.com/DRincs-Productions/pixi-vn-bucket/refs/heads/main/audio/sfx_whoosh.wav",
                    },
                ],
            },
        ],
    };
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Pause and resume [#pause-and-resume]

To <DynamicLink href="/start/sound#pause-and-resume">pause</DynamicLink&#x3E; a sound or a channel in &#x2A;**ink***, you can use the `pause` operation. To do this, you need to use the following syntax:

<CodeBlockTabs defaultValue="ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink">
      ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink">
    ```ink
    # pause sound bgm_cheerful
    ```
  </CodeBlockTab>

  <CodeBlockTab value="CLI">
    ```txt
    # pause <component type> <alias>

    where:
        component type = the component type to pause. Available types: `sound`, `channel`.
        alias = the alias to identify the sound or channel to pause. Use double quotes if it contains spaces.
    ```
  </CodeBlockTab>
</CodeBlockTabs>

To <DynamicLink href="/start/sound#pause-and-resume">resume</DynamicLink&#x3E; a sound or a channel in &#x2A;**ink***, you can use the `resume` operation. To do this, you need to use the following syntax:

<CodeBlockTabs defaultValue="ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink">
      ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink">
    ```ink
    # resume sound bgm_cheerful
    ```
  </CodeBlockTab>

  <CodeBlockTab value="CLI">
    ```txt
    # resume <component type> <alias>

    where:
        component type = the component type to resume. Available types: `sound`, `channel`.
        alias = the alias to identify the sound or channel to resume. Use double quotes if it contains spaces.
    ```
  </CodeBlockTab>
</CodeBlockTabs>

To pause or resume all sounds, you can use the following syntax:

```ink title="ink"
# pause all sounds
# resume all sounds
```

## Edit [#edit]

To <DynamicLink href="/start/sound#edit">edit</DynamicLink&#x3E; a sound in &#x2A;**ink***, you can use the `edit` operation. To do this, you need to use the following syntax:

<CodeBlockTabs defaultValue="ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink">
      ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink">
    ```ink
    # edit sound bgm_cheerful volume 50
    ```
  </CodeBlockTab>

  <CodeBlockTab value="CLI">
    ```txt
    # edit sound <alias> [<parameters>]

    where:
        alias = the alias to identify the sound to edit. Use double quotes if it contains spaces.
        parameters (Optional) = a space-separated list of property/value pairs. If a value is a string and includes spaces, you must use double quotes.
    ```
  </CodeBlockTab>
</CodeBlockTabs>

Available `parameters` (all optional) are the properties of [`PixiVNJsonSoundEditProps`](/jsdoc/pixi-vn-json/index/interfaces/PixiVNJsonSoundEditProps).

```ink title="ink"
# edit sound bgm_cheerful volume 50
# edit sound bgm_cheerful loop false
```

## Stop [#stop]

To <DynamicLink href="/start/sound#stop">stop</DynamicLink&#x3E; a sound in &#x2A;**ink***, you can use the `stop` operation. To do this, you need to use the following syntax:

<CodeBlockTabs defaultValue="ink">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="ink">
      ink
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="CLI">
      CLI
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="ink">
    ```ink
    # stop sound bgm_cheerful
    ```
  </CodeBlockTab>

  <CodeBlockTab value="CLI">
    ```txt
    # stop sound <alias>

    where:
        alias = the alias to identify the sound to stop. Use double quotes if it contains spaces.
    ```
  </CodeBlockTab>
</CodeBlockTabs>

To stop all sounds, you can use the following syntax:

```ink title="ink"
# stop all sounds
```
