示例#1
0
        public void SelectVoiceByHints(VoiceGender gender, VoiceAge age, int voiceAlternate, CultureInfo culture)
        {
            Helpers.ThrowIfNull(culture, nameof(culture));

            if (voiceAlternate < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(voiceAlternate), SR.Get(SRID.PromptBuilderInvalidVariant));
            }
            if (!VoiceInfo.ValidateGender(gender))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceGender"), nameof(gender));
            }

            if (!VoiceInfo.ValidateAge(age))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceAge"), nameof(age));
            }

            TTSVoice ttsVoice = VoiceSynthesizer.GetEngine(null, culture, gender, age, voiceAlternate, true);

            if (ttsVoice == null)
            {
                // No match - throw
                throw new InvalidOperationException(SR.Get(SRID.SynthesizerSetVoiceNoMatch));
            }
            VoiceSynthesizer.Voice = ttsVoice;
        }
示例#2
0
        public void SpeakAsync(Prompt prompt)
        {
            Helpers.ThrowIfNull(prompt, nameof(prompt));

            prompt.Synthesizer = this;
            VoiceSynthesizer.SpeakAsync(prompt);
        }
示例#3
0
 /// <summary>
 /// Resume the playback of all speech in this synthesizer.
 /// </summary>
 public void Resume()
 {
     if (_paused)
     {
         VoiceSynthesizer.Resume();
         _paused = false;
     }
 }
示例#4
0
        private void SetOutputStream(Stream stream, SpeechAudioFormatInfo formatInfo, bool headerInfo, bool closeStreamOnExit)
        {
            SetOutputToNull();
            _outputStream      = stream;
            _closeStreamOnExit = closeStreamOnExit;

            // Need to serialize into a proper wav file before closing the stream
            VoiceSynthesizer.SetOutput(stream, formatInfo, headerInfo);
        }
示例#5
0
 /// <summary>
 /// Pause the playback of all speech in this synthesizer.
 /// </summary>
 public void Pause()
 {
     // Increment the Paused count
     if (!_paused)
     {
         VoiceSynthesizer.Pause();
         _paused = true;
     }
 }
        public ServerWindow()
        {
            InitializeComponent();
            mServerVM        = new ServerViewModel();
            this.DataContext = mServerVM;
            this.Closing    += mServerVM.OnWindow_Closing;

            synthesizer = new VoiceSynthesizer();
            mServerVM.mServer.PropertyChanged += synthesizer.MServer_PropertyChanged;
        }
示例#7
0
        public ReadOnlyCollection <InstalledVoice> GetInstalledVoices(CultureInfo culture)
        {
            Helpers.ThrowIfNull(culture, nameof(culture));

            if (culture.Equals(CultureInfo.InvariantCulture))
            {
                throw new ArgumentException(SR.Get(SRID.InvariantCultureInfo), nameof(culture));
            }

            return(VoiceSynthesizer.GetInstalledVoices(culture));
        }
示例#8
0
        public void SelectVoice(string name)
        {
            Helpers.ThrowIfEmptyOrNull(name, nameof(name));
            TTSVoice ttsVoice = VoiceSynthesizer.GetEngine(name, CultureInfo.CurrentUICulture, VoiceGender.NotSet, VoiceAge.NotSet, 1, true);

            if (ttsVoice == null || name != ttsVoice.VoiceInfo.Name)
            {
                // No match - throw
                throw new ArgumentException(SR.Get(SRID.SynthesizerSetVoiceNoMatch));
            }
            VoiceSynthesizer.Voice = ttsVoice;
        }
示例#9
0
        public void Speak(Prompt prompt)
        {
            Helpers.ThrowIfNull(prompt, nameof(prompt));

            // Avoid a dead lock if the synthesizer is Paused
            if (State == SynthesizerState.Paused)
            {
                throw new InvalidOperationException(SR.Get(SRID.SynthesizerSyncSpeakWhilePaused));
            }

            prompt.Synthesizer = this;
            prompt._syncSpeak  = true;
            VoiceSynthesizer.Speak(prompt);
        }
示例#10
0
        // The stream is disposed when the speech synthesizer is disposed
        public void SetOutputToNull()
        {
            // Close the existing stream
            if (_outputStream != Stream.Null)
            {
                VoiceSynthesizer.SetOutput(Stream.Null, null, true);
            }

            if (_outputStream != null)
            {
                if (_closeStreamOnExit)
                {
                    _outputStream.Close();
                }
            }
            _outputStream = Stream.Null;
        }
示例#11
0
        public static async void Run()
        {
            if (_wasRun)
            {
                return;
            }
            _wasRun = true;

            var builder = new ContainerBuilder();

            var modules = new LayerModule[]
            {
                new CoreModule(),
                new ApplicationModule(),
            };

            modules.ForEach(builder.RegisterModule);

            var container = builder.Build();

            ServiceLocator.Init(container);
            modules.ForEach(m => m.OnPostContainerBuild(container));
            //new AudioDeviceResource().StartCapture();
            var s = new VoiceSynthesizer();

            string[] texts =
            {
                "Привет мир",
                "как дела",
                "Hello world",
                "How are you?",
                "test",
                "give me that thing please",
                "thats why I here",
                "translation test",
            };
            foreach (var text in texts)
            {
                await Task.Delay(500);

                s.Synthesize(text);
            }
        }
示例#12
0
        public void RemoveLexicon(Uri uri)
        {
            Helpers.ThrowIfNull(uri, nameof(uri));

            VoiceSynthesizer.RemoveLexicon(uri);
        }
示例#13
0
        public void AddLexicon(Uri uri, string mediaType)
        {
            Helpers.ThrowIfNull(uri, nameof(uri));

            VoiceSynthesizer.AddLexicon(uri, mediaType);
        }
示例#14
0
 public ReadOnlyCollection <InstalledVoice> GetInstalledVoices()
 {
     return(VoiceSynthesizer.GetInstalledVoices(null));
 }
示例#15
0
 /// <summary>
 /// Cancel playback of all Prompts currently in the queue.
 /// </summary>
 public void SpeakAsyncCancelAll()
 {
     VoiceSynthesizer.Abort();
 }
示例#16
0
        /// <summary>
        /// Cancel playback of all Prompts currently in the queue.
        /// </summary>
        public void SpeakAsyncCancel(Prompt prompt)
        {
            Helpers.ThrowIfNull(prompt, nameof(prompt));

            VoiceSynthesizer.Abort(prompt);
        }