16 #pragma message( "WARNING: You have not compiled speech into this build (use FS2_SPEECH)" )
19 #else // to end-of-file ...
31 ISpVoice *Voice_device;
32 #elif defined(SCP_UNIX)
39 #pragma error( "ERROR: Unknown platform, speech (FS2_SPEECH) is not supported" )
46 bool Speech_init =
false;
56 (
void **)&Voice_device);
58 Speech_init = SUCCEEDED(hr);
61 speech_dev = open(
"/dev/speech", O_WRONLY | O_DIRECT);
64 if (speech_dev == -1) {
66 mprintf((
"Couldn't open '/dev/speech', turning text-to-speech off...\n"));
78 if(Speech_init ==
false)
return;
81 Voice_device->Release();
90 if(Speech_init ==
false)
return true;
91 if(text == NULL)
return false;
94 int len = strlen(text);
95 wchar_t Conversion_buffer[MAX_SPEECH_CHAR_LEN];
97 if(len > (MAX_SPEECH_CHAR_LEN - 1)) {
98 len = MAX_SPEECH_CHAR_LEN - 1;
102 for(
int i = 0;
i <
len;
i++) {
108 Conversion_buffer[
count] = (
unsigned short) text[
i];
112 Conversion_buffer[
count] =
'\0';
115 return SUCCEEDED(Voice_device->Speak(Conversion_buffer, SPF_ASYNC, NULL));
117 int len = strlen(text);
118 char Conversion_buffer[MAX_SPEECH_CHAR_LEN];
120 if(len > (MAX_SPEECH_CHAR_LEN - 1)) {
121 len = MAX_SPEECH_CHAR_LEN - 1;
125 for(
int i = 0;
i <
len;
i++) {
131 Conversion_buffer[
count] = text[
i];
135 Conversion_buffer[
count] =
'\0';
137 if ( write(speech_dev, Conversion_buffer, count) == -1 )
150 if(Speech_init ==
false)
return true;
152 return SUCCEEDED(Voice_device->Pause());
162 if(Speech_init ==
false)
return true;
164 return SUCCEEDED(Voice_device->Resume());
174 if(Speech_init ==
false)
return true;
176 return SUCCEEDED(Voice_device->Speak( NULL, SPF_PURGEBEFORESPEAK, NULL ));
187 return SUCCEEDED(Voice_device->SetVolume(volume));
199 CComPtr<ISpObjectToken> cpVoiceToken;
200 CComPtr<IEnumSpObjectTokens> cpEnum;
201 ULONG num_voices = 0;
204 hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
206 if(FAILED(hr))
return false;
208 hr = cpEnum->GetCount(&num_voices);
210 if(FAILED(hr))
return false;
214 while (num_voices -- )
216 cpVoiceToken.Release();
218 hr = cpEnum->Next( 1, &cpVoiceToken, NULL );
225 return SUCCEEDED(Voice_device->SetVoice(cpVoiceToken));
243 SPVOICESTATUS pStatus;
245 hr = Voice_device->GetStatus(&pStatus, NULL);
246 if (FAILED(hr))
return false;
248 return (pStatus.dwRunningState != SPRS_DONE);
#define speech_play(text)
#define speech_set_volume(volume)
#define speech_is_speaking()
#define speech_set_voice(voice)