Exemplo n.º 1
0
 public static void Dispose()
 {
     if (synth != null)
     {
         synth.Dispose();
     }
 }
Exemplo n.º 2
0
        public override void Speak(string text, bool gender, int ipitch)
        {
            var Synth = new System.Speech.Synthesis.SpeechSynthesizer();

            Synth.SelectVoiceByHints((gender) ? System.Speech.Synthesis.VoiceGender.Female : System.Speech.Synthesis.VoiceGender.Male);
            if (text == "")
            {
                return;
            }
            var voci   = Synth.GetInstalledVoices();
            var stream = new System.IO.MemoryStream();
            var pitch  = Math.Max(0.1f, ipitch / 100f + 1f); //below 0.1 is just stupid, so just clamp there.

            if (pitch < 1f)
            {
                Synth.Rate = 10 - (int)(pitch * 10);
            }
            else
            {
                Synth.Rate = (int)(10 / pitch) - 10;
            }
            Synth.SetOutputToWaveStream(stream);
            Synth.SpeakAsync(text);

            EventHandler <System.Speech.Synthesis.SpeakCompletedEventArgs> OnComplete = null;

            OnComplete = (obj, evt) =>
            {
                GameThread.NextUpdate((u) =>
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    var sfx    = SoundEffect.FromStream(stream);
                    var inst   = sfx.CreateInstance();
                    inst.Pitch = pitch - 1f;
                    inst.Play();

                    GameThreadInterval interval = null;
                    interval = GameThread.SetInterval(() =>
                    {
                        if (inst.State == SoundState.Stopped)
                        {
                            sfx.Dispose(); //just catch and dispose these when appropriate
                            interval.Clear();
                        }
                    }, 1000);
                    Synth.Dispose();
                });
                Synth.SpeakCompleted -= OnComplete;
            };

            Synth.SpeakCompleted += OnComplete;
        }
Exemplo n.º 3
0
 public override void OnApplicationStopped()
 {
     // Add code to be executed when Playnite is shutting down.
     //needs to be sync or won't speak out full text before quiting
     DoSpeak(Settings.SpeakApplicationStoppedText, Settings.SpeakApplicationStopped, false);
     try
     {
         Speak.SpeakAsyncCancelAll();
         Speak.Dispose();
     }
     catch (Exception E)
     {
         logger.Error(E, "OnApplicationStopped");
         PlayniteApi.Dialogs.ShowErrorMessage(E.ToString(), Constants.AppName);
     }
 }
Exemplo n.º 4
0
 private void StopSpeech()
 {
     if ((App.Current as App).IsEnableSpeech)
     {
         if (ssz != null)
         {
             ssz.Dispose();
             ssz = null;
             BTN_Pause.Visibility    = Visibility.Collapsed;
             BTN_SysBegin.Visibility = Visibility.Visible;
             rindex = 0;
         }
     }
     else
     {
         new MainPanel.PopOk().ShowDialog("朗读功能暂不提供!");
     }
 }
Exemplo n.º 5
0
 public override void Dispose()
 {
     Synth.Dispose();
 }
Exemplo n.º 6
0
 public static void Dispose()
 {
     voice?.Dispose();
 }