using System; using System.Collections.Generic; using System.Linq; using System.Media; using System.Speech.Synthesis; using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Helpers; namespace Tango.MachineStudio.Common.Speech { /// /// Represents the default speech provider. /// /// /// public class DefaultSpeechProvider : ExtendedObject, ISpeechProvider { private SpeechSynthesizer _speech; private SoundPlayer _soundPlayer; private SoundPlayer _soundPlayerErr; private bool _mute; /// /// Gets or sets a value indicating whether this is mute. /// public bool Mute { get { return _mute; } set { _mute = value; RaisePropertyChangedAuto(); } } /// /// Initializes a new instance of the class. /// public DefaultSpeechProvider() { _speech = new SpeechSynthesizer(); _soundPlayer = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Common.bip.wav")); _soundPlayerErr = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Common.error.wav")); _speech.SelectVoice(_speech.GetInstalledVoices().LastOrDefault(x => x.VoiceInfo.Gender == VoiceGender.Female).VoiceInfo.Name); } /// /// Speaks the specified text associated with an information sound. /// /// The text. public void SpeakInfo(string text) { if (!Mute) { _soundPlayer.Play(); _speech.SpeakAsync(text); } } /// /// Speaks the specified text associated with an error sound. /// /// The text. public void SpeakError(string text) { if (!Mute) { _soundPlayerErr.Play(); _speech.SpeakAsync(text); } } } }