1
0
Fork 0
flightgear/src/Sound/VoiceSynthesizer.hxx

96 lines
2.6 KiB
C++
Raw Normal View History

2014-04-24 20:59:08 +02:00
/*
2014-05-06 10:33:50 +02:00
* VoiceSynthesizer.hxx - wraps flite+hts_engine
* Copyright (C) 2014 Torsten Dreyer - torsten (at) t3r (dot) de
*
* 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.
2014-04-24 20:59:08 +02:00
*/
#ifndef VOICESYNTHESIZER_HXX_
#define VOICESYNTHESIZER_HXX_
#include <simgear/sound/sample_openal.hxx>
#include <simgear/threads/SGQueue.hxx>
#include <string>
struct _Flite_HTS_Engine;
/**
* A Voice Synthesizer Interface
*/
class VoiceSynthesizer {
public:
virtual ~VoiceSynthesizer() {};
virtual SGSoundSample * synthesize( const std::string & text ) = 0;
};
class SoundSampleReadyListener {
public:
virtual ~SoundSampleReadyListener() {}
virtual void SoundSampleReady( SGSharedPtr<SGSoundSample> ) = 0;
};
struct SynthesizeRequest {
SynthesizeRequest() {
speed = volume = pitch = 1.0;
listener = NULL;
}
SynthesizeRequest( const SynthesizeRequest & other ) {
text = other.text;
speed = other.speed;
volume = other.volume;
pitch = other.pitch;
listener = other.listener;
}
SynthesizeRequest & operator = ( const SynthesizeRequest & other ) {
text = other.text;
speed = other.speed;
volume = other.volume;
pitch = other.pitch;
listener = other.listener;
return *this;
}
std::string text;
double speed;
double volume;
double pitch;
SoundSampleReadyListener * listener;
};
/**
* A Voice Synthesizer using FLITE+HTS
*/
class FLITEVoiceSynthesizer : public VoiceSynthesizer {
public:
FLITEVoiceSynthesizer( const std::string & voice );
~FLITEVoiceSynthesizer();
virtual SGSoundSample * synthesize( const std::string & text );
virtual void synthesize( SynthesizeRequest & request );
private:
struct _Flite_HTS_Engine * _engine;
class WorkerThread;
WorkerThread * _worker;
typedef SGBlockingQueue<SynthesizeRequest> SynthesizeRequestList;
SynthesizeRequestList _requests;
double _volume;
bool _keepScratchFile;
2014-04-24 20:59:08 +02:00
};
#endif /* VOICESYNTHESIZER_HXX_ */