Class AudioStreamSender
Component for sending audio streams.
Implements
Inherited Members
Namespace: Unity.RenderStreaming
Assembly: Unity.RenderStreaming.dll
Syntax
[AddComponentMenu("Render Streaming/Audio Stream Sender")]
public class AudioStreamSender : StreamSenderBase, IStreamSender
Properties
audioListener
Gets or sets the AudioListener component used as the audio source.
Declaration
public AudioListener audioListener { get; set; }
Property Value
Type | Description |
---|---|
AudioListener |
See Also
audioSource
Gets or sets the AudioSource component used as the audio source.
Declaration
public AudioSource audioSource { get; set; }
Property Value
Type | Description |
---|---|
AudioSource |
See Also
codec
Gets the codec used for the audio stream.
Declaration
public AudioCodecInfo codec { get; }
Property Value
Type | Description |
---|---|
AudioCodecInfo |
See Also
loopback
Gets or sets whether to play the audio locally while sending it to the remote peer.
Declaration
public bool loopback { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
maxBitrate
Gets the maximum bitrate for the audio stream.
Declaration
public uint maxBitrate { get; }
Property Value
Type | Description |
---|---|
uint |
See Also
minBitrate
Gets the minimum bitrate for the audio stream.
Declaration
public uint minBitrate { get; }
Property Value
Type | Description |
---|---|
uint |
See Also
source
Gets or sets the source of the audio stream.
Declaration
public AudioStreamSource source { get; set; }
Property Value
Type | Description |
---|---|
AudioStreamSource |
See Also
sourceDeviceIndex
Gets or sets the index of the microphone device used as the audio source.
Declaration
public int sourceDeviceIndex { get; set; }
Property Value
Type | Description |
---|---|
int |
See Also
Methods
GetAvailableCodecs()
Declaration
public static IEnumerable<AudioCodecInfo> GetAvailableCodecs()
Returns
Type | Description |
---|---|
IEnumerable<AudioCodecInfo> |
See Also
SetBitrate(uint, uint)
Sets the bitrate range for the audio stream.
Declaration
public void SetBitrate(uint minBitrate, uint maxBitrate)
Parameters
Type | Name | Description |
---|---|---|
uint | minBitrate | The minimum bitrate in kbps. Must be greater than zero. |
uint | maxBitrate | The maximum bitrate in kbps. Must be greater than or equal to the minimum bitrate. |
Examples
audioStreamSender.SetBitrate(128, 256);
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the maximum bitrate is less than the minimum bitrate. |
See Also
SetCodec(AudioCodecInfo)
Sets the codec for the audio stream.
Declaration
public void SetCodec(AudioCodecInfo codec)
Parameters
Type | Name | Description |
---|---|---|
AudioCodecInfo | codec | The codec information to set. |
Examples
var codec = AudioStreamSender.GetAvailableCodecs().First(x => x.mimeType.Contains("opus"));
audioStreamSender.SetCodec(codec);
See Also
SetData(ReadOnly, int)
Sets the audio data for the stream.
Declaration
public void SetData(NativeArray<float>.ReadOnly nativeArray, int channels)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<float>.ReadOnly | nativeArray | The native array containing the audio data. |
int | channels | The number of audio channels. |
Examples
int sampleRate = AudioSettings.outputSampleRate;
int frequency = 440;
int bufferSize = sampleRate; // 1 second buffer
var audioData = new NativeArray<float>(bufferSize, Allocator.Temp);
for (int i = 0; i < bufferSize; i++)
{
audioData[i] = Mathf.Sin(2 * Mathf.PI * frequency * i / sampleRate);
}
audioStreamSender.SetData(audioData.AsReadOnly(), 1);
audioData.Dispose();
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when the source property is not set to AudioStreamSource.APIOnly. |