Speech Translation in C#.NET


  1. This is to translate the text as speech.
  2. This makes us to listen a voice from the speakers that reads some specified text.
  3. Library: System.Speech.Synthesis.SpeechSynthesizer
  4. This class used to speak the required text through the speakers.

Implementation:

  • Create the object of "SpeechSynthesizer" class:
  • SpeechSynthesizer ss = new SpeechSynthesizer();
  • Set the volume (1 to 100):
  • ss.Volume = n;
  • Set the speed of speaking (-10 to +10):
  • ss.Rate = n;
  • Change the voice gender and age:
  • ss.SelectVoiceByHints(VoiceGender.xxxx, VoiceAge.xxxx);
  • Speak the text:
  • ss.SpeakAsync("message");

C# Code : Speech Translation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;
namespace SpeechTranslationDemo
{
 class Program
  {
   static void Main(string[] args)
    {
     Console.WriteLine("Enter text to speak:");
     string TextToSpeak = Console.ReadLine();
     SpeechSynthesizer ss = new SpeechSynthesizer();
     ss.Volume = 100; //1 to 100 
     ss.Rate = -3; // -10 to +10 
     ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
     ss.SpeakAsync(TextToSpeak);
     Console.Read();
    }
  }
}
0 Komentar untuk "Speech Translation in C#.NET"

Back To Top