Update to Chrome47 version of tts_linux

This commit is contained in:
Paul Betts 2015-12-07 14:28:42 -08:00
parent 4a8d58f914
commit fe86239a9c

View file

@ -13,6 +13,7 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "chrome/browser/speech/tts_platform.h" #include "chrome/browser/speech/tts_platform.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "library_loaders/libspeechd.h" #include "library_loaders/libspeechd.h"
@ -32,18 +33,17 @@ struct SPDChromeVoice {
class TtsPlatformImplLinux : public TtsPlatformImpl { class TtsPlatformImplLinux : public TtsPlatformImpl {
public: public:
virtual bool PlatformImplAvailable() override; bool PlatformImplAvailable() override;
virtual bool Speak( bool Speak(int utterance_id,
int utterance_id, const std::string& utterance,
const std::string& utterance, const std::string& lang,
const std::string& lang, const VoiceData& voice,
const VoiceData& voice, const UtteranceContinuousParameters& params) override;
const UtteranceContinuousParameters& params) override; bool StopSpeaking() override;
virtual bool StopSpeaking() override; void Pause() override;
virtual void Pause() override; void Resume() override;
virtual void Resume() override; bool IsSpeaking() override;
virtual bool IsSpeaking() override; void GetVoices(std::vector<VoiceData>* out_voices) override;
virtual void GetVoices(std::vector<VoiceData>* out_voices) override;
void OnSpeechEvent(SPDNotificationType type); void OnSpeechEvent(SPDNotificationType type);
@ -52,7 +52,7 @@ class TtsPlatformImplLinux : public TtsPlatformImpl {
private: private:
TtsPlatformImplLinux(); TtsPlatformImplLinux();
virtual ~TtsPlatformImplLinux(); ~TtsPlatformImplLinux() override;
// Initiate the connection with the speech dispatcher. // Initiate the connection with the speech dispatcher.
void Initialize(); void Initialize();
@ -83,7 +83,7 @@ class TtsPlatformImplLinux : public TtsPlatformImpl {
// uniquely identify a voice across all available modules. // uniquely identify a voice across all available modules.
scoped_ptr<std::map<std::string, SPDChromeVoice> > all_native_voices_; scoped_ptr<std::map<std::string, SPDChromeVoice> > all_native_voices_;
friend struct DefaultSingletonTraits<TtsPlatformImplLinux>; friend struct base::DefaultSingletonTraits<TtsPlatformImplLinux>;
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplLinux); DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplLinux);
}; };
@ -94,6 +94,11 @@ SPDNotificationType TtsPlatformImplLinux::current_notification_ =
TtsPlatformImplLinux::TtsPlatformImplLinux() TtsPlatformImplLinux::TtsPlatformImplLinux()
: utterance_id_(0) { : utterance_id_(0) {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kEnableSpeechDispatcher))
return;
BrowserThread::PostTask(BrowserThread::FILE, BrowserThread::PostTask(BrowserThread::FILE,
FROM_HERE, FROM_HERE,
base::Bind(&TtsPlatformImplLinux::Initialize, base::Bind(&TtsPlatformImplLinux::Initialize,
@ -111,7 +116,7 @@ void TtsPlatformImplLinux::Initialize() {
// http://crbug.com/317360 // http://crbug.com/317360
ANNOTATE_SCOPED_MEMORY_LEAK; ANNOTATE_SCOPED_MEMORY_LEAK;
conn_ = libspeechd_loader_.spd_open( conn_ = libspeechd_loader_.spd_open(
"chrome", "extension_api", NULL, SPD_MODE_SINGLE); "chrome", "extension_api", NULL, SPD_MODE_THREADED);
} }
if (!conn_) if (!conn_)
return; return;
@ -146,7 +151,7 @@ void TtsPlatformImplLinux::Reset() {
if (conn_) if (conn_)
libspeechd_loader_.spd_close(conn_); libspeechd_loader_.spd_close(conn_);
conn_ = libspeechd_loader_.spd_open( conn_ = libspeechd_loader_.spd_open(
"chrome", "extension_api", NULL, SPD_MODE_SINGLE); "chrome", "extension_api", NULL, SPD_MODE_THREADED);
} }
bool TtsPlatformImplLinux::PlatformImplAvailable() { bool TtsPlatformImplLinux::PlatformImplAvailable() {
@ -187,6 +192,10 @@ bool TtsPlatformImplLinux::Speak(
libspeechd_loader_.spd_set_voice_rate(conn_, 100 * log10(rate) / log10(3)); libspeechd_loader_.spd_set_voice_rate(conn_, 100 * log10(rate) / log10(3));
libspeechd_loader_.spd_set_voice_pitch(conn_, 100 * log10(pitch) / log10(3)); libspeechd_loader_.spd_set_voice_pitch(conn_, 100 * log10(pitch) / log10(3));
// Support languages other than the default
if (!lang.empty())
libspeechd_loader_.spd_set_language(conn_, lang.c_str());
utterance_ = utterance; utterance_ = utterance;
utterance_id_ = utterance_id; utterance_id_ = utterance_id;
@ -337,8 +346,9 @@ void TtsPlatformImplLinux::IndexMarkCallback(size_t msg_id,
// static // static
TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() { TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() {
return Singleton<TtsPlatformImplLinux, return base::Singleton<
LeakySingletonTraits<TtsPlatformImplLinux> >::get(); TtsPlatformImplLinux,
base::LeakySingletonTraits<TtsPlatformImplLinux>>::get();
} }
// static // static