Hello Everyone,
So this class is for text to speech for the following screenreaders.
Jaws
Windows Narrator
NVDA
What can you do with this class?
Simply put, you can use this to implent text to speech in your C Sharp projects.
How to use?
1: TTSEngine.Engine = Engine.NVDA;
Using the above statement you can set the engine you wish to use.
2: Rate, Volume etc.
These are only used for windows narrator.
And speak for itself ( See what i did there?).
3: TTSEngine.Speak("Hello World");
Using the above function you can make it say whatever you wish.
Requirements:
You will need the following libraries for it to work.
FSAPI.dll (Jaws library).
nvdaControllerClient.dll
nvdaHelperLocal.dll
I cant share these libraries.
You will need to find them online or contact me so i can send them personally.
The class i wrote ifs for simplified purposes.
For programmers that are more advanced i know i should use constructor , destructor handling completed states etc.
However like i state i wanted it as simple as possible.
Withouth it running into issues.
So below you will find the class.
Enjoy.
//Project: TextToSpeech
//Class: TTSEngine.cs
//Author: XSense.
#region Imports
using System;
using FSAPILib;
using System.Runtime.InteropServices;
#endregion
namespace TextToSpeech
{
class TTSEngine
{
#region DLL Imports
[DllImport("nvdaControllerClient.dll", CharSet = CharSet.Unicode)]
static extern long nvdaController_speakText(String text);
#endregion
#region Fields
public static int Volume { get; set; }
public static int Rate { get; set; }
public static int VoiceID { get; set; }
public static Engine SpeechEngine { get; set; }
#endregion
#region Enumeration
public enum Engine
{
Default, NVDA, Jaws
}
#endregion
#region Engines
private static FSAPILib.JawsApi Jaws = new JawsApi();
private static System.Speech.Synthesis.SpeechSynthesizer DefaultEngine = new System.Speech.Synthesis.SpeechSynthesizer();
#endregion
#region Speak
/// Speaks Message Using TTSEngine
/// <summary>
/// </summary>
/// <param name="info">String Message</param>
public static void Speak(string info)
{
try
{
//Switch on engine
switch (SpeechEngine)
{
case Engine.Default:
DefaultEngine.Volume = 100;
//DefaultEngine.Rate = Rate;
DefaultEngine.SpeakAsync(info);
break;
case Engine.Jaws:
Jaws.SayString(info);
break;
case Engine.NVDA:
nvdaController_speakText(info);
break;
}
}
catch (Exception)
{
}
}
#endregion
}
}