Ejemplo n.º 1
0
Archivo: say.c Proyecto: karmatr0n/say
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 QGCAudioWorker::say(QString inText, int severity)
{
	static bool threadInit = false;
	if (!threadInit) {
		threadInit = true;
		init();
	}

    if (!muted)
    {
        QString text = _fixTextMessageForAudio(inText);
        // Prepend high priority text with alert beep
        if (severity < GAudioOutput::AUDIO_SEVERITY_CRITICAL) {
            beep();
        }

#ifdef QGC_NOTIFY_TUNES_ENABLED
        // Wait for the last sound to finish
        while (!sound->isFinished()) {
            QGC::SLEEP::msleep(100);
        }
#endif

#if defined _MSC_VER && defined QGC_SPEECH_ENABLED
        HRESULT hr = pVoice->Speak(text.toStdWString().c_str(), SPF_DEFAULT, NULL);
		if (FAILED(hr)) {
			qDebug() << "Speak failed, HR:" << QString("%1").arg(hr, 0, 16);
		}
#elif defined Q_OS_LINUX && defined QGC_SPEECH_ENABLED
        // Set size of string for espeak: +1 for the null-character
        unsigned int espeak_size = strlen(text.toStdString().c_str()) + 1;
        espeak_Synth(text.toStdString().c_str(), espeak_size, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL);

#elif defined Q_OS_MAC && defined QGC_SPEECH_ENABLED
        // Slashes necessary to have the right start to the sentence
        // copying data prevents SpeakString from reading additional chars
        text = "\\" + text;
        std::wstring str = text.toStdWString();
        unsigned char str2[1024] = {};
        memcpy(str2, text.toLatin1().data(), str.length());
        SpeakString(str2);

        // Block the thread while busy
        // because we run in our own thread, this doesn't
        // halt the main application
        while (SpeechBusy()) {
            QGC::SLEEP::msleep(100);
        }

#else
        // Make sure there isn't an unused variable warning when speech output is disabled
        Q_UNUSED(inText);
#endif
    }
}
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
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
}