VERC: Voice API in SDK 2.2 Last edited 22 years ago2002-01-29 22:08:00 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

This article was recovered from an archive and needs to be reviewed

  1. The formatting may be incorrect as it was automatically converted to WikiCode from HTML, it needs to be revised and reformatted
  2. Some information may be out of date as it was written before Half-Life was available on Steam
  3. After the article is re-formatted and updated for Steam HL, remove this notice
  4. Please do not remove the archive notice from the bottom of the article.
  5. Some archive articles are no longer useful, or they duplicate information from other tutorials and entity guides. In this case, delete the page after merging any relevant information into other pages. Contact an admin to delete a page.

HL SDK 2.2

This article was originally made available as part of version 2.2 of the Half-Life SDK. As such, all limitations, restrictions, license agreements, copyrights and trademarks from the original document apply here (Link: index.php?doc=1011658625-34537700) .

Voice API

In this version of the Half-Life engine and SDK, we have added the ability for players to speak to each other while playing on a server. MOD authors have full control over which players are allowed to speak to each other.

There are two new functions in enginefuncs_s you can use to find out which players are allowed to talk to each other and to change who can talk to each other.

qboolean (*pfnVoice_GetClientListening)(int iReceiver, int iSender);

Use pfnVoice_GetClientListening to ask the engine if a certain player is currently allowed to hear another player's speech.

qboolean (*pfnVoice_SetClientListening)(int iReceiver, int iSender, qboolean bListen);
Use pfnVoice_SetClientListening to tell the engine if a certain player is allowed to hear another player's speech.

These two functions are all that the engine exposes to the MOD to control voice. Most of the code involved in adding voice to a MOD is in the form of HUD elements and such. A good way to add voice to your mod and have its functionality appear familiar to players is to use the code we have for Half-Life Deathmatch in the SDK. We describe the UI code below.

On the client, there is a new function a MOD can implement that takes this form:

void DLLEXPORT HUD_VoiceStatus(int entindex, qboolean bTalking)

The engine calls this when it detects that players in the game have started or stopped talking. Entity indices are usually passed into this function, but there are two special entity indices that are passed in.

SDK MOD Code

This section describes the SDK code that is available to MOD authors to use as a starting point for adding voice to their MOD.

In the MOD game DLL, we have a manager class called CVoiceGameMgr in the game_shared/voice_gamemgr.h file which: To use CVoiceGameMgr , derive a class from IVoiceGameMgrHelper and implement the CanPlayerHearPlayer function so CVoiceGameMgr can ask your MOD which players are allowed to hear each other. Then call its Update , ClientConnected , and ClientCommand functions from your CGameRules class in the corresponding callbacks ( Update corresponds to Think ).

Most of the game code that we have added to the SDK deals with presentation of UI elements for players to control who they want to hear. The core of this code is in the CVoiceStatus class in the game_shared/voice_status.h file. CVoiceStatus manages a list of who is currently speaking in the game and displays icons for the speakers on the screen. It also manages, saves, and loads a list of which players the local player has banned from hearing. This allows people to completely turn off players that abuse the voice functionality.

Use GetClientVoiceMgr() to get a pointer to a global instance of this class. Then call its member functions from the appropriate places in the rest of your client DLL code. You can find all the places CVoiceStatus is called from other code by doing a Find In Files through the client DLL files and searching for " GetClientVoiceMgr ".

CVoiceStatus makes use of several resources for the HUD display if they exist:

Console Variables and Commands of Interest

Server Console Variables/Commands
sv_voicecodec - The game DLL or the server admin can set this cvar to "", in which case none of the clients will be able to speak to each other or send voice data to the server. Client Console Variables/Commands
  1. Set voice_recordtofile to 1.
  2. Press your voice record button and say something like "testing 1, 2, 3" into the microphone.
  3. Set voice_recordtofile back to 0.
  4. You should now have a new file called voice_micdata.wav sitting in your executables directory. Rename this to voice_input.wav .
  5. From now on, if you set voice_inputfromfile to 1, it will send the sound data in voice_input.wav to the server rather than recording what you're saying into the microphone. Voice_inputfromfile and voice_loopback are usually used hand-in-hand.
This article was originally published on the Valve Editing Resource Collective (VERC).
TWHL only archives articles from defunct websites. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.