SCI: Text to Speech (TTS) functionality for SCI16 (SCI0 - SCI1.1) games

This is based on the work done for GSoC by @taylorzhancher in PR #3256

Highlights:
- TTS has been hooked globally onto places where text is shown
- TTS is currently performed for textboxes and button texts
- TTS stops when text windows are disposed (which enhances the in-game
  experience)
- No game-specific logic has been added
- This hasn't been extensively tested with all SCI16 games yet
- There will be cases that are not handled properly yet
- The TTS functions have been grouped under a SciTTS class
This commit is contained in:
Filippos Karapetis 2021-12-19 22:05:26 +02:00
parent 4f2f0e3a45
commit a488bb47e8
11 changed files with 145 additions and 11 deletions

View file

@ -43,6 +43,7 @@ namespace Sci {
#define GAMEOPTION_RGB_RENDERING GUIO_GAMEOPTIONS14
#define GAMEOPTION_PALETTE_MODS GUIO_GAMEOPTIONS15
#define GAMEOPTION_SQ1_BEARDED_MUSICIANS GUIO_GAMEOPTIONS16
#define GAMEOPTION_TTS GUIO_GAMEOPTIONS17
enum SciGameId {
GID_ASTROCHICKEN,

View file

@ -185,6 +185,18 @@ const ADExtraGuiOptionsMap optionsList[] = {
}
},
#ifdef USE_TTS
{
GAMEOPTION_TTS,
{
_s("Enable Text to Speech"),
_s("Use TTS to read the descriptions (if TTS is available)"),
"tts_enabled",
false
}
},
#endif
AD_EXTRA_GUI_OPTIONS_TERMINATOR
};

View file

@ -22,15 +22,15 @@
namespace Sci {
#define GUIO_STD16 GUIO5(GUIO_NOSPEECH, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_HIRES GUIO6(GUIO_NOSPEECH, GUIO_NOASPECT, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_UNDITHER GUIO6(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_PALETTEMODS GUIO7(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_PALETTE_MODS)
#define GUIO_STD16 GUIO6(GUIO_NOSPEECH, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_TTS)
#define GUIO_STD16_HIRES GUIO7(GUIO_NOSPEECH, GUIO_NOASPECT, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_TTS)
#define GUIO_STD16_UNDITHER GUIO7(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_TTS)
#define GUIO_STD16_PALETTEMODS GUIO8(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_PALETTE_MODS, GAMEOPTION_TTS)
#define GUIO_STD16_SPEECH GUIO4(GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_SPEECH_GM GUIO5(GUIO_MIDIGM, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_MAC GUIO4(GUIO_NOSPEECH, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_MAC_UNDITHER GUIO5(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define GUIO_STD16_MAC_PALETTEMODS GUIO6(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_PALETTE_MODS)
#define GUIO_STD16_MAC GUIO5(GUIO_NOSPEECH, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_TTS)
#define GUIO_STD16_MAC_UNDITHER GUIO6(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_TTS)
#define GUIO_STD16_MAC_PALETTEMODS GUIO7(GUIO_NOSPEECH, GAMEOPTION_EGA_UNDITHER, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING, GAMEOPTION_PALETTE_MODS, GAMEOPTION_TTS)
#define GUIO_STD16_MAC_SPEECH GUIO3(GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_MIDI_MODE, GAMEOPTION_RGB_RENDERING)
#define FANMADE_L(name, resMapMd5, resMapSize, resMd5, resSize, resVol, lang) \
@ -1406,10 +1406,11 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformDOS, 0, GUIO_STD16 },
#define GUIO_JONES_FLOPPY GUIO4(GUIO_NOSPEECH, \
#define GUIO_JONES_FLOPPY GUIO5(GUIO_NOSPEECH, \
GAMEOPTION_PREFER_DIGITAL_SFX, \
GAMEOPTION_MIDI_MODE, \
GAMEOPTION_RGB_RENDERING)
GAMEOPTION_RGB_RENDERING, \
GAMEOPTION_TTS)
#define GUIO_JONES_CD GUIO4(GAMEOPTION_JONES_CDAUDIO, \
GAMEOPTION_PREFER_DIGITAL_SFX, \
@ -5027,12 +5028,13 @@ static const struct ADGameDescription SciGameDescriptions[] = {
AD_LISTEND},
Common::EN_ANY, Common::kPlatformMacintosh, ADGF_MACRESFORK, GUIO1(GUIO_NONE) },
#define GUIO_SQ1_ENGLISH_PC GUIO6(GUIO_NOSPEECH, \
#define GUIO_SQ1_ENGLISH_PC GUIO7(GUIO_NOSPEECH, \
GAMEOPTION_PREFER_DIGITAL_SFX, \
GAMEOPTION_ORIGINAL_SAVELOAD, \
GAMEOPTION_MIDI_MODE, \
GAMEOPTION_RGB_RENDERING, \
GAMEOPTION_SQ1_BEARDED_MUSICIANS)
GAMEOPTION_SQ1_BEARDED_MUSICIANS, \
GAMEOPTION_TTS)
// Space Quest 1 VGA Remake - English Amiga (from www.back2roots.org)
// SCI interpreter version 1.000.510 (just a guess)

View file

@ -37,6 +37,7 @@
#include "sci/engine/savegame.h"
#include "sci/engine/state.h"
#include "sci/engine/selector.h"
#include "sci/engine/tts.h"
#include "sci/engine/kernel.h"
#include "sci/graphics/animate.h"
#include "sci/graphics/cache.h"
@ -1178,6 +1179,8 @@ reg_t kDisposeWindow(EngineState *s, int argc, reg_t *argv) {
reanimate = true;
g_sci->_gfxPorts->kernelDisposeWindow(windowId, reanimate);
g_sci->_tts->stop();
return s->r_acc;
}

View file

@ -0,0 +1,59 @@
/* 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.
*
*/
#include "sci/sci.h"
#include "sci/engine/tts.h"
#include "common/system.h"
#include "common/text-to-speech.h"
#include "common/config-manager.h"
namespace Sci {
SciTTS::SciTTS() : _lastText("") {
_ttsMan = ConfMan.getBool("tts_enabled") ? g_system->getTextToSpeechManager() : nullptr;
if (_ttsMan != nullptr)
_ttsMan->setLanguage(ConfMan.get("language"));
}
void SciTTS::button(const Common::String &text) {
if (_ttsMan != nullptr)
_ttsMan->say(text, Common::TextToSpeechManager::QUEUE_NO_REPEAT);
}
void SciTTS::text(const Common::String &text) {
if (_ttsMan != nullptr)
_ttsMan->say(text, Common::TextToSpeechManager::INTERRUPT);
}
void SciTTS::display(const Common::String &text) {
if (_ttsMan != nullptr && text != _lastText) {
_ttsMan->say(text, Common::TextToSpeechManager::QUEUE_NO_REPEAT);
_lastText = text;
}
}
void SciTTS::stop() {
if (_ttsMan != nullptr)
_ttsMan->stop();
}
} // End of namespace Sci

42
engines/sci/engine/tts.h Normal file
View file

@ -0,0 +1,42 @@
/* 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.
*
*/
#include "common/text-to-speech.h"
#include "sci/sci.h"
namespace Sci {
class SciTTS {
public:
SciTTS();
void button(const Common::String &text);
void text(const Common::String &text);
void display(const Common::String &text);
void stop();
private:
Common::TextToSpeechManager *_ttsMan;
Common::String _lastText;
};
} // End of namespace Sci

View file

@ -31,6 +31,7 @@
#include "sci/engine/kernel.h"
#include "sci/engine/state.h"
#include "sci/engine/selector.h"
#include "sci/engine/tts.h"
#include "sci/graphics/compare.h"
#include "sci/graphics/ports.h"
#include "sci/graphics/paint16.h"
@ -312,6 +313,8 @@ int GfxControls16::getPicNotValid() {
}
void GfxControls16::kernelDrawButton(Common::Rect rect, reg_t obj, const char *text, uint16 languageSplitter, int16 fontId, int16 style, bool hilite) {
g_sci->_tts->button(text);
int16 sci0EarlyPen = 0, sci0EarlyBack = 0;
if (!hilite) {
if (getSciVersion() == SCI_VERSION_0_EARLY) {
@ -350,6 +353,8 @@ void GfxControls16::kernelDrawButton(Common::Rect rect, reg_t obj, const char *t
}
void GfxControls16::kernelDrawText(Common::Rect rect, reg_t obj, const char *text, uint16 languageSplitter, int16 fontId, TextAlignment alignment, int16 style, bool hilite) {
g_sci->_tts->text(text);
if (!hilite) {
rect.grow(1);
_paint16->eraseRect(rect);

View file

@ -24,6 +24,7 @@
#include "sci/engine/features.h"
#include "sci/engine/state.h"
#include "sci/engine/selector.h"
#include "sci/engine/tts.h"
#include "sci/engine/workarounds.h"
#include "sci/graphics/cache.h"
#include "sci/graphics/coordadjuster.h"
@ -495,6 +496,8 @@ reg_t GfxPaint16::kernelDisplay(const char *text, uint16 languageSplitter, int a
// SCI01+ only)
Port oldPort = *_ports->getPort();
g_sci->_tts->display(text);
// setting defaults
_ports->penMode(0);
_ports->penColor(0);

View file

@ -37,6 +37,7 @@ MODULE_OBJS := \
engine/segment.o \
engine/state.o \
engine/static_selectors.o \
engine/tts.o \
engine/vm.o \
engine/vm_types.o \
engine/workarounds.o \

View file

@ -43,6 +43,7 @@
#include "sci/engine/script_patches.h"
#include "sci/engine/selector.h" // for SELECTOR
#include "sci/engine/scriptdebug.h"
#include "sci/engine/tts.h"
#include "sci/sound/audio.h"
#include "sci/sound/music.h"
@ -254,12 +255,15 @@ SciEngine::~SciEngine() {
delete _scriptPatcher;
delete _resMan; // should be deleted last
delete _tts;
g_sci = nullptr;
}
extern int showScummVMDialog(const Common::U32String &message, const Common::U32String &altButton = Common::U32String(), bool alignCenter = true);
Common::Error SciEngine::run() {
_tts = new SciTTS();
_resMan = new ResourceManager();
_resMan->addAppropriateSources();
_resMan->init();

View file

@ -80,6 +80,7 @@ class GfxScreen;
class GfxText16;
class GfxText32;
class GfxTransitions;
class SciTTS;
#ifdef ENABLE_SCI32
class GfxFrameout;
@ -256,6 +257,7 @@ public:
GfxText16 *_gfxText16;
GfxTransitions *_gfxTransitions; // transitions between screens for 16-bit gfx
GfxMacIconBar *_gfxMacIconBar; // Mac Icon Bar manager
SciTTS *_tts;
#ifdef ENABLE_SCI32
GfxControls32 *_gfxControls32; // Controls for 32-bit gfx