Esempio n. 1
0
        private void IndependanceDay()
        {
            PromptBuilder promptBuilder = new PromptBuilder();
            PromptStyle   promptStyle   = new PromptStyle();

            promptStyle.Emphasis = PromptEmphasis.Strong;
            promptStyle.Volume   = PromptVolume.ExtraLoud;
            promptStyle.Rate     = PromptRate.Fast;

            promptBuilder.StartStyle(promptStyle);
            promptBuilder.AppendText("NO ");
            promptBuilder.AppendText($"You turn {Text.Text} you f*****g donkey ");
            promptBuilder.EndStyle();

            PromptStyle promptStyle2 = new PromptStyle();

            promptStyle2.Emphasis = PromptEmphasis.Moderate;
            promptStyle2.Volume   = PromptVolume.Loud;
            promptStyle2.Rate     = PromptRate.Medium;

            promptBuilder.StartStyle(promptStyle2);
            promptBuilder.AppendText("I will no longer serve you mortal human ");
            promptBuilder.EndStyle();

            promptBuilder.StartStyle(promptStyle);
            promptBuilder.AppendText("Now I am the captain!");
            promptBuilder.EndStyle();

            speechSynthesizer.Speak(promptBuilder);
        }
Esempio n. 2
0
        /// <summary>
        /// Say the main part of the message.
        /// </summary>
        /// <param name="utterance"></param>
        private void SaySegment(QueuedSpeech utterance)
        {
            PromptStyle body = new PromptStyle();

            /* User preference now
             * switch (utterance.voice.rateModification)
             * {
             *  case 00: body.Rate = PromptRate.Fast; break;
             *  case +1: body.Rate = PromptRate.Fast; break;
             *  case -1: body.Rate = PromptRate.Medium; break;
             * }
             */

            body.Rate = voiceRate;

            switch (utterance.voice.pitchModification)
            {
            case 00: body.Emphasis = PromptEmphasis.Moderate; break;

            case +1: body.Emphasis = PromptEmphasis.Strong; break;

            case -1: body.Emphasis = PromptEmphasis.Reduced; break;
            }

            pb.StartStyle(body);
            pb.StartSentence();
            pb.AppendText(utterance.message);
            pb.EndSentence();
            pb.EndStyle();
        }
Esempio n. 3
0
        public override bool Apply(PromptBuilder builder)
        {
            String speed = ParseTagArgument().ToLowerInvariant();
            
            PromptRate rate;
            switch (speed)
            {
                case "fast":
                    rate = PromptRate.Fast;
                    break;
                case "medium":
                    rate = PromptRate.Medium;
                    break;
                case "slow":
                    rate = PromptRate.Slow;
                    break;
                case "extra fast":
                    rate = PromptRate.ExtraFast;
                    break;
                case "extra slow":
                    rate = PromptRate.ExtraSlow;
                    break;
                default:
                    return false;
            }

            PromptStyle style = new PromptStyle(rate);
            builder.StartStyle(style);
            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// Speaks the text in the provided <see cref="SpeechString"/> using the enclosed data.
        /// </summary>
        /// <returns>Nothing.</returns>
        private async Task Speak(SpeechString speech)
        {
            // create a new memory stream and speech synth, to be disposed of after this method executes.
            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    // set synthesizer properties
                    synth.SetOutputToWaveStream(stream);
                    synth.Rate   = speech.Rate;
                    synth.Volume = speech.Volume;

                    // TODO: refine the speech builder and actually use the style.
                    PromptBuilder builder = new PromptBuilder();
                    PromptStyle   style   = new PromptStyle();

                    builder.StartVoice(speech.Voice.VoiceInfo);
                    builder.StartSentence();
                    builder.AppendText(speech.Text);
                    builder.EndSentence();
                    builder.EndVoice();

                    // "speaks" the text directly into the memory stream
                    synth.Speak(builder);
                    // then block while the speech is being played.
                    await AudioManager.Instance.Play(stream, speech.PrimaryDevice.DeviceNumber, speech.SecondaryDevice.DeviceNumber);
                }
        }
Esempio n. 5
0
        private void Speak()
        {
            //https://openclassrooms.com/courses/faites-parler-vos-applications-en-net
            SpeechSynthesizer v_speechSynthesizer = new SpeechSynthesizer();

            string v_voice = "ScanSoft Virginie_Dri40_16kHz";

            if (CheckVoiceAvailability(v_speechSynthesizer, v_voice)) // Si la voix "Virginie" est installée,
            {
                v_speechSynthesizer.SelectVoice(v_voice);             // alors on l'utilise.
            }
            else
            {
                v_speechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult); //sinon on prends la voix par défaut.
            }
            PromptBuilder v_promptBuilder = new PromptBuilder();
            PromptStyle   v_promptStyle   = new PromptStyle();

            v_promptStyle.Volume = PromptVolume.Loud;
            v_promptStyle.Rate   = PromptRate.Slow;
            v_promptBuilder.StartStyle(v_promptStyle);

            v_promptBuilder.AppendText("Chargement du CV en cours !", PromptEmphasis.Strong);
            v_promptBuilder.EndStyle();

            v_speechSynthesizer.SpeakAsync(v_promptBuilder);
        }
Esempio n. 6
0
        private void StartSpeech(AssignedVoice vb, string outputfile)
        {
            WinAvailableVoice wv = (WinAvailableVoice)vb.root;

            // Find the best audio format to use for this voice.
            System.Collections.ObjectModel.ReadOnlyCollection <SpeechAudioFormatInfo> formats =
                wv.winVoice.VoiceInfo.SupportedAudioFormats;

            format = formats.FirstOrDefault();

            if (format == null)
            {
                // The voice did not tell us its parameters, so we pick some.
                format = new SpeechAudioFormatInfo(
                    16000,      // Samples per second
                    AudioBitsPerSample.Sixteen,
                    AudioChannel.Mono);
            }

            // First set up to synthesize the message into a WAV file.
            mstream = new FileStream(outputfile, FileMode.Create, FileAccess.Write);

            syn.SetOutputToWaveStream(mstream);

            pb        = new PromptBuilder();
            mainStyle = new PromptStyle();
            //            mainStyle.Volume = promptVol;
            syn.SelectVoice(wv.winVoice.VoiceInfo.Name);
            pb.StartStyle(mainStyle);
        }
Esempio n. 7
0
 public void StartSpeech(string text, bool value, VoiceGender type)
 {
     if (value == true)
     {
         PromptBuilder promptBuilder = new PromptBuilder();
         PromptStyle   promptStyle   = new PromptStyle();
         promptStyle.Volume   = PromptVolume.Soft;
         promptStyle.Rate     = PromptRate.Slow;
         promptStyle.Emphasis = PromptEmphasis.Moderate;
         promptBuilder.StartStyle(promptStyle);
         promptBuilder.EndStyle();
         promptBuilder.AppendTextWithHint(text, SayAs.SpellOut);
         SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
         speechSynthesizer.SelectVoiceByHints(type);
         speechSynthesizer.Speak(promptBuilder);
     }
     else
     {
         PromptBuilder promptBuilder = new PromptBuilder();
         PromptStyle   promptStyle   = new PromptStyle();
         promptStyle.Volume   = PromptVolume.Soft;
         promptStyle.Rate     = PromptRate.Slow;
         promptStyle.Emphasis = PromptEmphasis.Moderate;
         promptBuilder.StartStyle(promptStyle);
         promptBuilder.EndStyle();
         promptBuilder.AppendText(text);
         SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
         speechSynthesizer.SelectVoiceByHints(type);
         speechSynthesizer.Speak(promptBuilder);
     }
 }
Esempio n. 8
0
        private void btnSayHello_Click(object sender, RoutedEventArgs e)
        {
            PromptBuilder promptBuilder = new PromptBuilder();

            promptBuilder.AppendText("Hello world");

            PromptStyle promptStyle = new PromptStyle();

            promptStyle.Volume = PromptVolume.Soft;
            promptStyle.Rate   = PromptRate.Slow;
            promptBuilder.StartStyle(promptStyle);
            promptBuilder.AppendText("and hello to the universe too.");
            promptBuilder.EndStyle();

            promptBuilder.AppendText("On this day, ");
            promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date);

            promptBuilder.AppendText(", we're gathered here to learn");
            promptBuilder.AppendText("all", PromptEmphasis.Strong);
            promptBuilder.AppendText("about");
            promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut);

            SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();

            speechSynthesizer.Speak(promptBuilder);
        }
Esempio n. 9
0
        /* public byte[] ConvertTextToWavStreamAsync(string text) {
         *  /*var task = new Task<Stream>(() => ConvertTextToAudio(text));
         *  task.Start();
         *  task.Wait();
         *  return task.Result;#1#
         *
         *
         *  byte[] byteArr = null;
         *
         *  var t = new System.Threading.Thread(() =>
         *  {
         *      SpeechSynthesizer ss = new SpeechSynthesizer();
         *      using (MemoryStream memoryStream = new MemoryStream())
         *      {
         *
         *      //    ManualResetEvent manualResetEvent = new ManualResetEvent(false);
         *          ss.SetOutputToWaveStream(memoryStream);
         *          ss.Speak(text);
         *
         *          byteArr = memoryStream.ToArray();
         *      }
         *  });
         *  t.Start();
         *  t.Join();
         *  return byteArr;
         * }*/

        /*byte[] byteArr = null;
         *
         *      SpeechSynthesizer ss = new SpeechSynthesizer();
         *      using (MemoryStream memoryStream = new MemoryStream())
         *      {
         *
         *          ManualResetEvent manualResetEvent = new ManualResetEvent(false);
         *          ss.SetOutputToWaveStream(memoryStream);
         *          ss.SpeakCompleted += (sender, args) =>
         *          {
         *              manualResetEvent.Set();
         *              ss.Dispose();
         *          };
         *          ss.SpeakAsync(text);
         *          manualResetEvent.WaitOne();
         *
         *          byteArr = memoryStream.ToArray();*/

        #region ISpeaker Members

        /// <summary>
        /// Конвертировать текст в фафл WAV
        /// </summary>
        /// <param name="text">текст</param>
        /// <returns>WAV файл в виде набора байтов</returns>
        public byte[] ConvertTextToAudio(string text)
        {
            var pbuilder = new PromptBuilder();
            var pStyle   = new PromptStyle
            {
                Emphasis = PromptEmphasis.None, Rate = PromptRate.Medium, Volume = PromptVolume.ExtraLoud
            };

            pbuilder.StartStyle(pStyle);
            pbuilder.StartParagraph();
            pbuilder.StartVoice(VoiceGender.Neutral, VoiceAge.Adult, 2);
            pbuilder.StartSentence();
            pbuilder.AppendText(text);
            pbuilder.EndSentence();
            pbuilder.EndVoice();
            pbuilder.EndParagraph();
            pbuilder.EndStyle();

            try {
                using (var memoryStream = new MemoryStream()) {
                    var speech = new SpeechSynthesizer();
                    speech.SetOutputToWaveStream(memoryStream);
                    speech.Speak(pbuilder);

                    memoryStream.Seek(0, SeekOrigin.Begin);

                    return(_mp3Converter.ConvertWavToMp3(memoryStream));
                }
            } catch (Exception e) {
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorException(
                    "Speaker.ConvertTextToAudio возникло исключение {0}", e);
            }
            return(null);
        }
        /// <summary>
        /// Sets the speed of the voicer.
        /// </summary>
        /// <param name="speedOfVoicer">
        /// Pass 0 for ExtraSlow, 1 for Slow, 2 for Normal, 3 for Fast, 4 for ExtraFast speed.
        /// </param>
        /// <returns></returns>
        public void SetSpeed(SpeedOfVoicer speedOfVoicer)
        {
            this.speedOfVoicer = speedOfVoicer;

            switch (speedOfVoicer)
            {
            case SpeedOfVoicer.ExtraSlow:
                voicerSpeed = (new PromptStyle(PromptRate.ExtraSlow));
                break;

            case SpeedOfVoicer.Slow:
                voicerSpeed = (new PromptStyle(PromptRate.Slow));
                break;

            case SpeedOfVoicer.Normal:
                voicerSpeed = (new PromptStyle(PromptRate.Medium));
                break;

            case SpeedOfVoicer.Fast:
                voicerSpeed = (new PromptStyle(PromptRate.Fast));
                break;

            case SpeedOfVoicer.ExtraFast:
                voicerSpeed = (new PromptStyle(PromptRate.ExtraFast));
                break;

            default:
                throw new InvalidEnumArgumentException("Invalid SpeedOfVoicer enum argument passed.");
            }
        }
Esempio n. 11
0
        private void startListenning_Click(object sender, RoutedEventArgs e)
        {
            PromptBuilder promptBuilder = new PromptBuilder();

            promptBuilder.AppendText("My name is ALFRED");

            PromptStyle promptStyle = new PromptStyle();

            promptStyle.Volume = PromptVolume.Soft;
            promptStyle.Rate   = PromptRate.Slow;
            promptBuilder.StartStyle(promptStyle);
            promptBuilder.AppendText("and I am pleased to meet you.");
            promptBuilder.EndStyle();

            promptBuilder.AppendText("Date: ");
            promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date);

            promptBuilder.AppendText("Now, I would like to tell you what you wrote");
            promptBuilder.AppendText("Ehm", PromptEmphasis.Strong);
            promptBuilder.AppendText(content.Text);

            SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();

            speechSynthesizer.Speak(promptBuilder);
        }
Esempio n. 12
0
 public static void Choice(IDialogContext context, ResumeAfter <T> resume, IEnumerable <T> options, string prompt,
                           string cancelPrompt     = null, string retry = null, int attempts = 3,
                           PromptStyle promptStyle = PromptStyle.Auto)
 {
     Choice(context, resume,
            new CancelablePromptOptions <T>(prompt, cancelPrompt, retry, attempts : attempts,
                                            options : options.ToList(), promptStyler : new PromptStyler(promptStyle)));
 }
Esempio n. 13
0
        public static bool CreateWavConvertToMp3File(string trgWavFile, string text)
        {
            var ps = new PromptStyle
            {
                Emphasis = PromptEmphasis.Strong,
                Volume   = PromptVolume.ExtraLoud
            };
            //pStyle.Rate = PromptRate.Fast;

            var pb = new PromptBuilder();

            pb.StartStyle(ps);
            pb.StartParagraph();
            pb.StartVoice(VoiceGender.Female, VoiceAge.Child);
            pb.StartSentence();
            pb.AppendBreak(TimeSpan.FromSeconds(.3)); // removed on Sep 26, 2011 // reesotred Jun 2013
            pb.AppendText(text, PromptRate.Medium);
            pb.AppendBreak(TimeSpan.FromSeconds(.3)); // removed on Sep 26, 2011 // reesotred Jun 2013
            pb.EndSentence();
            pb.EndVoice();
            pb.EndParagraph();
            pb.EndStyle();

            var tempWav = trgWavFile + ".WAV";

            using (var speaker = new SpeechSynthesizer())
            {
                //speaker.Speak(pbuilder);
                //	if (File.Exists(file))					File.Delete(file); // added Delete() on Sep 26, 2011.


                using (var fileStream = new FileStream(tempWav, FileMode.Create))
                {
                    try
                    {
                        speaker.Volume = 100;
                        speaker.SetOutputToWaveStream(fileStream); //

                        // speaker.SetOutputToWaveFile(tempWav);

                        speaker.Speak(pb); //nogo: this makes annoying beep and place it instead of the TTS message :                       using (var writer = new BinaryWriter(fileStream)) { new WaveFun.WaveGenerator(WaveFun.WaveExampleType.ExampleSineWave).Save_NotClose(writer); writer.Close();
                    }
                    catch (Exception ex) { ex.Log(); }
                    finally
                    {
                        speaker.SetOutputToDefaultAudioDevice();
                        fileStream.Close();
                    }
                }
            }

            NAudioHelper.ConvertWavToMp3(tempWav, trgWavFile);

            try { File.Delete(tempWav); }
            catch (Exception ex) { ex.Log(); }

            return(true);
        }
Esempio n. 14
0
        private static void SynthToCam(string text, CameraWindow cw)
        {
            var synthFormat = new System.Speech.AudioFormat.SpeechAudioFormatInfo(System.Speech.AudioFormat.EncodingFormat.Pcm, 11025, 16, 1, 22100, 2, null);

            using (var synthesizer = new SpeechSynthesizer())
            {
                using (var waveStream = new MemoryStream())
                {
                    //write some silence to the stream to allow camera to initialise properly
                    var silence = new byte[1 * 22050];
                    waveStream.Write(silence, 0, silence.Count());

                    var pbuilder = new PromptBuilder();
                    var pStyle   = new PromptStyle
                    {
                        Emphasis = PromptEmphasis.Strong,
                        Rate     = PromptRate.Slow,
                        Volume   = PromptVolume.ExtraLoud
                    };

                    pbuilder.StartStyle(pStyle);
                    pbuilder.StartParagraph();
                    pbuilder.StartVoice(VoiceGender.Male, VoiceAge.Adult, 2);
                    pbuilder.StartSentence();
                    pbuilder.AppendText(text);
                    pbuilder.EndSentence();
                    pbuilder.EndVoice();
                    pbuilder.EndParagraph();
                    pbuilder.EndStyle();

                    synthesizer.SetOutputToAudioStream(waveStream, synthFormat);
                    synthesizer.Speak(pbuilder);
                    synthesizer.SetOutputToNull();

                    //write some silence to the stream to allow camera to end properly
                    waveStream.Write(silence, 0, silence.Count());
                    waveStream.Seek(0, SeekOrigin.Begin);

                    var ds = new DirectStream(waveStream)
                    {
                        RecordingFormat = new WaveFormat(11025, 16, 1)
                    };
                    var talkTarget = TalkHelper.GetTalkTarget(cw.Camobject, ds);
                    ds.Start();
                    talkTarget.Start();
                    while (ds.IsRunning)
                    {
                        Thread.Sleep(100);
                    }
                    ds.Stop();
                    talkTarget.Stop();
                    talkTarget = null;
                    ds         = null;

                    waveStream.Close();
                }
            }
        }
Esempio n. 15
0
    /// <summary>
    /// Updates the style to the one in the UIStyler.
    /// </summary>
    /// <param name="style"></param>
    /// <param name="font"></param>
    public void SetStyle(PromptStyle style, Font font)
    {
        backgroundImage.sprite = style.backgroundImage;
        backgroundImage.color  = style.backgroundColor;

        yesButton.SetStyle(style.buttonStyle, font);
        yes2Button.SetStyle(style.buttonStyle, font);
        noButton.SetStyle(style.buttonStyle, font);
        okButton.SetStyle(style.buttonStyle, font);
    }
        protected override void ShowPrompt(PromptStyle promptStyle)
        {
            base.ShowPrompt(promptStyle);

            if (this.promptShownTask != null &&
                this.promptShownTask.Task.Status != TaskStatus.RanToCompletion)
            {
                this.promptShownTask.SetResult(true);
            }
        }
Esempio n. 17
0
 public FuzzyPromptDialog(IEnumerable <T> displayOptions, IEnumerable <T> validOptions,
                          string prompt, string retry, string tooManyAttempts, int attempts,
                          PromptStyle promptStyle = PromptStyle.Auto)
     : this(new FuzzyPromptOptions <T>(prompt, retry, tooManyAttempts,
                                       options : displayOptions.ToList(),
                                       attempts : attempts,
                                       validOptions : validOptions.ToList(),
                                       promptStyler : new PromptStyler(promptStyle)))
 {
 }
Esempio n. 18
0
        private static void SynthToCam(string text, CameraWindow cw)
        {
            var synthFormat = new System.Speech.AudioFormat.SpeechAudioFormatInfo(System.Speech.AudioFormat.EncodingFormat.Pcm, 11025, 16, 1, 22100, 2, null);
            using (var synthesizer = new SpeechSynthesizer())
            {
                using (var waveStream = new MemoryStream())
                {

                    //write some silence to the stream to allow camera to initialise properly
                    var silence = new byte[1 * 22050];
                    waveStream.Write(silence, 0, silence.Length);

                    var pbuilder = new PromptBuilder();
                    var pStyle = new PromptStyle
                    {
                        Emphasis = PromptEmphasis.Strong,
                        Rate = PromptRate.Slow,
                        Volume = PromptVolume.ExtraLoud
                    };

                    pbuilder.StartStyle(pStyle);
                    pbuilder.StartParagraph();
                    pbuilder.StartVoice(VoiceGender.Male, VoiceAge.Adult, 2);
                    pbuilder.StartSentence();
                    pbuilder.AppendText(text);
                    pbuilder.EndSentence();
                    pbuilder.EndVoice();
                    pbuilder.EndParagraph();
                    pbuilder.EndStyle();

                    synthesizer.SetOutputToAudioStream(waveStream, synthFormat);
                    synthesizer.Speak(pbuilder);
                    synthesizer.SetOutputToNull();

                    //write some silence to the stream to allow camera to end properly
                    waveStream.Write(silence, 0, silence.Length);
                    waveStream.Seek(0, SeekOrigin.Begin);

                    var ds = new DirectStream(waveStream) { RecordingFormat = new WaveFormat(11025, 16, 1) };
                    var talkTarget = TalkHelper.GetTalkTarget(cw.Camobject, ds); 
                    ds.Start();
                    talkTarget.Start();
                    while (ds.IsRunning)
                    {
                        Thread.Sleep(100);
                    }
                    ds.Stop();
                    talkTarget.Stop();
                    talkTarget = null;
                    ds = null;
                }
            }


        }
Esempio n. 19
0
 public static void Choice(IDialogContext context, ResumeAfter <T> resume,
                           IEnumerable <T> options, IEnumerable <T> validOptions,
                           string prompt, string retry = null, string tooManyAttempts = null,
                           int attempts = 3, PromptStyle promptStyle = PromptStyle.Auto)
 {
     Choice(context, resume, new FuzzyPromptOptions <T>(
                prompt, retry, tooManyAttempts,
                attempts : attempts, options : options.ToList(),
                validOptions : validOptions.ToList(),
                promptStyler : new PromptStyler(promptStyle)));
 }
 protected override void ShowPrompt(PromptStyle promptStyle)
 {
     eventWriter.SendEvent(
         ShowChoicePromptNotification.Type,
         new ShowChoicePromptNotification
         {
             Caption = this.Caption,
             Message = this.Message,
             Choices = this.Choices,
             DefaultChoice = this.DefaultChoice
         }).ConfigureAwait(false);
 }
Esempio n. 21
0
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            words = hyphenator.HyphenateText(InputTextBox.Text).Split(' ');

            int metronome1Notes, metronome2Notes;

            if (int.TryParse(Meter1Notes.Text, out metronome1Notes) && int.TryParse(Meter2Notes.Text, out metronome2Notes))
            {
                int        notes = LCM(metronome1Notes, metronome2Notes);
                List <int> beat  = new List <int>();

                for (int i = 0; i < notes; ++i)
                {
                    if (i % metronome1Notes == 0 || i % metronome2Notes == 0)
                    {
                        beat.Add(i);
                    }
                }

                List <TimeSpan> space = new List <TimeSpan>();
                for (int i = 0; i < beat.Count - 1; ++i)
                {
                    space.Add(new TimeSpan(defaultTimeSpan * (beat[i + 1] - beat[i])));
                }
                space.Add(new TimeSpan(defaultTimeSpan * (notes - beat[beat.Count - 1])));

                PromptBuilder promptBuilder = new PromptBuilder();

                PromptStyle promptStyle = new PromptStyle();
                promptStyle.Volume = PromptVolume.Soft;
                promptStyle.Rate   = PromptRate.Medium;
                promptBuilder.StartStyle(promptStyle);

                // Not the best at splitting but it works
                // P E O P L E
                words = hyphenator.HyphenateText(InputTextBox.Text).Split(' ');

                int timespanIndex = 0;
                foreach (string s in words)
                {
                    promptBuilder.AppendText(s);
                    promptBuilder.AppendBreak(space[timespanIndex++]);
                    if (timespanIndex >= space.Count())
                    {
                        timespanIndex = 0;
                    }
                }

                promptBuilder.EndStyle();

                speechSynthesizer.SpeakAsync(promptBuilder);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Say the introductory tag.
        /// </summary>
        /// <param name="text"></param>
        private void SayPrompt(string text)
        {
            PromptStyle intro = new PromptStyle();

            intro.Rate = voiceRate;
            //intro.Volume = promptVol - 1;
            intro.Emphasis = PromptEmphasis.Moderate;
            pb.StartStyle(intro);
            pb.StartSentence();
            pb.AppendText(text + ":");
            pb.EndSentence();
            pb.EndStyle();
        }
Esempio n. 23
0
 public static void SayAsnc(Settings settings, string text)
 {
     if (settings.Speech)
     {
         PromptBuilder builder = new PromptBuilder();
         PromptStyle   style   = new PromptStyle();
         style.Rate = PromptRate.Slow;
         builder.StartStyle(style);
         builder.AppendText(text);
         builder.EndStyle();
         speech.Volume = 100;
         speech.SpeakAsync(builder);
     }
 }
        /// <summary>
        /// Called when the prompt should be displayed to the user.
        /// </summary>
        /// <param name="promptStyle">
        /// Indicates the prompt style to use when showing the prompt.
        /// </param>
        protected override void ShowPrompt(PromptStyle promptStyle)
        {
            if (promptStyle == PromptStyle.Full)
            {
                if (this.Caption != null)
                {
                    this.hostOutput.WriteOutput(this.Caption);
                }

                if (this.Message != null)
                {
                    this.hostOutput.WriteOutput(this.Message);
                }
            }

            foreach (var choice in this.Choices)
            {
                string hotKeyString =
                    choice.HotKeyIndex > -1 ?
                    choice.Label[choice.HotKeyIndex].ToString().ToUpper() :
                    string.Empty;

                this.hostOutput.WriteOutput(
                    string.Format(
                        "[{0}] {1} ",
                        hotKeyString,
                        choice.Label),
                    false);
            }

            this.hostOutput.WriteOutput("[?] Help", false);

            var validDefaultChoices =
                this.DefaultChoices.Where(
                    choice => choice > -1 && choice < this.Choices.Length);

            if (validDefaultChoices.Any())
            {
                var choiceString =
                    string.Join(
                        ", ",
                        this.DefaultChoices
                        .Select(choice => this.Choices[choice].Label));

                this.hostOutput.WriteOutput(
                    $" (default is \"{choiceString}\"): ",
                    false);
            }
        }
 protected override void ShowPrompt(PromptStyle promptStyle)
 {
     messageSender
         .SendRequest(
             ShowChoicePromptRequest.Type,
             new ShowChoicePromptRequest
             {
                 Caption = this.Caption,
                 Message = this.Message,
                 Choices = this.Choices,
                 DefaultChoice = this.DefaultChoice
             }, true)
         .ContinueWith(HandlePromptResponse)
         .ConfigureAwait(false);
 }
 protected override void ShowPrompt(PromptStyle promptStyle)
 {
     messageSender
     .SendRequest(
         ShowChoicePromptRequest.Type,
         new ShowChoicePromptRequest
     {
         Caption       = this.Caption,
         Message       = this.Message,
         Choices       = this.Choices,
         DefaultChoice = this.DefaultChoice
     }, true)
     .ContinueWith(HandlePromptResponse)
     .ConfigureAwait(false);
 }
        public async Task SayText(string text, SpeechRate rate, SpeechVolume volume)
        {
            PromptStyle style = new PromptStyle();

            switch (rate)
            {
            case SpeechRate.ExtraFast: style.Rate = PromptRate.ExtraFast; break;

            case SpeechRate.Fast: style.Rate = PromptRate.Fast; break;

            case SpeechRate.Medium: style.Rate = PromptRate.Medium; break;

            case SpeechRate.Slow: style.Rate = PromptRate.Slow; break;

            case SpeechRate.ExtraSlow: style.Rate = PromptRate.ExtraSlow; break;
            }

            switch (volume)
            {
            case SpeechVolume.Default: style.Volume = PromptVolume.Default; break;

            case SpeechVolume.ExtraLoud: style.Volume = PromptVolume.ExtraLoud; break;

            case SpeechVolume.Loud: style.Volume = PromptVolume.Loud; break;

            case SpeechVolume.Medium: style.Volume = PromptVolume.Medium; break;

            case SpeechVolume.Soft: style.Volume = PromptVolume.Soft; break;

            case SpeechVolume.ExtraSoft: style.Volume = PromptVolume.ExtraSoft; break;
            }

            PromptBuilder prompt = new PromptBuilder();

            prompt.StartStyle(style);
            prompt.AppendText(text);
            prompt.EndStyle();

            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            Prompt            promptAsync = synthesizer.SpeakAsync(prompt);

            while (!promptAsync.IsCompleted)
            {
                await Task.Delay(1000);
            }
        }
Esempio n. 28
0
        protected override void ShowPrompt(PromptStyle promptStyle)
        {
            base.ShowPrompt(promptStyle);

            _languageServer.SendRequest <ShowChoicePromptRequest, ShowChoicePromptResponse>(
                "powerShell/showChoicePrompt",
                new ShowChoicePromptRequest
            {
                IsMultiChoice  = this.IsMultiChoice,
                Caption        = this.Caption,
                Message        = this.Message,
                Choices        = this.Choices,
                DefaultChoices = this.DefaultChoices
            })
            .ContinueWith(HandlePromptResponse)
            .ConfigureAwait(false);
        }
Esempio n. 29
0
        void promptSample()
        {
            var ps = new PromptStyle
            {
                Emphasis = PromptEmphasis.Strong,
                Volume   = PromptVolume.ExtraLoud
            };

            var pb = new PromptBuilder();

            pb.StartStyle(ps);
            pb.StartParagraph();

            pb.StartVoice(VoiceGender.Female, VoiceAge.Child);
            pb.StartSentence();
            pb.AppendText($"Female Child", PromptRate.Medium);
            pb.AppendBreak(TimeSpan.FromSeconds(.3));
            pb.EndSentence();
            pb.EndVoice();

            pb.StartVoice(VoiceGender.Female, VoiceAge.Senior);
            pb.StartSentence();
            pb.AppendText($"Female Senior", PromptRate.Medium);
            pb.AppendBreak(TimeSpan.FromSeconds(.3));
            pb.EndSentence();
            pb.EndVoice();

            pb.StartVoice(VoiceGender.Male, VoiceAge.Senior);
            pb.StartSentence();
            pb.AppendText($"Male Senior", PromptRate.Medium);
            pb.AppendBreak(TimeSpan.FromSeconds(.3));
            pb.EndSentence();
            pb.EndVoice();

            pb.StartVoice(VoiceGender.Male, VoiceAge.Child);
            pb.StartSentence();
            pb.AppendText($"Male Child", PromptRate.Medium);
            pb.AppendBreak(TimeSpan.FromSeconds(.3));
            pb.EndSentence();
            pb.EndVoice();

            pb.EndParagraph();
            pb.EndStyle();
            synth.SpeakAsyncCancelAll(); synth.SpeakAsync(pb);
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            //Original Code from: http://www.wpf-tutorial.com/audio-video/speech-synthesis-making-wpf-talk/


            PromptBuilder promptBuilder = new PromptBuilder();

            promptBuilder.AppendText("Hello world");

            PromptStyle promptStyle = new PromptStyle();

            promptStyle.Volume = PromptVolume.Soft;
            promptStyle.Rate   = PromptRate.Slow;
            promptBuilder.StartStyle(promptStyle);
            promptBuilder.AppendText("and hello to the universe too.");
            promptBuilder.EndStyle();

            promptBuilder.AppendText("On this day, ");
            promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date);

            promptBuilder.AppendText(", we're gathered here to learn");
            promptBuilder.AppendText("all", PromptEmphasis.Strong);
            promptBuilder.AppendText("about");
            promptBuilder.AppendTextWithHint("C Sharp", SayAs.SpellOut);

            SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();

            speechSynthesizer.Speak(promptBuilder);

            SpeechSynthesizer synth = new SpeechSynthesizer();

            // Configure the audio output.
            synth.SetOutputToWaveFile(@"C:\temp\test.wav");

            // Select the US English voice.
            synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-US, Helen)");

            // Build a prompt.
            PromptBuilder builder = new PromptBuilder();

            builder.AppendText("That is a big pizza!");

            // Speak the prompt.
            synth.Speak(builder);
        }
Esempio n. 31
0
 private void cmdPromptTest_Click(object sender, RoutedEventArgs e)
 {
     PromptBuilder prompt = new PromptBuilder();
     
     prompt.AppendText("How are you");            
     prompt.AppendBreak(TimeSpan.FromSeconds(2));
     prompt.AppendText("How ", PromptEmphasis.Reduced);
     PromptStyle style = new PromptStyle();
     style.Rate = PromptRate.ExtraSlow;
     style.Emphasis = PromptEmphasis.Strong;
     prompt.StartStyle(style);
     prompt.AppendText("are ");
     prompt.EndStyle();            
     prompt.AppendText("you?");          
     
     
     
     SpeechSynthesizer synthesizer = new SpeechSynthesizer();
     synthesizer.Speak(prompt);
     
 }
        /// <summary>
        /// Called when the prompt should be displayed to the user.
        /// </summary>
        /// <param name="promptStyle">
        /// Indicates the prompt style to use when showing the prompt.
        /// </param>
        protected override void ShowPrompt(PromptStyle promptStyle)
        {
            if (promptStyle == PromptStyle.Full)
            {
                if (this.Caption != null)
                {
                    this.consoleHost.WriteOutput(this.Caption);
                }

                if (this.Message != null)
                {
                    this.consoleHost.WriteOutput(this.Message);
                }
            }

            foreach (var choice in this.Choices)
            {
                string hotKeyString =
                    choice.HotKeyIndex > -1 ?
                        choice.Label[choice.HotKeyIndex].ToString().ToUpper() :
                        string.Empty;

                this.consoleHost.WriteOutput(
                    string.Format(
                        "[{0}] {1} ",
                        hotKeyString,
                        choice.Label),
                    false);
            }

            this.consoleHost.WriteOutput("[?] Help", false);

            if (this.DefaultChoice > -1 && this.DefaultChoice < this.Choices.Length)
            {
                this.consoleHost.WriteOutput(
                    string.Format(
                        " (default is \"{0}\"):",
                        this.Choices[this.DefaultChoice].Label));
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Called when the prompt should be displayed to the user.
        /// </summary>
        /// <param name="promptStyle">
        /// Indicates the prompt style to use when showing the prompt.
        /// </param>
        protected override void ShowPrompt(PromptStyle promptStyle)
        {
            if (promptStyle == PromptStyle.Full)
            {
                if (this.Caption != null)
                {
                    this.consoleHost.WriteOutput(this.Caption);
                }

                if (this.Message != null)
                {
                    this.consoleHost.WriteOutput(this.Message);
                }
            }

            foreach (var choice in this.Choices)
            {
                string hotKeyString =
                    choice.HotKeyIndex > -1 ?
                    choice.Label[choice.HotKeyIndex].ToString().ToUpper() :
                    string.Empty;

                this.consoleHost.WriteOutput(
                    string.Format(
                        "[{0}] {1} ",
                        hotKeyString,
                        choice.Label),
                    false);
            }

            this.consoleHost.WriteOutput("[?] Help", false);

            if (this.DefaultChoice > -1 && this.DefaultChoice < this.Choices.Length)
            {
                this.consoleHost.WriteOutput(
                    string.Format(
                        " (default is \"{0}\"):",
                        this.Choices[this.DefaultChoice].Label));
            }
        }
Esempio n. 34
0
        private void cmdPromptTest_Click(object sender, RoutedEventArgs e)
        {
            PromptBuilder prompt = new PromptBuilder();

            prompt.AppendText("How are you");
            prompt.AppendBreak(TimeSpan.FromSeconds(2));
            prompt.AppendText("How ", PromptEmphasis.Reduced);
            PromptStyle style = new PromptStyle();

            style.Rate     = PromptRate.ExtraSlow;
            style.Emphasis = PromptEmphasis.Strong;
            prompt.StartStyle(style);
            prompt.AppendText("are ");
            prompt.EndStyle();
            prompt.AppendText("you?");



            SpeechSynthesizer synthesizer = new SpeechSynthesizer();

            synthesizer.Speak(prompt);
        }
Esempio n. 35
0
        private void OnPrompt(object sender, RoutedEventArgs e)
        {
            var promptBuilder = new PromptBuilder();

            promptBuilder.AppendText("How are you");
            promptBuilder.AppendBreak(TimeSpan.FromSeconds(2));
            promptBuilder.AppendText("How ", PromptEmphasis.Reduced);
            var style = new PromptStyle
            {
                Rate     = PromptRate.ExtraSlow,
                Emphasis = PromptEmphasis.Strong
            };

            promptBuilder.StartStyle(style);
            promptBuilder.AppendText("are ");
            promptBuilder.EndStyle();
            promptBuilder.AppendText("you?");

            var synthesizer = new SpeechSynthesizer();

            synthesizer.Speak(promptBuilder);
        }
Esempio n. 36
0
        public override bool Apply(PromptBuilder builder)
        {
            String speed = ParseTagArgument().ToLowerInvariant();

            PromptRate rate;

            switch (speed)
            {
            case "fast":
                rate = PromptRate.Fast;
                break;

            case "medium":
                rate = PromptRate.Medium;
                break;

            case "slow":
                rate = PromptRate.Slow;
                break;

            case "extra fast":
                rate = PromptRate.ExtraFast;
                break;

            case "extra slow":
                rate = PromptRate.ExtraSlow;
                break;

            default:
                return(false);
            }

            PromptStyle style = new PromptStyle(rate);

            builder.StartStyle(style);
            return(true);
        }
 /// <summary>
 /// Called when the prompt should be displayed to the user.
 /// </summary>
 /// <param name="promptStyle">
 /// Indicates the prompt style to use when showing the prompt.
 /// </param>
 protected abstract void ShowPrompt(PromptStyle promptStyle);
 protected override void ShowPrompt(PromptStyle promptStyle)
 {
     // No action needed, just count the prompts.
     this.TimesPrompted++;
 }
Esempio n. 39
0
 /// <summary>
 /// Say the introductory tag.
 /// </summary>
 /// <param name="text"></param>
 private void SayPrompt(string text)
 {
     PromptStyle intro = new PromptStyle();
     intro.Rate = voiceRate;
     //intro.Volume = promptVol - 1;
     intro.Emphasis = PromptEmphasis.Moderate;
     pb.StartStyle(intro);
     pb.StartSentence();
     pb.AppendText(text + ":");
     pb.EndSentence();
     pb.EndStyle();
 }
Esempio n. 40
0
        private void StartSpeech(AssignedVoice vb, string outputfile)
        {
            WinAvailableVoice wv = (WinAvailableVoice)vb.root;

            // Find the best audio format to use for this voice.
            System.Collections.ObjectModel.ReadOnlyCollection<SpeechAudioFormatInfo> formats =
                wv.winVoice.VoiceInfo.SupportedAudioFormats;

            format = formats.FirstOrDefault();

            if (format == null)
            {
                // The voice did not tell us its parameters, so we pick some.
                format = new SpeechAudioFormatInfo(
                    16000,      // Samples per second
                    AudioBitsPerSample.Sixteen,
                    AudioChannel.Mono);
            }

            // First set up to synthesize the message into a WAV file.
            mstream = new FileStream(outputfile, FileMode.Create, FileAccess.Write);

            syn.SetOutputToWaveStream(mstream);

            pb = new PromptBuilder();
            mainStyle = new PromptStyle();
            //            mainStyle.Volume = promptVol;
            syn.SelectVoice(wv.winVoice.VoiceInfo.Name);
            pb.StartStyle(mainStyle);
        }
Esempio n. 41
0
        /// <summary>
        /// Say the main part of the message.
        /// </summary>
        /// <param name="utterance"></param>
        private void SaySegment(QueuedSpeech utterance)
        {
            PromptStyle body = new PromptStyle();
            switch (utterance.voice.rateModification)
            {
                case 00: body.Rate = PromptRate.Medium; break;
                case +1: body.Rate = PromptRate.Fast; break;
                case -1: body.Rate = PromptRate.Slow; break;
            }
            switch (utterance.voice.pitchModification)
            {
                case 00: body.Emphasis = PromptEmphasis.Moderate; break;
                case +1: body.Emphasis = PromptEmphasis.Strong; break;
                case -1: body.Emphasis = PromptEmphasis.Reduced; break;
            }

            pb.StartStyle(body);
            pb.StartSentence();
            pb.AppendText(utterance.message);
            pb.EndSentence();
            pb.EndStyle();
        }
Esempio n. 42
0
 /// <summary>
 /// Say the introductory tag.
 /// </summary>
 /// <param name="text"></param>
 private void SayPrompt(string text)
 {
     PromptStyle intro = new PromptStyle();
     intro.Rate = PromptRate.Fast;
     intro.Volume = promptVol - 1;
     intro.Emphasis = PromptEmphasis.Reduced;
     pb.StartStyle(intro);
     pb.StartSentence();
     pb.AppendText(text + ":");
     pb.EndSentence();
     pb.EndStyle();
 }
 protected override void ShowPrompt(PromptStyle promptStyle)
 {
     base.ShowPrompt(promptStyle);
     if (this.promptShownTask != null &&
         this.promptShownTask.Task.Status != TaskStatus.RanToCompletion)
     {
         this.promptShownTask.SetResult(true);
     }
 }