Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Set voice in Text to Speech

C# Set voice in Text to Speech

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rockallica
    wrote on last edited by
    #1

    Hi, How do I set the voice in Text to Speech in C#? I have a toolStripMenu that I load the voices into. Then when one is chosen, I want it to use that voice. Haven't been able to figure set the voice to the chosen name. Thanks.

    private void Get_Voices()
    {
    ISpeechObjectTokens voices = objSpeech.GetVoices("", "");

    foreach (ISpeechObjectToken v in voices)
    {
              ts\_Menu = new ToolStripMenuItem();
    
               v\_name = v.GetDescription(0);
    
               ts\_Menu.Text = v\_name;
    
               ts\_Menu.CheckOnClick = true;
    
               voicesToolStripMenu.DropDownItems.Add(ts\_Menu);
               
                ts\_Menu.Click += voice\_Menu\_Click;
     }
    

    }

    private void voice_Menu_Click(object sender, EventArgs e)
    {
    ToolStripMenuItem item = sender as ToolStripMenuItem;
    foreach (ToolStripMenuItem tempItemp in voicesToolStripMenu.DropDownItems)
    {

             if (tempItemp == item)
             {
                   tempItemp.Checked = true;
              } 
               else
               {
                   tempItemp.Checked = false;
                } 
           }
    
           choosen\_voice = sender.ToString();
    

    }

    private void Speak(string txt)
    {

     SpVoice objSpeech = new SpVoice();
    
     objSpeech.Speak(txt, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            
     objSpeech.WaitUntilDone(Timeout.Infinite);
    

    }

    OriginalGriffO 1 Reply Last reply
    0
    • R Rockallica

      Hi, How do I set the voice in Text to Speech in C#? I have a toolStripMenu that I load the voices into. Then when one is chosen, I want it to use that voice. Haven't been able to figure set the voice to the chosen name. Thanks.

      private void Get_Voices()
      {
      ISpeechObjectTokens voices = objSpeech.GetVoices("", "");

      foreach (ISpeechObjectToken v in voices)
      {
                ts\_Menu = new ToolStripMenuItem();
      
                 v\_name = v.GetDescription(0);
      
                 ts\_Menu.Text = v\_name;
      
                 ts\_Menu.CheckOnClick = true;
      
                 voicesToolStripMenu.DropDownItems.Add(ts\_Menu);
                 
                  ts\_Menu.Click += voice\_Menu\_Click;
       }
      

      }

      private void voice_Menu_Click(object sender, EventArgs e)
      {
      ToolStripMenuItem item = sender as ToolStripMenuItem;
      foreach (ToolStripMenuItem tempItemp in voicesToolStripMenu.DropDownItems)
      {

               if (tempItemp == item)
               {
                     tempItemp.Checked = true;
                } 
                 else
                 {
                     tempItemp.Checked = false;
                  } 
             }
      
             choosen\_voice = sender.ToString();
      

      }

      private void Speak(string txt)
      {

       SpVoice objSpeech = new SpVoice();
      
       objSpeech.Speak(txt, SpeechVoiceSpeakFlags.SVSFlagsAsync);
              
       objSpeech.WaitUntilDone(Timeout.Infinite);
      

      }

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      See here: Speech - Text-To-Speech Synthesis in .NET | Microsoft Docs[^] - it includes sample code which does that.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      R 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        See here: Speech - Text-To-Speech Synthesis in .NET | Microsoft Docs[^] - it includes sample code which does that.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        R Offline
        R Offline
        Rockallica
        wrote on last edited by
        #3

        I see. Thanks!

        OriginalGriffO 1 Reply Last reply
        0
        • R Rockallica

          I see. Thanks!

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You're welcome - but please try the official documentation first next time! :laugh:

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups