> For the complete documentation index, see [llms.txt](https://infinitypbr.gitbook.io/magic-pig-games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/voices/code-examples.md).

# Code Examples

## Creating a `Speak()` method

While there are many ways to play audio, using the `PlayClip` method on the `Voice.cs` script is an easy way to get audio to play. You can create a very simple `Speak()` method to use as well:

```csharp
public void Speak(string line, emotion = "", index = -1) 
    => voice.PlayClip(audioSource, line, emotion, index);
```

If this is attached to your `Player()` class, you can then easily get your players to speak with something like:

```csharp
// Play a random clip form "Level Up", ignoring emotions
player.Speak("LevelUp");

// Play a random clip from "Let's Get Out of Here" with the "Scared" emotion
player.Speak("LetsGetOutOfHere", "Scared");

// Play a specific clip from "Great Loot", ignoring emotions
player.Spkea("GreatLoot", "", 2);
```
