Sound
You can control sounds from the game as well as playing external sound files. Below you will find an overview of different functions to play speech recordings and audio from the GTA V audio bank, and a method to play a custom .WAV file from your scripts folder.
PLAY AMBIENT SPEECHES
The native function
void _PLAY_AMBIENT_SPEECH1(Ped ped, string speechName, string speechParam, int p4);
Try to use the native function to make the player character say something from the
Function.Call(Hash._PLAY_AMBIENT_SPEECH1, Game.Player.Character, "GENERIC_BYE", "SPEECH_PARAMS_FORCE", 1);
You will see that, every time you use that function, the character will say one possible variation (“bye”, “later on”, “bye now” if you use the character of Franklin) contained in the generic bye speech. If you change your character, the speech will change accordingly, although not every character has speech associated with them. For speech parameters, the easiest is to stick with
List of available speech names
APOLOGY_NO_TROUBLE
BLOCKED_GENERIC
BUMP
CHAT_RESP
CHAT_STATE
COVER_ME
COVER_YOU
DODGE
DYING_HELP
DYING_MOAN
FALL_BACK
GENERIC_BYE
GENERIC_CURSE_HIGH
GENERIC_CURSE_MED
GENERIC_FRIGHTENED_HIGH
GENERIC_FRIGHTENED_MED
GENERIC_FUCK_YOU
GENERIC_HI
GENERIC_HOWS_IT_GOING
GENERIC_INSULT_MED
GENERIC_INSULT_HIGH
GENERIC_SHOCKED_HIGH
GENERIC_SHOCKED_MED
GENERIC_THANKS
GENERIC_WAR_CRY
HOOKER_CAR_INCORRECT
HOOKER_DECLINE_SERVICE
HOOKER_DECLINED
HOOKER_DECLINED_TREVOR
HOOKER_HAD_ENOUGH
HOOKER_LEAVES_ANGRY
HOOKER_OFFER_AGAIN
HOOKER_OFFER_SERVICE
HOOKER_REQUEST
HOOKER_SECLUDED
HOOKER_STORY_REVULSION_RESP
HOOKER_STORY_SARCASTIC_RESP
HOOKER_STORY_SYMPATHETIC_RESP
KIFFLOM_GREET
KILLED_ALL
PROVOKE_TRESPASS
PURCHASE_ONLINE
RELOADING
ROLLERCOASTER_CHAT_EXCITED
ROLLERCOASTER_CHAT_NORMAL
SEX_CLIMAX
SEX_FINISHED
SEX_GENERIC
SEX_GENERIC_FEM
SEX_ORAL
SEX_ORAL_FEM
SHOOT
SHOP_BANTER
SHOP_BANTER_FRANKLIN
SHOP_BANTER_TREVOR
SHOP_BROWSE
SHOP_BROWSE_ARMOUR
SHOP_BROWSE_BIG
SHOP_BROWSE_FRANKLIN
SHOP_BROWSE_GUN
SHOP_BROWSE_MELEE
SHOP_BROWSE_TATTOO_MENU
SHOP_BROWSE_THROWN
SHOP_BROWSE_TREVOR
SHOP_CUTTING_HAIR
SHOP_GIVE_FOR_FREE
SHOP_GOODBYE
SHOP_GREET
SHOP_GREET_FRANKLIN
SHOP_GREET_MICHAEL
SHOP_GREET_SPECIAL
SHOP_GREET_TREVOR
SHOP_GREET_UNUSUAL
SHOP_HAIR_WHAT_WANT
SHOP_NICE_VEHICLE
SHOP_NO_COPS
SHOP_NO_MESSING
SHOP_NO_WEAPON
SHOP_OUT_OF_STOCK
SHOP_REMOVE_VEHICLE
SHOP_SELL
SHOP_SELL_ARMOUR
SHOP_SELL_BRAKES
SHOP_SELL_BULLETPROOF_TYRES
SHOP_SELL_COSMETICS
SHOP_SELL_ENGINE_UPGRADE
SHOP_SELL_EXHAUST
SHOP_SELL_HORN
SHOP_SELL_REPAIR
SHOP_SELL_SUSPENSION
SHOP_SELL_TRANS_UPGRADE
SHOP_SELL_TURBO
SHOP_SHOOTING
SHOP_SPECIAL_DISCOUNT
SHOP_TATTOO_APPLIED
SHOP_TRY_ON_ITEM
SHOUT_THREATEN_GANG
SHOUT_THREATEN_PED
SOLICIT_FRANKLIN
SOLICIT_FRANKLIN_RETURN
SOLICIT_MICHAEL
SOLICIT_MICHAEL_RETURN
SOLICIT_TREVOR
SOLICIT_TREVOR_RETURN
STAY_DOWN
TAKE_COVER
PLAY AMBIENT SPEECHES WITH A DIFFERENT VOICE
You can also play an ambient speech with a different voice file from the one of the character, using the function
It takes as parameter the Ped that will speak, the speech name, the voice name, the speech parameters and the last parameter is an associated integer between 0 and 4.
_PLAY_AMBIENT_SPEECH_WITH_VOICE(Ped ped, string speechName, string voiceName, string speechParam, int p5);
Here you can find a list of all speech voices, with their associated speech names and values. Try the following examples, and tweak them with other parameters.
Function.Call(Hash._PLAY_AMBIENT_SPEECH_WITH_VOICE, Game.Player.Character, "GENERIC_BYE", "A_F_M_BEVHILLS_01_WHITE_FULL_01", "SPEECH_PARAMS_FORCE", 1);
Function.Call(Hash._PLAY_AMBIENT_SPEECH_WITH_VOICE, Game.Player.Character, "GENERIC_INSULT_HIGH", "S_M_Y_SHERIFF_01_WHITE_FULL_01", "SPEECH_PARAMS_FORCE_SHOUTED", 0);
PLAY PAIN SOUNDS
In addition to ambient speech, you can also play “pain” sounds. The native function
Function.Call(Hash.PLAY_PAIN, Game.Player.Character, 6, 0, 0);
You can disable and enable these sounds for each character using the native
Function.Call(Hash.DISABLE_PED_PAIN_AUDIO, Game.Player.Character , true);
PLAY SOUND FILES FROM GTA V SOUND BANK
You can also play a sound file from an audio bank of GTA V sound files. To do that you first load the audio bank, then you use the native function
//load the audio bank
while (!Function.Call<bool>(Hash.REQUEST_SCRIPT_AUDIO_BANK, "Michael_2_Acid_Bath", 0, -1)){ Wait(100);}
//play the audio file
Function.Call(Hash.PLAY_SOUND_FROM_ENTITY, -1, "ACID_BATH_FALL", Game.Player.Character, "MICHAEL_2_SOUNDS", 0, 0);
PLAY EXTERNAL SOUND FILES
Finally you can play an external sound file by adding a .wav file in your Scripts folder and using the SoundPlayer object. SoundPlayer is simple but limited and only accepts .wav files. To use it, first add using System.Media at the very top of your code, to import the reference.using System.Media
Create a new sound player as a global variable and load the file by adding the path to your .wav in the Script folder:
SoundPlayer player = new SoundPlayer("./scripts/myAudioFile.wav");
player.Load();
And on key press you can use play and stop to control playback
//play
player.Play();
//stop
player.Stop()