C language calling SAPI speech

SAPI is not a new thing, and
I still can not find the current method of direct call SAPI, can only borrow vbs to transition:
Example:

#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
VOID Say(LPCSTR lpText) 
{ 
 FILE *fp;
 fp=fopen("spkTmp.vbs","w");
 if(fp == NULL)
 {
     printf("无法打开临时文件!\n");
  return;
 }
 fprintf(fp,"Createobject(\"sapi.SpVoice\").Speak \"%s\"",lpText);
 fclose(fp);
 system("attrib +h spkTmp.vbs");
 ShellExecute(0,"open","wscript.exe","\"spkTmp.vbs\"","",SW_SHOW);
 system("attrib -h spkTmp.vbs");
 Sleep(300);
 system("del spkTmp.vbs");
 return;
}
int main()
{
 Say("你好!");
 return 0;
}

No amount of ... Sleep (300) wscript'll miss this one deleted vbs, after all, has little effect on the speed of the program.

Released eight original articles · won praise 1 · views 1099

Guess you like

Origin blog.csdn.net/cjz2005/article/details/104415742