Example #1
0
        public static async void SpeakContentAsync
            (String content, Boolean isSsml, String voiceId)
        {
            if (String.IsNullOrWhiteSpace(content))
            {
                return;
            }

            // Find the voice with the matching Id or just use the default
            var voice = Voices.FirstOrDefault(x => x.Id == voiceId) ??
                        DefaultVoice;

            using (var synthesizer = new SpeechSynthesizer {
                Voice = voice
            })
            {
                // NOTE - if Synthesize___ToStreamAsync throws an Access Denied exception,
                // there is a known problem with some fresh Windows 8.1 installations.
                // Additional information about the problem and its remedy (clearing
                // a bad permission entry for a registry value) can be found at http://j.mp/1o2eeJL

                // Get the voice stream for the given text
                var voiceStream = isSsml
                    ? await synthesizer.SynthesizeSsmlToStreamAsync(content)
                    : await synthesizer.SynthesizeTextToStreamAsync(content);

                // Create a new MediaElement and use it to play the voice stream
                var mediaElement = new MediaElement();
                mediaElement.SetSource(voiceStream, voiceStream.ContentType);
                mediaElement.Play();
            }
        }
        public NotificationSettingsViewModel(Languages languages)
        {
            random    = new Random();
            Languages = languages;

            testState            = new State(JsonConvert.DeserializeObject <List <EntryData> >(IOUtils.GetEntryDatasJson()), languages, "Count");
            testState.Blueprints = new List <Blueprint>(JsonConvert.DeserializeObject <List <Blueprint> >(IOUtils.GetBlueprintsJson(), new BlueprintConverter(testState.Cargo)));

            testCommanderNotifications = new CommanderNotifications(testState);
            testCommanderNotifications.SubscribeNotifications();

            NotificationKindThresholdReached = SettingsManager.NotificationKindThresholdReached;
            NotificationKindCargoAlmostFull  = SettingsManager.NotificationKindCargoAlmostFull;
            NotificationKindBlueprintReady   = SettingsManager.NotificationKindBlueprintReady;

            SelectedVoice = Voices.FirstOrDefault(v => v.Item2 == SettingsManager.NotificationVoice) ?? Voices.FirstOrDefault();
        }
Example #3
0
        //public bool IsSpeaking => _synth.State == SynthesizerState.Speaking;

        public Voice(Action speakCompleted)
        {
            try
            {
                _synth = new SpeechSynthesizer();
                GetVoices();
                // Load an spanish voice or the first.
                ChangeCurrentVoice(Voices.FirstOrDefault(x => x.Contains("Spanish")) ?? Voices[0]);
                Msgs                 = new Queue <string>();
                SpkCompleted         = speakCompleted;
                _synth.StateChanged += SynthStateChanged;
                TskLoadVolController = Task.Run(LoadVolumeSett);
            }
            catch (Exception exc)
            {
                throw new Exception($"Error en la configuración de la voz de la aplicación:\n{exc.Message}");
            }
        }
Example #4
0
 public Voice(Action speakCompleted)
 {
     //TODO:Check Voices.Count>0
     try
     {
         _synth = new SpeechSynthesizer();
         GetVoices();
         ChangeCurrentVoice(Voices.FirstOrDefault(x => x.Contains("Spanish")) ?? Voices[0]);
         _msgs                = new Queue <string>();
         _spkCompleted        = speakCompleted;
         _synth.StateChanged += SynthStateChanged;
         ThVolumeSett         = new Thread(ThLoadVolumeSett);
         ThVolumeSett.Start();
     }
     catch (Exception exc)
     {
         throw new Exception($"Error en la configuración de la voz de la aplicación:\n{exc.Message}");
     }
 }
        public void Play(string words)
        {
            if (string.IsNullOrEmpty(words))
            {
                return;
            }

            if (Speaking)
            {
                Queue.Add(words);
            }
            else
            {
                Speaking = true;
                Queue.RemoveAll(words.Equals);
                speaker.SelectVoice(Voices.Contains(SelectedVoice) ? SelectedVoice : Voices.FirstOrDefault());
                speaker.SpeakAsync(words);
            }
        }