
FAQ about .Net Text to Speech converter
.Net has System.Speech.Synthesis namespace that contains class to work with text-to-speech synthesizer software. Usually TTS is already installed on Windows machine and can be used in applications.
How to use TTS converter in .Net?
TTS converter is placed in System.Speech.Synthesis namespace, but it is not a part of default namespaces. Therefore it should be added to references:
- In Visual Studio Solution explorer right click on References of .Net Framework project
- Click on Add reference…
- Assemblies – Framework – System.Speech – Ok
- Add using System.Speech.Synthesis;
How to install voices for TTS on Windows 10?
- Open Speech settings (from Start menu)
- In Speech tab you can see all the installed voices
- In Language tab you can choose language that supports Speech to download or set Speech for installed languages if it is possible
How to show installed voices?
SpeechSynthesizer class has GetInstalledVoices method that returns collection of InstalledVoice class exemplars items. InstalledVoice class contains VoiceInfo class property that contains description of a voice:
- Name
- Age
- Gender
- Culture
- and so on
... SpeechSynthesizer synthesizer = new SpeechSynthesizer(); //getting collection of installed voices ReadOnlyCollection voices = synthesizer.GetInstalledVoices(); foreach(var voice in voices) { string name = voice.VoiceInfo.Name; //get name of a voice Console.WriteLine(name); //show name in console } synthesizer.Dispose(); ...
How to choose voice for TTS?
To use a specific voice it is should be enabled and chosen (by its name) in SpeechSynthesizer class exemplar.
... public static void TestVoice(InstalledVoice voice) { voice.Enabled = true; using (SpeechSynthesizer synthesizer = new SpeechSynthesizer()) { synthesizer.SelectVoice(voice.VoiceInfo.Name); ... } } ...
How to listen to input text using TTS?
... SpeechSynthesizer synthesizer = new SpeechSynthesizer(); ReadOnlyCollection voices = synthesizer.GetInstalledVoices(); InstalledVoice voice = voices[0]; voice.Enabled = true; synthesizer.SelectVoice(voice.VoiceInfo.Name); synthesizer.SetOutputToDefaultAudioDevice(); synthesizer.Speak($"Hello, my name is {voice.VoiceInfo.Name}."); ...
How to convert text to speech and save in audio file?
... synthesizer.SetOutputToWaveFile("speech.wav"); //pass a path to save audio file in .wav synthesizer.Speak("Hello, i am talking from an audio file!"); ...
How to set voice volume?
... synthesizer.Volume = 50; //Volume is a value from 0 to 100 ...
How to set voice rate?
... synthesizer.Rate = 5; //from -10 to 10 ...