# Change Voice on AI

This script ensures that any unit with the specified classname that spawns during the mission will automatically have its voice changed to the one defined in the script.

{% stepper %}
{% step %}

### Creating a sqf file

Start of by created a **init.sqf** then copy & paste this code in there:

```sqf
[] execVM "SetVoiceOnSpawn.sqf";
```

{% endstep %}

{% step %}

### Creating the script

So now create a new file called **SetVoiceOnSpawn.sqf** open it and paste this code in there:

```sqf
[ "CAManBase", "InitPost", {
	params ["_unit"];
	if (typeOf _unit == "CLASSNAME") then {
		_unit setSpeaker "VOICE"
	};
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
```

{% endstep %}

{% step %}

### Choose unit and voice

Open **SetVoiceOnSpawn.sqf** and find the section labeled `"CLASSNAME"`. Replace `"CLASSNAME"` with the classname of the unit whose voice you want to change.

Next, locate the section labeled `"VOICE"`. Replace `"VOICE"` with the desired voice for the unit. You can refer to the list of available voices under [**Speakers Available**](https://community.bistudio.com/wiki/setSpeaker#Notes) to choose a suitable voice.
{% endstep %}
{% endstepper %}


---

# 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://kaarlos.gitbook.io/arma3-documentation/snippets-and-scripts/change-voice-on-ai.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.
