Re: [Carbon] Using Speech in Cocoa
Re: [Carbon] Using Speech in Cocoa
- Subject: Re: [Carbon] Using Speech in Cocoa
- From: Brian Webster <email@hidden>
- Date: Sun, 30 Sep 2001 16:25:20 -0500
On Sunday, September 30, 2001, at 03:55 PM, cocoa-dev-
email@hidden wrote:
I've just started playing around with SpeechSynthesis from one of my
cocoa docklings. What I understand is that I simply need to call
SpeakString (SpeakString([AlarmTitle cString]);) to have the default
voice telling me something. Unfortunately, what it doesn't say what it
should ('Time to go home'), but rather something like 'loren bfx qt".
And if I call the string directly(SpeakString ("Time to go
home"), I get
"Time to go home as in FulScreenView" which happens to be the name of
the class. Weird huh?
The problem is that SpeakString() takes a Pascal style string as
input, not a C string. In a Pascal string, the first byte holds
a number telling how long the string is, and the rest of the
bytes hold the characters. So when you pass a C string into the
function, it takes the first byte as the length and speaks that
number of characters, even if it passes the null character that
marks the end of the C string.
The easiest way to get a Pascal string from an NSString is to
use the CoreFoundation function CFStringGetPascalStringPtr().
SpeakString(CFStringGetPascalStringPtr((CFStringRef)AlarmTitle));
You should read the notes at the top of CFString.h regarding
some conditions where this function may return NULL.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster