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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/voices/code-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
