void Speak(const void *text, long size) { SpeechChannel chan; NewSpeechChannel (NULL, &chan); SetSpeechInfo(chan, soSpeechDoneCallBack, (void*)&SpeakingDone); SpeakText (chan, text, size); }
int prSpeakText(struct VMGlobals *g, int numArgsPushed){ OSErr theErr = noErr; PyrSlot *obj = g->sp-2; PyrSlot *a = g->sp-1; PyrSlot *str = g->sp; int chan; slotIntVal(a, &chan); chan = sc_clip(chan, 0, kMaxSpeechChannels); if(speechStrings[chan] != NULL) { post("voice %i already speaking\n", chan); return errNone; } else { // speechStrings[chan] = (char*)pyr_pool_compile->Alloc((a->uo->size + 1)* sizeof(char)); speechStrings[chan] = (char*) malloc((str->uo->size + 1)* sizeof(char)); MEMFAIL(speechStrings[chan]); slotStrVal(str, speechStrings[chan], str->uo->size+1); //if(!fCurSpeechChannel) theErr = NewSpeechChannel( NULL, &fCurSpeechChannel ); theErr = SpeakText( fCurSpeechChannel[chan], speechStrings[chan], strlen(speechStrings[chan])); //should be freed only after the text was spoken! // todo move this bit to the callback! // pyr_pool_compile->Free(theTextToSpeak); } return errNone; }
void tts_send(char *txt, KQMLPerformative *perf) { int theErr = noErr; /* Notify that we started speaking */ DEBUG0("notifying started speaking"); sendStartedSpeaking(); DEBUG0("done"); /* wait until speech-in got the message note: it's impractical to do this sync-ing via messages, so we'll just wait a reasonable amount of time, say 20ms */ usleep(20000); /* Send the text */ DEBUG1("saying \"%s\"", txt); theErr = SpeakText(channel, txt, strlen(txt) ); if (theErr != noErr) { errorMsg("SpeakText failed", theErr); } /* Wait for speech to finish */ DEBUG0("waiting"); if (sem_wait(sem) < 0) { SYSERR0("sem_wait failed"); } /* Notify that we stopped speaking */ DEBUG0("notifying stopped speaking"); sendStoppedSpeaking(); DEBUG0("done"); /* Send reply */ DEBUG0("replying"); sendDoneReply(perf); DEBUG0("done"); }
void CAgentCtl::ProcessInstruction(const CInstruction& instruction) { USES_CONVERSION; if (lstrcmpi(instruction.szCommand, _T("Speak")) == 0) SpeakText(CComBSTR(instruction.szText)); else if (lstrcmpi(instruction.szCommand, _T("Play")) == 0) m_pCharacter->Play((BSTR)CComBSTR(instruction.szText), &m_nRequestID); else if (lstrcmpi(instruction.szCommand, _T("Hide")) == 0) m_pCharacter->Hide(FALSE, &m_nRequestID); else if (lstrcmpi(instruction.szCommand, _T("Show")) == 0) m_pCharacter->Show(FALSE, &m_nRequestID); else if (lstrcmpi(instruction.szCommand, _T("MoveTo")) == 0) { short x, y; #ifdef _UNICODE wscanf_s(instruction.szText, _T("%d, %d"), &x, &y); #else sscanf_s(instruction.szText, _T("%d, %d"), &x, &y); #endif m_pCharacter->MoveTo(x, y, (100-m_nSpeed)*10+100, &m_nRequestID); } else if (lstrcmpi(instruction.szCommand, _T("GestureAt")) == 0) { short x, y; #ifdef _UNICODE wscanf_s(instruction.szText, _T("%d, %d"), &x, &y); #else sscanf_s(instruction.szText, _T("%d, %d"), &x, &y); #endif m_pCharacter->GestureAt(x, y, &m_nRequestID); } }
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()); }
STDMETHODIMP CAgentCtl::SpeakFile(BSTR FileName) { USES_CONVERSION; HANDLE hFile = CreateFile(OLE2T(FileName), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (hFile == INVALID_HANDLE_VALUE) return Error("Couldn't open file"); char szBuffer[100000]; DWORD dwBytesRead; m_pCharacter->Show(FALSE, &m_nRequestID); ReadFile(hFile, szBuffer, 99999, &dwBytesRead, NULL); CloseHandle(hFile); *(szBuffer+dwBytesRead) = 0; // Add the NULL byte SpeakText((BSTR)CComBSTR(szBuffer)); return S_OK; }
int SayText(char *text) { OSErr err; pid_t child_pid; //if (debug_level & 2) //fprintf(stderr,"SayText: %s\n",text); // Check whether the last text was the same and it hasn't been // enough time between them (30 seconds). if ( (strcmp(last_speech_text,text) == 0) // Strings match && (last_speech_time + 30 > sec_now()) ) { //fprintf(stderr,"Same text, skipping speech: %d seconds, %s\n", // (int)(sec_now() - last_speech_time), // text); return(1); } //fprintf(stderr,"Speaking: %s\n",text); xastir_snprintf(last_speech_text, sizeof(last_speech_text), "%s", text); last_speech_time = sec_now(); // Check for the variable going out-of-bounds if (macspeech_processes < 0) { macspeech_processes = 0; } // Allow only so many processes to be queued up ready to send // text to the speech subsystem. // if (macspeech_processes > 10) { // Too many processes queued up! return(1); // Don't send this string, return to calling program } // Create a separate process to handle the speech so that our // main process can continue processing packets and displaying // maps. // child_pid = fork(); if (child_pid == -1) { // The fork failed return(1); } if (child_pid == 0) { // Child process macspeech_processes++; // Go back to default signal handler instead of calling // restart() on SIGHUP (void) signal(SIGHUP,SIG_DFL); // Wait for the speech system to be freed up. Note that if // we have multiple processes queued up we don't know in // which order they'll get access to the speech subsystem. // while (SpeechBusy() == true) { usleep(1000000); } // The speech system is free, so send it our text. Right // now we ignore any errors. // err = SpeakText(channel, text, strlen(text)); macspeech_processes--; // Exit this child process. We don't need it anymore. exit(0); } else { // Parent process // Drop through to the return } return(0); // Return to the calling program }
void ofxSpeechSynthesizer::speakPhrase(std::string phraseToSpeak) { OSErr errorStatus; errorStatus = SpeakText(speechChannel, phraseToSpeak.c_str(), phraseToSpeak.length()); }