2019-07-10 10:49:29 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
|
|
|
|
#define BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
|
|
|
|
|
2019-07-11 00:14:28 +02:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2019-07-10 10:49:29 +02:00
|
|
|
#if defined(USE_TTS)
|
|
|
|
|
2019-07-11 00:14:28 +02:00
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/debug.h"
|
2019-07-10 10:49:29 +02:00
|
|
|
namespace Common {
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Text to speech voice class.
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
class TTSVoice {
|
|
|
|
friend class TextToSpeechManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Gender {
|
|
|
|
MALE,
|
|
|
|
FEMALE,
|
2019-07-17 13:33:42 +02:00
|
|
|
UNKNOWN_GENDER
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Age {
|
|
|
|
CHILD,
|
|
|
|
ADULT,
|
|
|
|
UNKNOWN_AGE
|
2019-07-11 00:14:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
TTSVoice()
|
2019-07-17 13:33:42 +02:00
|
|
|
: _gender(UNKNOWN_GENDER)
|
|
|
|
, _age(UNKNOWN_AGE)
|
2019-07-12 22:16:44 +02:00
|
|
|
, _data(nullptr)
|
|
|
|
, _description("") {}
|
2019-07-17 13:33:42 +02:00
|
|
|
TTSVoice(Gender gender, Age age, void *data, String description)
|
2019-07-11 00:14:28 +02:00
|
|
|
: _gender(gender)
|
2019-07-17 13:33:42 +02:00
|
|
|
, _age(age)
|
2019-07-12 22:16:44 +02:00
|
|
|
, _data(data)
|
|
|
|
, _description(description) {}
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the gender of the used voice.
|
|
|
|
*
|
|
|
|
* @note The gender information is really platform specific, it may not be
|
|
|
|
* possible to find it out on some platforms. Sometimes it can be set by
|
|
|
|
* the user in the TTS engine configuration and so the information might be
|
|
|
|
* wrong
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
Gender getGender() { return _gender; };
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the voice gender, should probably be used only by the backends
|
|
|
|
* that are directly communicating with the TTS engine.
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
void setGender(Gender gender) { _gender = gender; };
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the age of the used voice.
|
|
|
|
*
|
|
|
|
* @note The age information is really platform specific, it may not be
|
|
|
|
* possible to find it out on some platforms. Sometimes it can be set by
|
|
|
|
* the user in the TTS engine configuration and so the information might be
|
|
|
|
* wrong
|
|
|
|
*/
|
2019-07-17 13:33:42 +02:00
|
|
|
Age getAge() { return _age; };
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the voice age, should probably be used only by the backends
|
|
|
|
* that are directly communicating with the TTS engine.
|
|
|
|
*/
|
2019-07-17 13:33:42 +02:00
|
|
|
void setAge(Age age) { _age = age; };
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data about the voice, this is engine specific variable,
|
|
|
|
* it has close to no value for anything else then communicating with
|
|
|
|
* directly with the TTS engine, which should probably be done only by
|
|
|
|
* the backends.
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
void setData(void *data) { _data = data; };
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the voice age, should probably be used only by the backends
|
|
|
|
* that are directly communicating with the TTS engine.
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
void *getData() { return _data; };
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the voice description. This description is really tts engine
|
|
|
|
* specific and might be not be availaible with some tts engines.
|
|
|
|
*/
|
2019-07-12 22:16:44 +02:00
|
|
|
String getDescription() { return _description; };
|
2019-07-11 00:14:28 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Gender _gender;
|
2019-07-17 13:33:42 +02:00
|
|
|
Age _age;
|
2019-07-11 00:14:28 +02:00
|
|
|
void *_data;
|
2019-07-12 22:16:44 +02:00
|
|
|
String _description;
|
2019-07-11 00:14:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TTSState {
|
|
|
|
int _rate;
|
|
|
|
int _pitch;
|
|
|
|
int _volume;
|
|
|
|
String _language;
|
2019-07-12 00:46:42 +02:00
|
|
|
int _activeVoice;
|
2019-07-11 00:14:28 +02:00
|
|
|
Array<TTSVoice> _availaibleVoices;
|
|
|
|
TTSState *_next;
|
|
|
|
};
|
|
|
|
|
2019-07-10 10:49:29 +02:00
|
|
|
/**
|
|
|
|
* The TextToSpeechManager allows speech synthesis.
|
|
|
|
*/
|
|
|
|
class TextToSpeechManager {
|
|
|
|
public:
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* The constructor sets the language to the translation manager language if
|
|
|
|
* USE_TRANSLATION is defined, or english when it isn't defined. It sets the rate,
|
|
|
|
* pitch and volume to their middle values.
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
TextToSpeechManager();
|
|
|
|
virtual ~TextToSpeechManager();
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Says the given string
|
|
|
|
*
|
|
|
|
* @param str The string to say
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual bool say(String str) { return false; }
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Stops the speech
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual bool stop() { return false; }
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pauses the speech
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual bool pause() { return false; }
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resumes the speech
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual bool resume() { return false; }
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Returns true, if the TTS engine is speaking
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual bool isSpeaking() { return false; }
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true, if the TTS engine is paused
|
|
|
|
*/
|
2019-07-11 23:38:06 +02:00
|
|
|
virtual bool isPaused() { return false; }
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true, if the TTS engine is ready to speak (isn't speaking and isn't paused)
|
|
|
|
*/
|
2019-07-11 23:38:06 +02:00
|
|
|
virtual bool isReady() { return false; }
|
2019-07-11 00:14:28 +02:00
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Sets a voice to be used by the TTS.
|
|
|
|
*
|
|
|
|
* @param index The index of the voice inside the _ttsState->_availaibleVoices array
|
|
|
|
*/
|
2019-07-12 00:46:42 +02:00
|
|
|
virtual void setVoice(unsigned index) {}
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the voice, that is used right now
|
|
|
|
*/
|
2019-07-12 00:46:42 +02:00
|
|
|
TTSVoice getVoice() { return _ttsState->_availaibleVoices[_ttsState->_activeVoice]; }
|
2019-07-11 00:14:28 +02:00
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Sets the speech rate
|
|
|
|
*
|
|
|
|
* @param rate Integer between -100 (slowest) and 100 (fastest)
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual void setRate(int rate) {}
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current speech rate
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
int getRate() { return _ttsState->_rate; }
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Sets the pitch
|
|
|
|
*
|
|
|
|
* @param pitch Integer between -100 (lowest) and 100 (highest)
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual void setPitch(int pitch) {}
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns current speech pitch
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
int getPitch() { return _ttsState->_pitch; }
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Sets the speech volume
|
|
|
|
*
|
|
|
|
* @param volume Volume as a percentage (0 means muted, 100 means as loud as possible)
|
|
|
|
*/
|
2019-07-12 12:52:18 +02:00
|
|
|
virtual void setVolume(unsigned volume) {}
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current voice volume
|
|
|
|
*/
|
2019-07-12 12:52:18 +02:00
|
|
|
virtual int getVolume() { return _ttsState->_volume; }
|
2019-07-11 00:14:28 +02:00
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Sets the speech language
|
|
|
|
*
|
|
|
|
* @param language The language identifier as defined by ISO (2 characters long string)
|
|
|
|
*
|
|
|
|
* @note After using this method, it is probably a good idea to use setVoice,
|
|
|
|
* because voices are usually language specific and so it is set to some platform
|
|
|
|
* specific default after switching languages.
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual void setLanguage(String language) {}
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current speech language
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
String getLanguage() { return _ttsState->_language; }
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Returns array of availaible voices for the current language
|
|
|
|
*/
|
2019-07-11 00:14:28 +02:00
|
|
|
Array<TTSVoice> getVoicesArray() { return _ttsState->_availaibleVoices; }
|
|
|
|
|
2019-07-18 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* Pushes the current state of the TTS
|
|
|
|
*/
|
2019-07-12 00:46:42 +02:00
|
|
|
void pushState();
|
2019-07-18 00:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pops the TTS state
|
|
|
|
*/
|
2019-07-16 22:09:05 -07:00
|
|
|
virtual bool popState() { return true; }
|
2019-07-12 00:46:42 +02:00
|
|
|
|
2019-07-11 00:14:28 +02:00
|
|
|
protected:
|
|
|
|
TTSState *_ttsState;
|
2019-07-10 10:49:29 +02:00
|
|
|
|
2019-07-11 00:14:28 +02:00
|
|
|
virtual void updateVoices() {};
|
2019-07-10 10:49:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Common
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
|