Skip to Content
DocsVoicereactAPI Reference

API Reference

Complete reference for all public VoiceReact APIs.

Core Components

VoiceReactController

High-level gameplay API for voice detection. Main component for player voice input.

Namespace: Peek.VoiceReact

Inherits: MonoBehaviour

Dependencies: Automatically adds MicrophoneInputHandler component.

Properties

IsPlayerSpeaking
public bool IsPlayerSpeaking { get; }

Is the player currently speaking?

Example:

if (voiceController.IsPlayerSpeaking) { Debug.Log("Player is speaking"); }
CurrentDB
public float CurrentDB { get; }

Current audio level in decibels (-60 to 0 dB). Higher values = louder speech.

NoiseFloorDB
public float NoiseFloorDB { get; }

Background noise level in decibels. Automatically tracked and updated.

SpeechDuration
public float SpeechDuration { get; }

Duration of current speech session in seconds. Returns 0 if not speaking.

NormalizedVolume
public float NormalizedVolume { get; }

Normalized volume level (0-1) for UI displays. Automatically scales based on detected min/max volume.

IsInCooldown
public bool IsInCooldown { get; }

Is the system currently in cooldown (preventing new detections)?

TimeSinceLastSpeech
public float TimeSinceLastSpeech { get; }

Time since last speech ended in seconds. Returns 0 if currently speaking.

detectionPreset
public DetectionPreset detectionPreset { get; set; }

Current detection sensitivity preset. Can be changed at runtime.

Values:

  • DetectionPreset.VerySensitive - Horror games, detect whispers
  • DetectionPreset.Balanced - General gameplay (default)
  • DetectionPreset.LessSensitive - Noisy environments
  • DetectionPreset.Custom - Manual configuration
detectionCooldown
public float detectionCooldown { get; set; }

Cooldown period in seconds after speech ends before detecting again.

enableVolumeNormalization
public bool enableVolumeNormalization { get; set; }

Enable normalized volume calculation (0-1 range for UI).

enableNetworking
public bool enableNetworking { get; set; }

Enable network voice event broadcasting.

Events

OnSpeechStart (UnityEvent)
public UnityEvent OnSpeechStart

Fired when speech starts.

Example:

voiceController.OnSpeechStart.AddListener(OnSpeechStarted); void OnSpeechStarted() { Debug.Log("Started speaking"); }
OnSpeechEnd (UnityEvent<float>)
public UnityEvent<float> OnSpeechEnd

Fired when speech ends. Parameter is speech duration in seconds.

Example:

voiceController.OnSpeechEnd.AddListener(OnSpeechEnded); void OnSpeechEnded(float duration) { Debug.Log($"Spoke for {duration} seconds"); }
OnTranscriptionReady (UnityEvent<string>)
public UnityEvent<string> OnTranscriptionReady

Fired when speech-to-text transcription is ready. Requires Whisper integration.

OnSpeechStartAdvanced (C# Event)
public event EventHandler<VoiceReactEventArgs> OnSpeechStartAdvanced

Advanced event with detailed speech start information.

Example:

voiceController.OnSpeechStartAdvanced += HandleSpeechStart; void HandleSpeechStart(object sender, VoiceReactEventArgs e) { Debug.Log($"Speech started at {e.DecibelLevel} dB"); // Access audio data: e.AudioData }
OnSpeechEndAdvanced (C# Event)
public event EventHandler<VoiceReactEventArgs> OnSpeechEndAdvanced

Advanced event with detailed speech end information including recorded audio.

OnSpeechDataAdvanced (C# Event)
public event EventHandler<VoiceReactEventArgs> OnSpeechDataAdvanced

Fired during speech with real-time audio data. Use for live processing or visualization.

Methods

HasBeenSilentFor
public bool HasBeenSilentFor(float seconds)

Check if player has been silent for at least the specified duration.

Parameters:

  • seconds - Duration in seconds

Returns: true if silent for at least seconds, false otherwise

Example:

if (voiceController.HasBeenSilentFor(10f)) { Debug.Log("Silent for 10 seconds"); }
SetDetectionCooldown
public void SetDetectionCooldown(float seconds)

Set a cooldown period before next speech can be detected.

Parameters:

  • seconds - Cooldown duration
SetDetectionPreset
public void SetDetectionPreset(DetectionPreset preset)

Apply a detection preset programmatically.

Parameters:

  • preset - Preset to apply

Example:

voiceController.SetDetectionPreset(DetectionPreset.VerySensitive);
GetNormalizedVolume
public float GetNormalizedVolume()

Get current normalized volume (0-1) for UI displays.

Returns: Normalized volume level

GetCurrentConfig
public DetectionPresetValues.PresetConfig GetCurrentConfig()

Get current detection preset configuration values.

GetListenersWhoCanHear
public List<VoiceListener> GetListenersWhoCanHear()

Get all VoiceListeners currently hearing this player. Requires VoiceReactManager in scene.

Returns: List of listeners that can hear player

SetNetworkAdapter
public void SetNetworkAdapter(IVoiceNetworkAdapter adapter)

Set custom network adapter for multiplayer integration.

Parameters:

  • adapter - Network adapter instance (or null to disable)
GetNetworkAdapter
public IVoiceNetworkAdapter GetNetworkAdapter()

Get current network adapter.

Returns: Network adapter instance or null


VoiceListener

Makes enemies, NPCs, and game objects hear player voice based on distance and volume.

Namespace: Peek.VoiceReact

Inherits: MonoBehaviour

Requirements: VoiceReactManager must be in scene for listener to function.

Properties

CanHearPlayer
public bool CanHearPlayer { get; }

Is the listener currently hearing the player?

DistanceToPlayer
public float DistanceToPlayer { get; }

Distance to player in meters.

HeardDecibelLevel
public float HeardDecibelLevel { get; }

Decibel level when player was last heard.

EffectiveHearingRange
public float EffectiveHearingRange { get; }

Current effective hearing range based on player volume.

LastKnownPlayerPosition
public Vector3 LastKnownPlayerPosition { get; }

Last known player position when heard.

HearingRange
public float HearingRange { get; }

Base hearing range (same as baseHearingRange).

Inspector Fields

baseHearingRange
public float baseHearingRange = 10f

Base hearing range in meters (when player is at “Loud” volume).

whisperMultiplier
public float whisperMultiplier = 0.2f

Range multiplier for whisper volume. Example: 10m base * 0.2 = 2m for whispers.

normalMultiplier
public float normalMultiplier = 0.5f

Range multiplier for normal speech. Example: 10m base * 0.5 = 5m for normal.

loudMultiplier
public float loudMultiplier = 1.0f

Range multiplier for loud speech. Example: 10m base * 1.0 = 10m for loud.

shoutMultiplier
public float shoutMultiplier = 2.0f

Range multiplier for shouts. Example: 10m base * 2.0 = 20m for shouts.

requireLineOfSight
public bool requireLineOfSight = false

Require line of sight to hear player (sound blocked by walls).

occlusionLayers
public LayerMask occlusionLayers = -1

Layers that block sound when line of sight is required.

showDebugGizmos
public bool showDebugGizmos = true

Draw debug visualization in Scene view.

Events

OnPlayerHeard (UnityEvent<Vector3, float>)
public UnityEvent<Vector3, float> OnPlayerHeard

Fired when player becomes audible.

Parameters:

  • Vector3 - Player’s position
  • float - Decibel level

Example:

listener.OnPlayerHeard.AddListener(OnHeardPlayer); void OnHeardPlayer(Vector3 position, float db) { Debug.Log($"Heard at {position} with {db} dB"); }
OnPlayerLost (UnityEvent)
public UnityEvent OnPlayerLost

Fired when player becomes inaudible.

OnDecibelLevelChanged (UnityEvent<float>)
public UnityEvent<float> OnDecibelLevelChanged

Fired when decibel level changes significantly while hearing player.

Methods

UpdateHearing
public void UpdateHearing()

Update hearing status. Called automatically by VoiceReactManager. Can be called manually for custom update timing.

IsPlayerAudible
public bool IsPlayerAudible()

Check if player is currently audible (same as CanHearPlayer property).

ProcessRemotePlayerVoice
public void ProcessRemotePlayerVoice(float normalizedVolume, float distance)

Process voice from remote player over network.

Parameters:

  • normalizedVolume - Volume level (0-1)
  • distance - Distance to remote player

VoiceReactManager

Required singleton coordinator that manages all VoiceListener components.

Namespace: Peek.VoiceReact

Inherits: MonoBehaviour

Important: Must be added to scene. Use Tools > VoiceReact > Quick Setup Scene or add prefab manually.

Properties

Instance
public static VoiceReactManager Instance { get; }

Singleton instance. Returns null if not in scene.

PlayerVoice
public VoiceReactController PlayerVoice { get; }

Reference to player’s VoiceReactController.

ListenerCount
public int ListenerCount { get; }

Number of registered listeners.

LogSettings
public VoiceReactLogSettings LogSettings { get; }

Logging configuration for VoiceReact system.

Inspector Fields

onlyUpdateWhileSpeaking
public bool onlyUpdateWhileSpeaking = true

Only update listeners when player is speaking (performance optimization).

updateFrequency
public float updateFrequency = 30f

Maximum update frequency for listeners (times per second). Range: 1-60 Hz.

Methods

RegisterListener
public void RegisterListener(VoiceListener listener)

Register a VoiceListener to receive updates. Called automatically by VoiceListener.

UnregisterListener
public void UnregisterListener(VoiceListener listener)

Unregister a VoiceListener. Called automatically on destroy.

GetAllListeners
public List<VoiceListener> GetAllListeners()

Get all currently registered listeners.

GetListenersWhoCanHear
public List<VoiceListener> GetListenersWhoCanHear()

Get all listeners that can currently hear the player.

ForceUpdateListeners
public void ForceUpdateListeners()

Force immediate update of all listeners (bypasses throttling).


MicrophoneInputHandler

Low-level audio engine. Automatically managed by VoiceReactController.

Namespace: Peek.VoiceReact

Inherits: MonoBehaviour

Important: Do not add manually. Use VoiceReactController instead.

Properties

CurrentDB
public float CurrentDB { get; }

Current audio level in decibels.

NoiseFloorDB
public float NoiseFloorDB { get; }

Background noise level in decibels.

IsVoiceDetected
public bool IsVoiceDetected { get; }

Is voice currently detected?

IsProcessing
public bool IsProcessing { get; }

Is audio processing active?

Events

OnVoiceCaptureStarted
public event EventHandler<AudioCaptureEventArgs> OnVoiceCaptureStarted

Fired when voice capture begins.

OnVoiceCaptureStopped
public event EventHandler<AudioCaptureEventArgs> OnVoiceCaptureStopped

Fired when voice capture ends.

OnVoiceCaptureData
public event EventHandler<AudioCaptureEventArgs> OnVoiceCaptureData

Fired during capture with real-time audio data chunks.

Methods

ApplyDetectionSettings
public void ApplyDetectionSettings(VoiceDetectionSettings settings)

Apply custom detection settings.

GetAvailableDevices
public string[] GetAvailableDevices()

Get all available microphone devices.

SetMicrophoneDevice
public bool SetMicrophoneDevice(string deviceName)

Set microphone device to use. Cannot change while recording.

Returns: True if device was set successfully

GetCurrentDevice
public string GetCurrentDevice()

Get currently selected microphone device name.

RefreshDevices
public void RefreshDevices()

Refresh microphone device list. Call if devices were plugged/unplugged at runtime.

EnableDebugMode
public void EnableDebugMode(bool enable)

Enable/disable debug GUI overlay showing real-time audio levels.

UpdateMonitorVolume
public void UpdateMonitorVolume(float volume)

Update volume for audio monitoring (0-1).


Event Args Classes

VoiceReactEventArgs

High-level event arguments for VoiceReactController events.

Namespace: Peek.VoiceReact

Inherits: EventArgs

Properties

DecibelLevel
public float DecibelLevel { get; }

Current audio level in decibels.

Duration
public float Duration { get; }

Speech duration in seconds (OnSpeechEnd only).

NormalizedVolume
public float NormalizedVolume { get; }

Normalized volume (0-1) for UI displays.

Transcription
public string Transcription { get; }

Speech-to-text transcription (if STT enabled).

AudioData
public float[] AudioData { get; }

Raw audio samples (may be null).

SampleRate
public int SampleRate { get; }

Audio sample rate in Hz.


AudioCaptureEventArgs

Low-level event arguments for MicrophoneInputHandler events.

Namespace: Peek.VoiceReact

Inherits: EventArgs

Properties

AudioData
public float[] AudioData { get; }

Raw audio samples.

SampleRate
public int SampleRate { get; }

Audio sample rate in Hz.

DecibelLevel
public float DecibelLevel { get; }

Current decibel level.

NoiseFloor
public float NoiseFloor { get; }

Background noise level in dB.

IsVoiceDetected
public bool IsVoiceDetected { get; }

Is voice currently detected?


Enums

DetectionPreset

Sensitivity presets for voice detection.

Namespace: Peek.VoiceReact

public enum DetectionPreset { VerySensitive, // Horror games, detect whispers Balanced, // General gameplay (default) LessSensitive, // Noisy environments Custom // Manual configuration }

AudioProviderType

Audio source selection for MicrophoneInputHandler.

Namespace: Peek.VoiceReact

public enum AudioProviderType { UnityMicrophone, // Unity Microphone API (default) Dissonance, // Dissonance VoIP CustomComponent // Custom provider component }

Configuration Classes

VoiceDetectionSettings

Detection threshold configuration.

Namespace: Peek

public class VoiceDetectionSettings { public float startThresholdDB; public float endThresholdDB; public float minAmplitudeThreshold; public float significantAmplitudeThreshold; public float minPercentageNonZero; public float noiseMarginDB; public bool isConfigured; }

DetectionPresetValues

Preset configuration values.

Namespace: Peek.VoiceReact

public static class DetectionPresetValues { public struct PresetConfig { public float startThresholdDB; public float endThresholdDB; public float minAmplitudeThreshold; public float significantAmplitudeThreshold; public float noiseMarginDB; public float minSilenceDuration; } public static PresetConfig GetConfig(DetectionPreset preset); }

Interfaces

IAudioProvider

Interface for audio input providers.

Namespace: Peek.VoiceReact.Audio

public interface IAudioProvider { string ProviderName { get; } string DeviceName { get; } AudioClip AudioClip { get; } int SampleRate { get; } int Channels { get; } bool IsActive { get; } bool Initialize(int sampleRate, int lengthSeconds); bool Start(); void Stop(); int GetCurrentPosition(); bool GetAudioData(float[] samples, int offsetSamples); void Dispose(); string[] GetAvailableDevices(); bool SetDevice(string deviceName); string GetCurrentDevice(); }

See Custom Audio Providers for implementation details.


IVoiceNetworkAdapter

Interface for networking library adapters.

Namespace: Peek.VoiceReact.Network

public interface IVoiceNetworkAdapter { void SendVoiceEvent(VoiceNetworkData data); void OnRemoteVoiceEvent(VoiceNetworkData data); }

See Networking for implementation details.


Network Data Structures

VoiceNetworkData

Voice event data for network transmission.

Namespace: Peek.VoiceReact.Network

public struct VoiceNetworkData { public bool isPlayerSpeaking; public float decibelLevel; public Vector3 playerPosition; public string transcription; public float timestamp; }

Base Classes

AudioProviderComponent

Base class for custom audio provider components.

Namespace: Peek.VoiceReact.Audio

Inherits: MonoBehaviour

public abstract class AudioProviderComponent : MonoBehaviour { public abstract IAudioProvider CreateProvider(int sampleRate, int lengthSeconds); }

Extend this to create Inspector-assignable custom providers.


Threading Utilities

MainThreadDispatcher

Marshals background thread operations to Unity’s main thread.

Namespace: Peek.VoiceReact.Threading

Inherits: MonoBehaviour

Methods

RunOnMainThreadAsync (Action)
public static Task RunOnMainThreadAsync(Action action)

Execute action on main thread.

RunOnMainThreadAsync<T> (Func<T>)
public static Task<T> RunOnMainThreadAsync<T>(Func<T> function)

Execute function on main thread and return result.

Example:

await MainThreadDispatcher.RunOnMainThreadAsync(() => { // This runs on main thread transform.position = newPosition; });

Project Settings

VoiceReactProjectSettings

Project-wide default settings applied to all VoiceReact components.

Location: Edit > Project Settings > VoiceReact

Note: Settings are applied to new components only. Existing components retain their values.


Next Steps

Last updated on