/// <summary> /// Adds an utterance to the utterance queue. /// <para>it will be spoken when any other utterances queued before it have been spoken.</para> /// </summary> public void Speak(SpeechSynthesisUtterance utterance) { if (Available) { JSRuntime.InvokeAsync <object>(Namespace + ".speak", this.GetObjectRef(), utterance, utterance.GetObjectRef()); } }
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed /// <summary> /// Adds an utterance to the utterance queue. /// <para>it will be spoken when any other utterances queued before it have been spoken.</para> /// </summary> public void Speak(SpeechSynthesisUtterance utterance) { if (Available) { lock (_EventHandledUtterancesLock) { var eventHandledUtterances = _EventHandledUtterances .Select(wref => (WeakRef: wref, Utterance: wref.TryGetTarget(out var u) ? u : null)) .Where(item => item.Utterance != null) .ToArray(); var eventHandled = eventHandledUtterances.Any(item => Object.ReferenceEquals(item.Utterance, utterance)); if (!eventHandled) { eventHandledUtterances = eventHandledUtterances .ToArray(); _EventHandledUtterances = eventHandledUtterances.Select(item => item.WeakRef) .Concat(new[] { new WeakReference <SpeechSynthesisUtterance>(utterance) }) .ToArray(); HandleEvents(utterance); } else { _EventHandledUtterances = eventHandledUtterances.Select(item => item.WeakRef).ToArray(); } } InvokeJavaScriptAsync <object>("speak", this.GetObjectRef(), utterance, utterance.GetObjectRef()); } }
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed /// <summary> /// Adds an utterance to the utterance queue. /// <para>it will be spoken when any other utterances queued before it have been spoken.</para> /// </summary> public void Speak(SpeechSynthesisUtterance utterance) { if (Available) { InvokeJavaScriptAsync <object>("speak", this.GetObjectRef(), utterance, utterance.GetObjectRef()); } }
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed private void HandleEvents(SpeechSynthesisUtterance utterancet) { utterancet.Start += OnStart; utterancet.Boundary += OnBoundary; utterancet.Mark += OnMark; utterancet.Pause += OnPause; utterancet.Resume += OnResume; utterancet.End += OnEnd; utterancet.Error += OnError; }