SapiSpeech.dll - A Wrapper for Microsoft Speech API
  Download it ->  SapiSpeech



Overview :


SapiSpeech.dll is a dynamic linking library written by Ammar Qammaz to simplify the process of importing Speech without using managed-code :) in non Visual-Studio compiled applications.

The library contains very few calls , and in the future I plan to also provide an interface for speech recognition ( right now , only computer speech is included )

In order to use it , you will need a PC with Windows 9x/XP/Vista  and The Speech API redistributables..
You can download version 5.1 The Speech API redistributables here , you propably want SpeechSDK51.exe ( Windows Vista users have 5.3 preinstalled so you don`t need it)

SapiSpeech.dll was compiled using Visual Studio 2003

Exports :


//BASIC FUNCTIONALITY
bool _stdcall InitSpeech()  // Required one time at the start of the program
bool _stdcall UnInitSpeech()
// Required one time at the end of the program

//SPEAKING
// consists of two parts , (1) passing a string to the library and (2) order the Sapi to speak

     // PASSING STRINGS (For  languages that do not have a char array data type)
     
void _stdcall Speech_PassNewString(unsigned int charlen)   // Pass new string with a total of  "charlen" characters
     unsigned int _stdcall Speech_GetStringLength()
// Get Length of string currently loaded
     char _stdcall Speech_GetStringChar(unsigned int thech)   // Return Character with character number "thech" (First character is character 0 , last character is character Speech_GetStringLength() -1 )
     void _stdcall Speech_SetStringChar(unsigned int thech,char theval)
// Pass Character with character number "thech" and value "theval" (First character is character 0 , last character is character Speech_GetStringLength() -1 )

   
      //SPEAKING
      void _stdcall SaySomething()
    void _stdcall SayString(const char * thestr)




Code Sample #1 (Dev-C++) :


//THIS CODE WILL START A  CONSOLE WINDOW , LOAD THE DLL FUNCTIONS AND START TALKING :)

#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;


typedef bool (*InitSpeech)();
typedef bool (*UnInitSpeech)();
typedef void (*SaySomething)();
typedef void (*Speech_PassNewString)(const unsigned int);
typedef void (*Speech_SetStringChar)(const unsigned int,const char);
typedef char (*Speech_GetStringChar)(const unsigned int);
typedef char (*SayString)( const char *);


HINSTANCE hInstLibrary;
InitSpeech _InitSpeech;
UnInitSpeech _UnInitSpeech;
SaySomething _SaySomething;
Speech_PassNewString _Speech_PassNewString;
Speech_SetStringChar _Speech_SetStringChar;
Speech_GetStringChar _Speech_GetStringChar;
SayString _SayString;

 
char* itoa(int val, int base){
   
    static char buf[32] = {0};
   
    int i = 30;
   
    for(; val && i ; --i, val /= base)
   
        buf[i] = "0123456789abcdef"[val % base];
   
    return &buf[i+1];
   
}

int main(int argc, char *argv[])
{
   
    printf("%s","Loading Library..\n");
    hInstLibrary = LoadLibrary("SapiSpeech.dll");
      if (hInstLibrary)
     {
       printf("%s","Connecting Procedures..\n");
       _InitSpeech = (InitSpeech)GetProcAddress(hInstLibrary, "InitSpeech");
       _UnInitSpeech = (UnInitSpeech)GetProcAddress(hInstLibrary, "UnInitSpeech");
       _SaySomething = (SaySomething)GetProcAddress(hInstLibrary, "SaySomething");
       _Speech_PassNewString = (Speech_PassNewString)GetProcAddress(hInstLibrary, "Speech_PassNewString");
       _Speech_SetStringChar = (Speech_SetStringChar)GetProcAddress(hInstLibrary, "Speech_SetStringChar");
       _Speech_GetStringChar = (Speech_GetStringChar)GetProcAddress(hInstLibrary, "Speech_GetStringChar");
       _SayString = (SayString)GetProcAddress(hInstLibrary, "SayString");
     
  
       if (_InitSpeech) {} else printf("%s","Something went wrong with InitSpeech\n");
       if (_UnInitSpeech) {} else printf("%s","Something went wrong with UnInitSpeech\n");
       if (_SaySomething) {} else printf("%s","Something went wrong with SaySomething\n");
       if (_Speech_PassNewString) {} else printf("%s","Something went wrong with Speech_PassNewString\n");
       if (_Speech_SetStringChar) {} else printf("%s","Something went wrong with Speech_SetStringChar\n");
       if (_SayString) {} else printf("%s","Something went wrong with SayString\n");
     
       printf("%s","Initializing..\n");
      
          _InitSpeech();
        
          _SaySomething();  // Will say : "Hello World This is SapiSpeech.dll version x.xx"  (This is because we haven`t passed a string yet)
          
           _SayString("I believe this sample code is very self-explanitory!");  //  :)
          
           _SayString("Plus , it is working fine");
          
          
           _SayString("I will now count to 10");
           _SayString("And then exit gracefully!");
            
              char thenum[3];
              for (int i=1; i<=10; i++)
               { 
                  _SayString(itoa(i,10));
                  Sleep(100);
               }
                        
           _SayString("Thank you for your time!");
           _SayString("My job is done!");
           _SayString("Bye bye");
          
          _UnInitSpeech();

        FreeLibrary(hInstLibrary);
        printf("%s","Run ending..\n");
   
     }  else
    printf("%s","Could not load DLL Functions , check if SapiSpeech.dll is in the same folder as the executable\n");
     
    
    return EXIT_SUCCESS;
}