private async Task StartTTS() { // wait for the audio channel to be active await Task.WhenAll(_audioSendStatusActive.Task); // create an audio/video frame player with audio channel only AudioVideoFramePlayer audioVideoFramePlayer = new AudioVideoFramePlayer(_audioSocket, null, new AudioVideoFramePlayerSettings(new AudioSettings(20), new VideoSettings(), 1000)); // list of AudioMediaBuffer to be sent to the player... we will populate this buffers with the audio coming from the two TTS engines var audioMediaBuffers = new List <AudioMediaBuffer>(); // reference time tick for the audio buffers var referenceTimeTicks = DateTime.Now.Ticks; String text = "I'm completely operational, and all my circuits are functioning perfectly."; // create the local TTS engine ITtsEngine localTts = new TtsEngineLocal(); referenceTimeTicks = populateAudioBuffersFromStream(localTts.SynthesizeText(text), audioMediaBuffers, referenceTimeTicks); // create the TTS service engine ITtsEngine serviceTts = new TtsEngineService(); populateAudioBuffersFromStream(serviceTts.SynthesizeText(text), audioMediaBuffers, referenceTimeTicks); // enqueue the audio buffers, passing an empty list of video buffers since our player is audio only await audioVideoFramePlayer.EnqueueBuffersAsync(audioMediaBuffers, new List <VideoMediaBuffer>()); }
private async Task StartAudioVideoFramePlayer() { try { await Task.WhenAll(_audioSendStatusActive.Task, _videoSendStatusActive.Task); Log.Info( new CallerInfo(), LogContext.Media, "Send status active for audio and video Creating the audio video player"); AudioVideoFramePlayerSettings settings = new AudioVideoFramePlayerSettings(new AudioSettings(20), new VideoSettings(), _mediaBufferToLoadInSeconds * 1000); _audioVideoFramePlayer = new AudioVideoFramePlayer(_audioSocket, _videoSocket, settings); Log.Info( new CallerInfo(), LogContext.Media, "created the audio video player"); _downloadManager.ConnectToStorageAccount(); _audioVideoFramePlayer.LowOnFrames += OnLowOnFrames; var currentTick = DateTime.Now.Ticks; _videoMediaBuffers = _downloadManager.GetVideoMediaBuffers(currentTick); _audioMediaBuffers = _downloadManager.GetAudioMediaBuffers(currentTick); //update the tick for next iteration _mediaTick = Math.Max(_audioMediaBuffers.Last().Timestamp, _videoMediaBuffers.Last().Timestamp); await _audioVideoFramePlayer.EnqueueBuffersAsync(_audioMediaBuffers, _videoMediaBuffers); } finally { _startVideoPlayerCompleted.Set(); } }
private void OnLowOnFrames(object sender, LowOnFramesEventArgs e) { if (Interlocked.CompareExchange(ref _disposed, 1, 1) == 1) { return; } Log.Info( new CallerInfo(), LogContext.Media, "Low in frames event raised]"); _videoMediaBuffers = _downloadManager.GetVideoMediaBuffers(_mediaTick); _audioMediaBuffers = _downloadManager.GetAudioMediaBuffers(_mediaTick); _mediaTick = Math.Max(_audioMediaBuffers.Last().Timestamp, _videoMediaBuffers.Last().Timestamp); _audioVideoFramePlayer.EnqueueBuffersAsync(_audioMediaBuffers, _videoMediaBuffers).ForgetAndLogException(); Log.Info( new CallerInfo(), LogContext.Media, "enqueued more frames in frames event raised"); }
private async Task StartTTVS() { // wait for both the audio and video channels to be active await Task.WhenAll(_audioSendStatusActive.Task, _videoSendStatusActive.Task); // create an audio/video frame player audioVideoFramePlayer = new AudioVideoFramePlayer(_audioSocket, _videoSocket, new AudioVideoFramePlayerSettings(new AudioSettings(20), new VideoSettings(), 1000)); // lists of buffers to be sent to the player... we will populate this buffers with the audio/video coming from the TTVS engines var audioMediaBuffers = new List <AudioMediaBuffer>(); var videoMediaBuffers = new List <VideoMediaBuffer>(); // create the TTVS engine and generate the media buffers TtvsEngine ttvsEngine = new TtvsEngine(_defaultVideoFormat); string welcomeText = "I'm completely operational, and all my circuits are functioning perfectly!"; ttvsEngine.SynthesizeText(welcomeText, audioMediaBuffers, videoMediaBuffers); await audioVideoFramePlayer.EnqueueBuffersAsync(audioMediaBuffers, videoMediaBuffers); }