Esempio n. 1
0
  long set_voice(
        const char* aName,
        const char* aLang=NULL,
        unsigned char aGender=0,
        unsigned char aAge=0,
        unsigned char aVariant = 0
    ) {
    long result = 0;
    if (aLang || aGender || aAge || aVariant) {
      espeak_VOICE props = { 0 };
      props.name = aName;
      props.languages = aLang;
      props.gender = aGender;
      props.age = aAge;
      props.variant = aVariant;
      result = espeak_SetVoiceByProperties(&props);
    } else {
      result = espeak_SetVoiceByName(aName);
    }

    // This way we don't need to allocate the name/lang strings to the heap.
    // Instead, we store the actual global voice.
    current_voice = espeak_GetCurrentVoice();

    return result;
  }
Esempio n. 2
0
        eSpeak::eSpeak(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

            // Initialize espeak, and set it to play out the speakers, and not exit if it can't find it's directory
            espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 500, nullptr, 1 << 15);
            espeak_SetVoiceByName("default");
            espeak_SetParameter(espeakVOLUME, 100, 0);
            espeak_SetParameter(espeakCAPITALS, 6, 0);

            on<Trigger<messages::output::Say>, Options<Sync<eSpeak>>>([](const messages::output::Say& message) {
                // Wait to finish the current message (if any)
                // By waiting here this reaction can finish and return to the pool
                // if it does not have to wait for another say message
                espeak_Synchronize();

                // Say the new message
                espeak_Synth(message.c_str(),       // Text
                             message.size() + 1,    // Size (including null at end)
                             0,                     // Start position
                             POS_CHARACTER,         // Position Type (irrelevant since we start at the beginning)
                             0,                     // End position (0 means no end position)
                             espeakCHARS_AUTO,      // Flags (auto encoding)
                             nullptr,               // User identifier for callback
                             nullptr                // Callback
                        );
            });

            on<Trigger<Shutdown>>([](const Shutdown&) {
                // Stop espeak
                espeak_Terminate();
            });
        }
Esempio n. 3
0
static void reinitialize_espeak(struct synth_t *s)
{
	int rate;

	/* Re-initialize espeak */
	rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0);
	if (rate < 0) {
		fprintf(stderr, "Unable to initialize espeak.\n");
		return;
	}

	/* We need a callback in acsint mode, but not in speakup mode. */
	if (espeakup_mode == ESPEAKUP_MODE_ACSINT)
		espeak_SetSynthCallback(acsint_callback);

	/* Set parameters again */
	espeak_SetVoiceByName(s->voice);
	espeak_SetParameter(espeakRANGE, s->frequency * frequencyMultiplier, 0);
	espeak_SetParameter(espeakPITCH, s->pitch * pitchMultiplier, 0);
	espeak_SetParameter(espeakRATE, s->rate * rateMultiplier + rateOffset, 0);
	espeak_SetParameter(espeakVOLUME, (s->volume + 1) * volumeMultiplier, 0);
	espeak_SetParameter(espeakCAPITALS, 0, 0);
	paused_espeak = 0;
	return;
}
Esempio n. 4
0
static espeak_ERROR set_voice(struct synth_t *s, char *voice)
{
	espeak_ERROR rc;

	rc = espeak_SetVoiceByName(voice);
	if (rc == EE_OK)
		strcpy(s->voice, voice);
	return rc;
}
bool PlatformSpeechSynthesisProviderEfl::engineInit()
{
    if (!m_isEngineStarted) {
        if (!(m_isEngineStarted = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, 0, 0) != EE_INTERNAL_ERROR))
            return false;
        espeak_SetVoiceByName("default");
    }
    return true;
}
Esempio n. 6
0
static void
espeak_set_synthesis_voice(char *synthesis_voice)
{
	if (synthesis_voice != NULL) {
		espeak_ERROR ret = espeak_SetVoiceByName(synthesis_voice);
		if (ret != EE_OK) {
			DBG("Espeak: Failed to set synthesis voice to %s.", synthesis_voice);
		}
	}
}
Esempio n. 7
0
static int spk_construct(volatile SpeechSynthesizer *spk, char **parameters)
{
	char *data_path, *voicename, *punctlist;
	int result;

	spk->setVolume = spk_setVolume;
	spk->setRate = spk_setRate;
	spk->setPitch = spk_setPitch;
	spk->setPunctuation = spk_setPunctuation;
	spk->drain = spk_drain;

	logMessage(LOG_INFO, "eSpeak-NG version %s", espeak_Info(NULL));

	data_path = parameters[PARM_PATH];
	if (data_path && !*data_path)
		data_path = NULL;
	result = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, data_path, 0);
	if (result < 0) {
		logMessage(LOG_ERR, "eSpeak-NG: initialization failed");
		return 0;
	}

	voicename = parameters[PARM_VOICE];
	if(!voicename || !*voicename)
		voicename = "en";
	result = espeak_SetVoiceByName(voicename);
	if (result != EE_OK) {
		espeak_VOICE voice_select;
		memset(&voice_select, 0, sizeof(voice_select));
		voice_select.languages = voicename;
		result = espeak_SetVoiceByProperties(&voice_select);
	}
	if (result != EE_OK) {
		logMessage(LOG_ERR, "eSpeak-NG: unable to load voice '%s'", voicename);
		return 0;
	}

	punctlist = parameters[PARM_PUNCTLIST];
	if (punctlist && *punctlist) {
		wchar_t w_punctlist[strlen(punctlist) + 1];
		int i = 0;
		while ((w_punctlist[i] = punctlist[i]) != 0) i++;
		espeak_SetPunctuationList(w_punctlist);
	}

	if (parameters[PARM_MAXRATE]) {
		int val = atoi(parameters[PARM_MAXRATE]);
		if (val > espeakRATE_MINIMUM) maxrate = val;
	}

	espeak_SetSynthCallback(SynthCallback);

	return 1;
}
Esempio n. 8
0
//-----------------------------------------------------------------------------
// InitSpeak - This function initializes the speech using the current file name
//  or parameters...
//-----------------------------------------------------------------------------
void RobotSpeak::InitSpeak()
{
    espeak_ERROR err = EE_NOT_FOUND; // something other than OK...

    // See if this is the first time through if so register our release function.
    if (_bIDSDRSpeak == 0xff) 
        _bIDSDRSpeak = SDRRegisterReleaseFunction(&_EndSpeak);
        
    // Tell our quick and dirty Sound registry stuff, that we want to be the current one...    
    SDRSetCurrent(_bIDSDRSpeak);
    
    esoutput = AUDIO_OUTPUT_PLAYBACK;
    espeak_Initialize(esoutput, Buflength, path, Options );

    // First see if someone registered a voice file name
    if (_pszVoiceFileName) 
    {
        err = espeak_SetVoiceByName(_pszVoiceFileName);
        if (err != EE_OK) 
            printf("Speak SetVoiceByProp failed %d\n", err);
    }    

    else if (_pszVoiceLanguage)
    {
        espeak_VOICE voice;
        voice.name = NULL;
        voice.languages = _pszVoiceLanguage;
        voice.identifier= NULL;
        voice.age = 0;
        voice.gender = _bVoiceGender;
        voice.variant = 0;
        err = espeak_SetVoiceByProperties(&voice);
        if (err != EE_OK) 
            printf("Speak SetVoiceByProp failed %d\n", err);
    }

    if (err != EE_OK)
        espeak_SetVoiceByName(g_szDefaultVoice);

    _fSpeakInit = true;
}
Esempio n. 9
0
/* Given a language code and SD voice code, sets the espeak voice. */
static void espeak_set_language_and_voice(char *lang, SPDVoiceType voice_code)
{
	log_msg(OTTS_LOG_DEBUG, "Espeak: set_language_and_voice %s %d", lang,
		voice_code);
	espeak_ERROR ret;

	unsigned char overlay = 0;
	switch (voice_code) {
	case SPD_NO_VOICE:
		overlay = 0;
		break;
	case SPD_MALE1:
		overlay = 0;
		break;
	case SPD_MALE2:
		overlay = 1;
		break;
	case SPD_MALE3:
		overlay = 2;
		break;
	case SPD_FEMALE1:
		overlay = 11;
		break;
	case SPD_FEMALE2:
		overlay = 12;
		break;
	case SPD_FEMALE3:
		overlay = 13;
		break;
	case SPD_CHILD_MALE:
		overlay = 4;
		break;
	case SPD_CHILD_FEMALE:
		overlay = 14;
		break;
	}

	char *name = g_strdup_printf("%s+%d", lang, overlay);
	log_msg(OTTS_LOG_INFO, "Espeak: set_language_and_voice name=%s", name);
	ret = espeak_SetVoiceByName(name);

	if (ret != EE_OK) {
		log_msg(OTTS_LOG_WARN, "Espeak: Error selecting language %s",
			name);
	} else {
		log_msg(OTTS_LOG_DEBUG,
			"Espeak: Successfully set voice to \"%s\"", name);
	}
	g_free(name);
}
Esempio n. 10
0
int main(int argc, char* argv[] ) 
{
    output = AUDIO_OUTPUT_PLAYBACK;
    int I, Run = 1, L;    
    espeak_Initialize(output, Buflength, path, Options ); 
    espeak_SetVoiceByName(Voice);
    Size = strlen(text)+1;    
    printf("Saying  '%s'",text);
    espeak_Synth( text, Size, position, position_type, end_position, flags,
    unique_identifier, user_data );
    espeak_Synchronize( );
    printf("\n:Done\n"); 
    return 0;
}
Esempio n. 11
0
  void synth_(const char* aText, void* aCallback) {
    t_espeak_callback* cb = reinterpret_cast<t_espeak_callback*>(aCallback);
    espeak_SetSynthCallback(cb);
    espeak_SetParameter(espeakPITCH, pitch, 0);
    espeak_SetParameter(espeakRATE, rate, 0);

    if (current_voice)
      espeak_SetVoiceByProperties(current_voice);
    else
      espeak_SetVoiceByName("default");

    espeak_Synth(aText, 0, 0, POS_CHARACTER, 0, 0, NULL, NULL);

    // Reset callback so other instances will work too.
    espeak_SetSynthCallback(NULL);
  }
Esempio n. 12
0
static espeak_ERROR set_voice(struct synth_t *s, char *voice)
{
	espeak_ERROR rc;
	espeak_VOICE voice_select;

	rc = espeak_SetVoiceByName(voice);
	if (rc != EE_OK)
	{
		memset(&voice_select, 0, sizeof(voice_select));
		voice_select.languages = voice;
		rc = espeak_SetVoiceByProperties(&voice_select);
	}
	if (rc == EE_OK)
		strcpy(s->voice, voice);
	return rc;
}
Esempio n. 13
0
uint8_t speech_poll() {
  speech_list_t *p_list;
	if( speaking == 2 ) {
    SDL_PauseAudio( 1 );
    speaking = 0;
	}
	if( speaking == 0 ) {
    SDL_mutexP( speech_mx );
		if( speech_first ) {
  		// Queue pop
      p_list = speech_first;
      speech_first = p_list->next;
      SDL_mutexV( speech_mx );
#ifdef USE_SAM
  		// Set parameters
  		sam_params( SAM_SCALE, SAM_SING, SAM_SPEED, SAM_PITCH, SAM_MOUTH, SAM_THROAT );
      buf_pos = 0;
  		buf_size = sizeof( buf );
  		if( sam_speak( buf, &buf_size, p_list->data ) == 0 ) buf_play();
#else

      printf( "Speech [info]: eSpeak voice return: %i\n", espeak_SetVoiceByName( p_list->voice ) );
      espeak_SetParameter(espeakRATE,130,0);
	    espeak_SetParameter(espeakRANGE,0,0);
//		espeak_SetParameter(espeakVOLUME,volume,0);
//		espeak_SetParameter(espeakPITCH,pitch,0);
//		espeak_SetParameter(espeakCAPITALS,option_capitals,0);
//		espeak_SetParameter(espeakPUNCTUATION,option_punctuation,0);
//		espeak_SetParameter(espeakWORDGAP,wordgap,0);
//		espeak_SetParameter(espeakLINELENGTH,option_linelength,0);
//		espeak_SetPunctuationList(option_punctlist);

      p_buf = buf;
      viseme_count = 0;
      espeak_Synth( p_list->data, strlen( p_list->data ) + 1, 0, POS_CHARACTER, 0, 0, NULL, NULL );
      buf_play();
#endif
  		free( p_list );
		} else {
      SDL_mutexV( speech_mx );
		}
	}
	return( speaking );
}
void PlatformSpeechSynthesisProviderEfl::speak(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance)
{
    if (!engineInit() || !utterance) {
        fireSpeechEvent(SpeechError);
        return;
    }

    m_utterance = utterance;
    String voice = voiceName(m_utterance);
    espeak_SetVoiceByName(voice.utf8().data());
    espeak_SetParameter(espeakRATE, convertRateToEspeakValue(m_utterance->rate()), 0);
    espeak_SetParameter(espeakVOLUME, convertVolumeToEspeakValue(m_utterance->volume()), 0);
    espeak_SetParameter(espeakPITCH, convertPitchToEspeakValue(m_utterance->pitch()), 0);

    String textToRead = m_utterance->text();
    espeak_ERROR err = espeak_Synth(textToRead.utf8().data(), textToRead.length(), 0, POS_CHARACTER, 0, espeakCHARS_AUTO, 0, nullptr);
    if (err == EE_INTERNAL_ERROR) {
        fireSpeechEvent(SpeechError);
        m_utterance = nullptr;
        return;
    }

    fireSpeechEvent(SpeechStart);
}
Esempio n. 15
0
void
carmen_voice_initialize(char *language)
{
	espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 500, NULL, 0);
	espeak_SetVoiceByName(language);
}
Esempio n. 16
0
static void espeak_voice(t_espeak*x, t_symbol*s){
  espeak_ERROR err= espeak_SetVoiceByName(s->s_name);
}
Esempio n. 17
0
/*Used to set person in TTS. in the case of espeak we will set 
 * language by this. return False if language is not available  */
int T4K_Tts_set_voice(char voice_name[]){
	if (espeak_SetVoiceByName(voice_name) == EE_OK)
		return 1;
	else
		return 0;
}
Esempio n. 18
0
int main (int argc, char **argv)
//==============================
{
	static struct option long_options[] =
		{
		/* These options set a flag. */
//		{"verbose", no_argument,       &verbose_flag, 1},
//		{"brief",   no_argument,       &verbose_flag, 0},

		/* These options don't set a flag.
			We distinguish them by their indices. */
		{"help",    no_argument,       0, 'h'},
		{"stdin",   no_argument,       0, 0x100},
		{"compile-debug", optional_argument, 0, 0x101},
		{"compile", optional_argument, 0, 0x102},
		{"punct",   optional_argument, 0, 0x103},
		{"voices",  optional_argument, 0, 0x104},
		{"stdout",  no_argument,       0, 0x105},
		{"split",   optional_argument, 0, 0x106},
		{0, 0, 0, 0}
		};

	static const char* err_load = "Failed to read ";


	FILE *f_text=NULL;
	char *p_text=NULL;

	int option_index = 0;
	int c;
	int ix;
	int flag_stdin = 0;
	int flag_compile = 0;
	int filesize = 0;
	int synth_flags = espeakCHARS_AUTO | espeakPHONEMES | espeakENDPAUSE;

	int volume = -1;
	int speed = -1;
	int pitch = -1;
	int wordgap = -1;
	int option_capitals = -1;
	int option_punctuation = -1;
	int option_phonemes = -1;
	int option_linelength = 0;
	int option_waveout = 0;

	char filename[120];
	char voicename[40];
	char voice_mbrola[20];
	char dictname[40];
#define N_PUNCTLIST  100
	wchar_t option_punctlist[N_PUNCTLIST];

	voicename[0] = 0;
	voice_mbrola[0] = 0;
	dictname[0] = 0;
	wavefile[0] = 0;
	filename[0] = 0;
	option_punctlist[0] = 0;

	while(true)
	{
		c = getopt_long (argc, argv, "a:bf:g:hk:l:mp:qs:v:w:xXz",
					long_options, &option_index);

		/* Detect the end of the options. */
		if (c == -1)
			break;

		switch (c)
		{
		case 'b':
			synth_flags |= espeakCHARS_8BIT;
			break;

		case 'h':
			printf("\n");
			printf("eSpeak text-to-speech: %s\n%s",espeak_Info(NULL),help_text);
			exit(0);
			break;

		case 'k':
			option_capitals = atoi(optarg);
			break;

		case 'x':
			option_phonemes = 1;
			break;

		case 'X':
			option_phonemes = 2;
			break;

		case 'm':
			synth_flags |= espeakSSML;
			break;

		case 'p':
			pitch = atoi(optarg);
			break;

		case 'q':
			quiet = 1;
			break;

		case 'f':
			strncpy0(filename,optarg,sizeof(filename));
			break;

		case 'l':
			option_linelength = atoi(optarg);
			break;

		case 'a':
			volume = atoi(optarg);
			break;

		case 's':
			speed = atoi(optarg);
			break;

		case 'g':
			wordgap = atoi(optarg);
			break;

		case 'v':
			strncpy0(voicename,optarg,sizeof(voicename));
			break;

		case 'w':
			option_waveout = 1;
			strncpy0(wavefile,optarg,sizeof(filename));
			break;

		case 'z':  // remove pause from the end of a sentence
			synth_flags &= ~espeakENDPAUSE;
			break;

		case 0x100:		// --stdin
			flag_stdin = 1;
			break;

		case 0x105:		// --stdout
			option_waveout = 1;
			strcpy(wavefile,"stdout");
			break;

		case 0x101:    // --compile-debug
		case 0x102:		// --compile
			strncpy0(voicename,optarg,sizeof(voicename));
			flag_compile = c;
			quiet = 1;
			break;

		case 0x103:		// --punct
			option_punctuation = 1;
			if(optarg != NULL)
			{
				ix = 0;
				while((ix < N_PUNCTLIST) && ((option_punctlist[ix] = optarg[ix]) != 0)) ix++;
				option_punctlist[N_PUNCTLIST-1] = 0;
				option_punctuation = 2;
			}
			break;

		case 0x104:   // --voices
			espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL,0);
			DisplayVoices(stdout,optarg);
			exit(0);

		case 0x106:   // -- split
			if(optarg == NULL)
				samples_split = 30;  // default 30 minutes
			else
				samples_split = atoi(optarg);
			break;

		default:
			exit(0);
		}
	}


	if(option_waveout || quiet)
	{
		// writing to a file (or no output), we can use synchronous mode
		samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,NULL,0);
		samples_split = (samplerate * samples_split) * 60;

		espeak_SetSynthCallback(SynthCallback);
		if(samples_split)
		{
			char *extn;
			extn = strrchr(wavefile,'.');
			if((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4))
			{
				strcpy(filetype,extn);
				*extn = 0;
			}
		}
		else
		if(option_waveout)
		{
			if(OpenWavFile(wavefile,samplerate) != 0)
				exit(4);
		}
	}
	else
	{
		// play the sound output
		samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,NULL,0);
	}
	

	if(voicename[0] == 0)
		strcpy(voicename,"default");

	if(espeak_SetVoiceByName(voicename) != EE_OK)
	{
		fprintf(stderr,"%svoice '%s'\n",err_load,voicename);
		exit(2);
	}

	if(flag_compile)
	{
		// This must be done after the voice is set
		espeak_CompileDictionary("", stderr, flag_compile & 0x1);
		exit(0);
	}

	// set any non-default values of parameters. This must be done after espeak_Initialize()
	if(speed > 0)
		espeak_SetParameter(espeakRATE,speed,0);
	if(volume >= 0)
		espeak_SetParameter(espeakVOLUME,volume,0);
	if(pitch >= 0)
		espeak_SetParameter(espeakPITCH,pitch,0);
	if(option_capitals >= 0)
		espeak_SetParameter(espeakCAPITALS,option_capitals,0);
	if(option_punctuation >= 0)
		espeak_SetParameter(espeakPUNCTUATION,option_punctuation,0);
	if(wordgap >= 0)
		espeak_SetParameter(espeakWORDGAP,wordgap,0);
	if(option_linelength > 0)
		espeak_SetParameter(espeakLINELENGTH,option_linelength,0);
	if(option_punctuation == 2)
		espeak_SetPunctuationList(option_punctlist);
	if(option_phonemes >= 0)
		espeak_SetPhonemeTrace(option_phonemes,stderr);

	if(filename[0]==0)
	{
		if((optind < argc) && (flag_stdin == 0))
		{
			// there's a non-option parameter, and no -f or --stdin
			// use it as text
			p_text = argv[optind];
		}
		else
		{
			f_text = stdin;
			if(flag_stdin == 0)
			{
				flag_stdin = 2;
			}
		}
	}
	else
	{
		filesize = GetFileLength(filename);
		f_text = fopen(filename,"r");
	}

	if((f_text == NULL) && (p_text == NULL))
	{
		fprintf(stderr,"%sfile '%s'\n",err_load,filename);
		exit(1);
	}


	if(p_text != NULL)
	{
		int size;
		size = strlen(p_text);
		espeak_Synth(p_text,size+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
	}
	else
	if(flag_stdin)
	{
		int max = 1000;
		p_text = (char *)malloc(max);

		if(flag_stdin == 2)
		{
			// line by line input on stdin
			while(fgets(p_text,max,stdin) != NULL)
			{
				p_text[max-1] = 0;
				espeak_Synth(p_text,max,0,POS_CHARACTER,0,synth_flags,NULL,NULL);

			}
		}
		else
		{
			// bulk input on stdin
			ix = 0;
			while(!feof(stdin))
			{
				p_text[ix++] = fgetc(stdin);
				if(ix >= (max-1))
				{
					max += 1000;
					p_text = (char *)realloc(p_text,max);
				}
			}
			if(ix > 0)
			{
				p_text[ix-1] = 0;
				espeak_Synth(p_text,ix+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
			}
		}
	}
	else
	if(f_text != NULL)
	{
		if((p_text = (char *)malloc(filesize+1)) == NULL)
		{
			fprintf(stderr,"Failed to allocate memory %d bytes",filesize);
			exit(3);
		}

		fread(p_text,1,filesize,f_text);
		p_text[filesize]=0;
		espeak_Synth(p_text,filesize+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
		fclose(f_text);
	}

	espeak_Synchronize();
	return(0);
}