Ejemplo n.º 1
0
        public AudioStreamer CreateAudioStreamer()
        {
            if (!Ready)
            {
                throw new InvalidOperationException("Voice socket is not ready to create audio streamer.");
            }

            var endPointInfo = new VoiceEndPointInfo
            {
                SocketEndPoint = GetUdpEndpoint(),
                LocalPort      = LocalPort,
                Ssrc           = Ssrc,
                EncryptionKey  = SecretKey,
                EncryptionMode = EncryptionMode,
            };

            var streamer = new AudioStreamer(new OpusAudioEncoder(Connectivity.VoiceSampleRate, Connectivity.VoiceChannels), endPointInfo, cancellationToken: CancellationTokenSource.Token);

            streamer.OnAudioStart += async(a, b) =>
            {
                await BeginSpeaking();
            };

            streamer.OnAudioStop += async(a, b) =>
            {
                await EndSpeaking();
            };

            return(streamer);
        }
Ejemplo n.º 2
0
        public AudioStreamer(IAudioEncoder encoder, VoiceEndPointInfo endPointInfo, CancellationToken cancellationToken = default)
        {
            Encoder                  = encoder;
            EndPointInfo             = endPointInfo;
            _globalCancellationToken = cancellationToken;

            new Thread(() => AudioLoop().Wait()).Start();
        }