00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <iostream>
00013
00014 using namespace std;
00015
00016 #include "config.h"
00017 #ifdef FESTIVAL_SUPPORT
00018 #include "festival.h"
00019 #endif
00020 #include "wavfile.h"
00021 #include "tts.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 static bool ttsInitialised=false;
00034
00035 tts::tts()
00036 {
00037 #ifdef FESTIVAL_SUPPORT
00038 if (!ttsInitialised)
00039 festival_initialize(true, 300000);
00040 ttsInitialised = true;
00041 #endif
00042 }
00043
00044
00045 tts::~tts()
00046 {
00047 #ifdef FESTIVAL_SUPPORT
00048 festival_tidy_up();
00049 #endif
00050 }
00051
00052
00053 void tts::setVoice(const char *voice)
00054 {
00055 #ifdef FESTIVAL_SUPPORT
00056 char voiceCmd[100];
00057 if (strlen(voice) < (sizeof(voiceCmd) - 3))
00058 {
00059 sprintf(voiceCmd, "(%s)", voice);
00060 festival_eval_command(voiceCmd);
00061 }
00062 else
00063 cerr << "Voice too long" << voice << endl;
00064 #endif
00065 }
00066
00067
00068 void tts::say(const char *sentence)
00069 {
00070 #ifdef FESTIVAL_SUPPORT
00071 festival_say_text(sentence);
00072 #endif
00073 }
00074
00075
00076 void tts::toWavFile(const char *sentence, wavfile &outWave)
00077 {
00078 #ifdef FESTIVAL_SUPPORT
00079 EST_Wave Wave;
00080 if (!festival_text_to_wave(sentence, Wave))
00081 cout << "Festival TTS failed ro generate speech for: " << sentence << endl;
00082
00083 outWave.load(Wave.values().memory(),
00084 Wave.num_samples(),
00085 16, 1,
00086 Wave.num_channels(),
00087 Wave.sample_rate());
00088 #endif
00089 }
00090
00091
00092