Hello World
Moderators: hgm, Rebel, chrisw
-
- Posts: 27809
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Hello World
Does anyone happen to know an example of a "Hello World" program in plain C that speaks the sentence using the Windows SAPI?
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: Hello World
Here it is (Windows in all its concision...) :
Source: http://www.paulgriffiths.net/program/c/winhello.php
Code: Select all
/*
WINHELLO.C
==========
(c) Paul Griffiths 1999
Email: mail@paulgriffiths.net
"Hello, world!", Win32 style.
*/
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/* WinMain(), our entry point */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR szCmdLine, int iCmdShow) {
static char szAppName[] = "winhello";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
/* Fill in WNDCLASSEX struct members */
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
/* Register a new window class with Windows */
RegisterClassEx(&wndclass);
/* Create a window based on our new class */
hwnd = CreateWindow(szAppName, "Hello, world!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
/* Show and update our window */
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
/* Retrieve and process messages until we get WM_QUIT */
while ( GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg); /* for certain keyboard messages */
DispatchMessage(&msg); /* send message to WndProc */
}
/* Exit with status specified in WM_QUIT message */
return msg.wParam;
}
/* Window procedure */
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
/* Switch according to what type of message we have received */
switch ( iMsg ) {
case WM_PAINT:
/* We receive WM_PAINT every time window is updated */
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 100, 100, "Hello, world!", 13);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
/* Window has been destroyed, so exit cleanly */
PostQuitMessage(0);
return 0;
}
/* Send any messages we don't handle to default window procedure */
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 27809
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Hello World
This does not speak, does it? It only prints.
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: Hello World
Oh, sorry, I thought that was a figure of speech, when you wrote "speaks"...hgm wrote:This does not speak, does it? It only prints.
But I guess you probably yet saw Microsoft's SAPI tutorial ?
http://msdn.microsoft.com/en-us/library ... s.85).aspx
It's all C++ though...
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 27809
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Hello World
Indeed, that is the problem. I would need an example how to make it work from a C program. (In particular, WinBoard for the visually impaired...)
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: Hello World
That explains where the Winboard users come from! ^^hgm wrote:Indeed, that is the problem. I would need an example how to make it work from a C program. (In particular, WinBoard for the visually impaired...)
(Sorry, H.G., I had to make the joke! )
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Hello World
Try the bottom of this article. I have not installed the SAPI SDK so I could not compile it. But it looks plausible. You need to remove the "::" qualifiers, define COBJMACROS, change the calls "pVoice->..." into "ISpVoice_...", and hope for the besthgm wrote:Indeed, that is the problem. I would need an example how to make it work from a C program. (In particular, WinBoard for the visually impaired...)
Be sure to fix the syntax error near the end of the line containing "CoCreateInstance". Also watch out for necessary #include-s.
Sven
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Hello World
Link fixed.JuLieN wrote:Oh, sorry, I thought that was a figure of speech, when you wrote "speaks"...hgm wrote:This does not speak, does it? It only prints.
But I guess you probably yet saw Microsoft's SAPI tutorial ?
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
It's all C++ though...
-
- Posts: 31
- Joined: Tue Dec 07, 2010 11:19 pm
- Location: Holland
Re: Hello World
I am not sure if this is what you mean but Petzold Programming for windows 95 has an example of a speaking program in chapter 1.
Let me know please if you are interested then i go look it up for you.
groeten
Pierre
Let me know please if you are interested then i go look it up for you.
groeten
Pierre
-
- Posts: 317
- Joined: Mon Jun 26, 2006 9:44 am
Re: Hello World
You can execute C++ code from a c program:
http://dsc.sun.com/solaris/articles/mix ... cpp_from_c
Here there is a SAPI hello world program in C++:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Or if as want to do things directly, this thread is about using SAPI 5.3 in c:
http://cboard.cprogramming.com/c-progra ... api-c.html
or you could use a TTS written for c:
http://www.speech.cs.cmu.edu/flite/index.html
Good luck!
EDIT: The 2nd and 3rd links appear to duplicate links already provided in this thread so you may find clicking on them to be redundant. FYI
http://dsc.sun.com/solaris/articles/mix ... cpp_from_c
Here there is a SAPI hello world program in C++:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Or if as want to do things directly, this thread is about using SAPI 5.3 in c:
http://cboard.cprogramming.com/c-progra ... api-c.html
or you could use a TTS written for c:
http://www.speech.cs.cmu.edu/flite/index.html
Good luck!
EDIT: The 2nd and 3rd links appear to duplicate links already provided in this thread so you may find clicking on them to be redundant. FYI