void Speak(const void *text, long size) { SpeechChannel chan; NewSpeechChannel (NULL, &chan); SetSpeechInfo(chan, soSpeechDoneCallBack, (void*)&SpeakingDone); SpeakText (chan, text, size); }
int SayTextInit(void) { OSErr err; long response; long mask; VoiceSpec defaultVoiceSpec; VoiceDescription voiceDesc; err = Gestalt(gestaltSpeechAttr, &response); if (err != noErr) { fprintf(stderr,"can't init Mac Speech Synthesis\n"); return(1); } mask = 1 << gestaltSpeechMgrPresent; if ((response & mask) == 0) { fprintf(stderr,"Mac Speech not supported\n"); return(1); } err = GetVoiceDescription(nil, &voiceDesc, sizeof(voiceDesc)); defaultVoiceSpec = voiceDesc.voice; err = NewSpeechChannel( &defaultVoiceSpec, &channel ); if (err != noErr) { DisposeSpeechChannel(channel); fprintf(stderr,"Failed to open a speech channel\n"); return(1); } last_speech_text[0] = '\0'; last_speech_time = (time_t)0; return(0); }
int main(int argc, char **argv) { OSErr rc; SpeechChannel channel; VoiceSpec vs; int voice; char *text = "What do you want to say?"; if (!argv[1]) { voice = 1; } else { voice = atoi(argv[1]); } if (argc == 3) { text = argv[2]; } // GetIndVoice gets the voice define by the (positive) index rc = GetIndVoice(voice, // SInt16 index, &vs); // VoiceSpec *voice // NewSpeechChannel basically makes the voice usable rc = NewSpeechChannel(&vs, // VoiceSpec *voice, &channel); // Can be NULL CFStringRef string = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8); rc = SpeakCFString(channel, string, NULL); if (rc) { fprintf(stderr, "unable to speak!\n"); exit(1); } while (SpeechBusy()) sleep(1); exit(0); }
void say(const char* words) { while (SpeechBusy()) { QGC::SLEEP::msleep(100); } NewSpeechChannel(NULL, &sc); SetSpeechInfo(sc, soVolume, &volume); SetSpeechInfo(sc, soSpeechDoneCallBack, reinterpret_cast<void *>(speechDone)); CFStringRef cfstr = CFStringCreateWithCString(NULL, words, kCFStringEncodingUTF8); SpeakCFString(sc, cfstr, NULL); }
void TextToSpeechPrivate::ProcessSpeech() { QByteArray ba; qmLock.lock(); ba = qlMessages.takeFirst(); qmLock.unlock(); NewSpeechChannel(NULL, &scChannel); SetSpeechInfo(scChannel, soVolume, &fVolume); SetSpeechInfo(scChannel, soRefCon, this); SetSpeechInfo(scChannel, soSpeechDoneCallBack, reinterpret_cast<void *>(speech_done_cb)); SpeakText(scChannel, ba.constData(), ba.size()); }
/* * The initSynthesizer method creates the speech channel to be used by the * synthesizer with the specified voice. If no voice is specified, then the * the synthesizer is initializeed with the default system voice. */ void ofxSpeechSynthesizer::initSynthesizer(std::string voice) { OSErr errorStatus; VoiceSpec theVoiceSpec; if(voice == "") { //-- Create a speech channel with a null voice spec, this returns the default system voice currentVoice = "Default"; errorStatus = NewSpeechChannel(NULL, &speechChannel); } else { //-- Create a speech channel with the voice spec that has the specified voice currentVoice = voice; short voiceIndex = voices[voice]; errorStatus = GetIndVoice(voiceIndex, &theVoiceSpec); if(!errorStatus) errorStatus = NewSpeechChannel(&theVoiceSpec, &speechChannel); } }
int prInitSpeech(struct VMGlobals *g, int numArgsPushed){ OSErr theErr = noErr; //PyrSlot *a = g->sp-1; PyrSlot *b = g->sp; int chan; slotIntVal(b, &chan); if (chan < 0 || chan >= kMaxSpeechChannels) return errIndexOutOfRange; for (int i=0; i<chan; ++i) { if(fCurSpeechChannel[i]) DisposeSpeechChannel(fCurSpeechChannel[i]); NewSpeechChannel( NULL, fCurSpeechChannel+i ); theErr = SetSpeechInfo (fCurSpeechChannel[i], soSpeechDoneCallBack, (const void*)OurSpeechDoneCallBackProc); theErr = SetSpeechInfo (fCurSpeechChannel[i], soWordCallBack, (const void*)OurWordCallBackProc); theErr = SetSpeechInfo (fCurSpeechChannel[i], soRefCon, (void*) i); } return errNone; }
/* * Allocate speech channel and setup callbacks */ static SpeechChannel createNewSpeechChannel(VoiceSpec *voiceSpec) { SpeechChannel channel = NULL; OSErr theErr = noErr; theErr = NewSpeechChannel(voiceSpec, &channel); if (theErr != noErr) { errorMsg("NewSpeechChannel failed", theErr); } else { theErr = SetSpeechInfo(channel, soErrorCallBack, OurErrorCallBackProc); if (theErr != noErr) { errorMsg("SetSpeechInfo(soErrorCallBack) failed", theErr); } theErr = SetSpeechInfo(channel, soSpeechDoneCallBack, OurSpeechDoneCallBackProc); if (theErr != noErr) { errorMsg("SetSpeechInfo(soSpeechDoneCallBack) failed", theErr); } } return channel; }