2018-05-05 10:56:04

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
    }
}

Put your coding where your mouth is.

2018-05-05 14:56:52

the nvda ones are easy to find though I don't know about that nvdahelper.dll, I know what the nvdahelper.exe is though, its like a bridge that the nvda.exe process offloads work to because nvda.exe is 32 bit ,and nvdahelper is 64 bit, and the two processes communicate back and forth.

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united

2018-05-05 16:36:26

consider adding  auto-detection, or minimally a boolian to see if the reader the user wishes to speak through is even active.

With NVDA it's simply nvdaController_testIfRunning.
The same can't be said for JFW, although you could always see if speaking a blank string is successful.