Photon Voice v2.22.1

Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Properties | List of all members
Recorder Class Reference

Component representing outgoing audio stream in scene. More...

Inherits VoiceComponent.

Classes

class  PhotonVoiceCreatedParams
 

Public Types

enum  InputSourceType
 
enum  MicType
 
enum  SampleTypeConv
 

Public Member Functions

void Init (VoiceClient voiceClient, object customObj=null)
 Initializes the Recorder component to be able to transmit audio. More...
 
void Init (VoiceConnection voiceConnection)
 Initializes the Recorder component to be able to transmit audio. More...
 
void ReInit ()
 
void RestartRecording (bool force=false)
 Restarts recording if something has changed that requires this. More...
 
void VoiceDetectorCalibrate (int durationMs, Action< float > detectionEndedCallback=null)
 Trigger voice detector calibration process. While calibrating, keep silence. Voice detector sets threshold basing on measured background noise level. More...
 
void StartRecording ()
 Starts recording. More...
 
void StopRecording ()
 Stops recording. More...
 
bool ResetLocalAudio ()
 Resets audio session and parameters locally to fix broken recording due to system configuration modifications or audio interruptions or audio routing changes. More...
 

Static Public Member Functions

static bool CompareUnityMicNames (string mic1, string mic2)
 
static bool IsDefaultUnityMic (string mic)
 

Static Public Attributes

const int MIN_OPUS_BITRATE = 6000
 
const int MAX_OPUS_BITRATE = 510000
 

Protected Member Functions

virtual void SendPhotonVoiceCreatedMessage ()
 
- Protected Member Functions inherited from VoiceComponent
virtual void Awake ()
 

Properties

static AudioInEnumerator PhotonMicrophoneEnumerator [get]
 Enumerator for the available microphone devices gathered by the Photon plugin. More...
 
bool IsInitialized [get]
 If true, this Recorder has been initialized and is ready to transmit to remote clients. Otherwise call Init(VoiceConnection). More...
 
bool RequiresInit [get]
 
bool RequiresRestart [get, protected set]
 Returns true if something has changed in the Recorder while recording that won't take effect unless recording is restarted using RestartRecording. More...
 
bool TransmitEnabled [get, set]
 If true, audio transmission is enabled. More...
 
bool Encrypt [get, set]
 If true, voice stream is sent encrypted. More...
 
bool DebugEchoMode [get, set]
 If true, outgoing stream routed back to client via server same way as for remote client's streams. More...
 
bool ReliableMode [get, set]
 If true, stream data sent in reliable mode. More...
 
bool VoiceDetection [get, set]
 If true, voice detection enabled. More...
 
float VoiceDetectionThreshold [get, set]
 Voice detection threshold (0..1, where 1 is full amplitude). More...
 
int VoiceDetectionDelayMs [get, set]
 Keep detected state during this time after signal level dropped below threshold. Default is 500ms More...
 
object UserData [get, set]
 Custom user object to be sent in the voice stream info event. More...
 
Func< IAudioDescInputFactory [get, set]
 Set the method returning new Voice.IAudioDesc instance to be assigned to a new voice created with Source set to Factory More...
 
AudioUtil.IVoiceDetectorVoiceDetector [get]
 Returns voice activity detector for recorder's audio stream. More...
 
string UnityMicrophoneDevice [get, set]
 Set or get Unity microphone device used for streaming. More...
 
int PhotonMicrophoneDeviceId [get, set]
 Set or get photon microphone device used for streaming. More...
 
byte AudioGroup [get, set]
 Target interest group that will receive transmitted audio. More...
 
byte InterestGroup [get, set]
 Target interest group that will receive transmitted audio. More...
 
bool IsCurrentlyTransmitting [get]
 Returns true if audio stream broadcasts. More...
 
AudioUtil.ILevelMeterLevelMeter [get]
 Level meter utility. More...
 
bool VoiceDetectorCalibrating [get]
 If true, voice detector calibration is in progress. More...
 
ILocalVoiceAudio voiceAudio [get]
 
InputSourceType SourceType [get, set]
 Audio data source. More...
 
MicType MicrophoneType [get, set]
 Which microphone API to use when the Source is set to Microphone. More...
 
SampleTypeConv TypeConvert [get, set]
 Force creation of 'short' pipeline and convert audio data to short for 'float' audio sources. More...
 
AudioClip AudioClip [get, set]
 Source audio clip. More...
 
bool LoopAudioClip [get, set]
 Loop playback for audio clip sources. More...
 
SamplingRate SamplingRate [get, set]
 Outgoing audio stream sampling rate. More...
 
OpusCodec.FrameDuration FrameDuration [get, set]
 Outgoing audio stream encoder delay. More...
 
int Bitrate [get, set]
 Outgoing audio stream bitrate. More...
 
bool IsRecording [get, set]
 Gets or sets whether this Recorder is actively recording audio to be transmitted. More...
 
bool ReactOnSystemChanges [get, set]
 If true, the Recorder will automatically restart recording to recover from audio device changes. More...
 
bool AutoStart [get, set]
 If true, automatically start recording when initialized. More...
 
bool RecordOnlyWhenEnabled [get, set]
 If true, component will work only when enabled and active in hierarchy. More...
 
bool SkipDeviceChangeChecks [get, set]
 If true, restarts recording without checking if audio config/device changes affected recording. More...
 
bool StopRecordingWhenPaused [get, set]
 If true, stop recording when paused resume/restart when un-paused. More...
 
bool UseOnAudioFilterRead [get, set]
 If true, recording will make use of Unity's OnAudioFitlerRead callback from a muted local AudioSource. More...
 
bool TrySamplingRateMatch [get, set]
 If true, Recorder will try to match sampling rates of microphone device and Opus encoder to avoid re sampling of audio input. More...
 
bool UseMicrophoneTypeFallback [get, set]
 If true, if recording fails to start with Unity microphone type, Photon microphone type is used -if available- as a fallback and vice versa. More...
 
- Properties inherited from VoiceComponent
VoiceLogger Logger [get, protected set]
 
DebugLevel LogLevel [get, set]
 
bool IgnoreGlobalLogLevel [get, set]
 
- Properties inherited from ILoggableDependent
bool IgnoreGlobalLogLevel [get, set]
 
- Properties inherited from ILoggable
DebugLevel LogLevel [get, set]
 
VoiceLogger Logger [get]
 

Additional Inherited Members

- Protected Attributes inherited from VoiceComponent
DebugLevel logLevel = DebugLevel.INFO
 

Detailed Description

Component representing outgoing audio stream in scene.

Member Function Documentation

◆ Init() [1/2]

void Init ( VoiceClient  voiceClient,
object  customObj = null 
)

Initializes the Recorder component to be able to transmit audio.

Parameters
voiceClientThe VoiceClient to be used with this Recorder.
customObjOptional user data object to be transmitted with the voice stream info

◆ Init() [2/2]

void Init ( VoiceConnection  voiceConnection)

Initializes the Recorder component to be able to transmit audio.

Parameters
voiceConnectionThe VoiceConnection to be used with this Recorder.

◆ ResetLocalAudio()

bool ResetLocalAudio ( )

Resets audio session and parameters locally to fix broken recording due to system configuration modifications or audio interruptions or audio routing changes.

Returns
If reset is done.

◆ RestartRecording()

void RestartRecording ( bool  force = false)

Restarts recording if something has changed that requires this.

Parameters
forceSet to true if you want to restart even if this is not required (RequiresRestart = false)

◆ StartRecording()

void StartRecording ( )

Starts recording.

◆ StopRecording()

void StopRecording ( )

Stops recording.

◆ VoiceDetectorCalibrate()

void VoiceDetectorCalibrate ( int  durationMs,
Action< float >  detectionEndedCallback = null 
)

Trigger voice detector calibration process. While calibrating, keep silence. Voice detector sets threshold basing on measured background noise level.

Parameters
durationMsDuration of calibration in milliseconds.
detectionEndedCallbackCallback when VAD calibration ends.

Property Documentation

◆ AudioClip

AudioClip AudioClip
getset

Source audio clip.

◆ AudioGroup

byte AudioGroup
getset

Target interest group that will receive transmitted audio.

If AudioGroup != 0, recorder's audio data is sent only to clients listening to this group.

◆ AutoStart

bool AutoStart
getset

If true, automatically start recording when initialized.

◆ Bitrate

int Bitrate
getset

Outgoing audio stream bitrate.

◆ DebugEchoMode

bool DebugEchoMode
getset

If true, outgoing stream routed back to client via server same way as for remote client's streams.

◆ Encrypt

bool Encrypt
getset

If true, voice stream is sent encrypted.

◆ FrameDuration

OpusCodec.FrameDuration FrameDuration
getset

Outgoing audio stream encoder delay.

◆ InputFactory

Func<IAudioDesc> InputFactory
getset

Set the method returning new Voice.IAudioDesc instance to be assigned to a new voice created with Source set to Factory

◆ InterestGroup

byte InterestGroup
getset

Target interest group that will receive transmitted audio.

If InterestGroup != 0, recorder's audio data is sent only to clients listening to this group.

◆ IsCurrentlyTransmitting

bool IsCurrentlyTransmitting
get

Returns true if audio stream broadcasts.

◆ IsInitialized

bool IsInitialized
get

If true, this Recorder has been initialized and is ready to transmit to remote clients. Otherwise call Init(VoiceConnection).

◆ IsRecording

bool IsRecording
getset

Gets or sets whether this Recorder is actively recording audio to be transmitted.

◆ LevelMeter

AudioUtil.ILevelMeter? LevelMeter
get

Level meter utility.

◆ LoopAudioClip

bool LoopAudioClip
getset

Loop playback for audio clip sources.

◆ MicrophoneType

MicType MicrophoneType
getset

Which microphone API to use when the Source is set to Microphone.

◆ PhotonMicrophoneDeviceId

int PhotonMicrophoneDeviceId
getset

Set or get photon microphone device used for streaming.

◆ PhotonMicrophoneEnumerator

AudioInEnumerator PhotonMicrophoneEnumerator
staticget

Enumerator for the available microphone devices gathered by the Photon plugin.

◆ ReactOnSystemChanges

bool ReactOnSystemChanges
getset

If true, the Recorder will automatically restart recording to recover from audio device changes.

By default, the Recorder will restart recording only when the Recorder.SourceType is InputSourceType.Microphone and the device being used is no longer available or valid, in some cases you may need to force restarts even if the device in use did not change. To enable this set Recorder.SkipDeviceChangeChecks to true.

◆ RecordOnlyWhenEnabled

bool RecordOnlyWhenEnabled
getset

If true, component will work only when enabled and active in hierarchy.

◆ ReliableMode

bool ReliableMode
getset

If true, stream data sent in reliable mode.

◆ RequiresRestart

bool RequiresRestart
getprotected set

Returns true if something has changed in the Recorder while recording that won't take effect unless recording is restarted using RestartRecording.

Think of this as a "isDirty" flag.

◆ SamplingRate

SamplingRate SamplingRate
getset

Outgoing audio stream sampling rate.

◆ SkipDeviceChangeChecks

bool SkipDeviceChangeChecks
getset

If true, restarts recording without checking if audio config/device changes affected recording.

To be used when Recorder.ReactOnSystemChanges is true.

◆ SourceType

InputSourceType SourceType
getset

Audio data source.

◆ StopRecordingWhenPaused

bool StopRecordingWhenPaused
getset

If true, stop recording when paused resume/restart when un-paused.

◆ TransmitEnabled

bool TransmitEnabled
getset

If true, audio transmission is enabled.

◆ TrySamplingRateMatch

bool TrySamplingRateMatch
getset

If true, Recorder will try to match sampling rates of microphone device and Opus encoder to avoid re sampling of audio input.

◆ TypeConvert

SampleTypeConv TypeConvert
getset

Force creation of 'short' pipeline and convert audio data to short for 'float' audio sources.

◆ UnityMicrophoneDevice

string UnityMicrophoneDevice
getset

Set or get Unity microphone device used for streaming.

◆ UseMicrophoneTypeFallback

bool UseMicrophoneTypeFallback
getset

If true, if recording fails to start with Unity microphone type, Photon microphone type is used -if available- as a fallback and vice versa.

◆ UseOnAudioFilterRead

bool UseOnAudioFilterRead
getset

If true, recording will make use of Unity's OnAudioFitlerRead callback from a muted local AudioSource.

If enabled, 3D sounds and voice positioning can be lost.

◆ UserData

object UserData
getset

Custom user object to be sent in the voice stream info event.

◆ VoiceDetection

bool VoiceDetection
getset

If true, voice detection enabled.

◆ VoiceDetectionDelayMs

int VoiceDetectionDelayMs
getset

Keep detected state during this time after signal level dropped below threshold. Default is 500ms

◆ VoiceDetectionThreshold

float VoiceDetectionThreshold
getset

Voice detection threshold (0..1, where 1 is full amplitude).

◆ VoiceDetector

AudioUtil.IVoiceDetector? VoiceDetector
get

Returns voice activity detector for recorder's audio stream.

◆ VoiceDetectorCalibrating

bool VoiceDetectorCalibrating
get

If true, voice detector calibration is in progress.