format previously missed chromium_src .cc files
This commit is contained in:
parent
8cc81509d7
commit
f7d4437b3f
58 changed files with 688 additions and 898 deletions
|
@ -27,36 +27,26 @@ std::string TrimLanguageCode(std::string lang) {
|
|||
} // namespace
|
||||
|
||||
bool IsFinalTtsEventType(TtsEventType event_type) {
|
||||
return (event_type == TTS_EVENT_END ||
|
||||
event_type == TTS_EVENT_INTERRUPTED ||
|
||||
event_type == TTS_EVENT_CANCELLED ||
|
||||
event_type == TTS_EVENT_ERROR);
|
||||
return (event_type == TTS_EVENT_END || event_type == TTS_EVENT_INTERRUPTED ||
|
||||
event_type == TTS_EVENT_CANCELLED || event_type == TTS_EVENT_ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// UtteranceContinuousParameters
|
||||
//
|
||||
|
||||
|
||||
UtteranceContinuousParameters::UtteranceContinuousParameters()
|
||||
: rate(-1),
|
||||
pitch(-1),
|
||||
volume(-1) {}
|
||||
|
||||
: rate(-1), pitch(-1), volume(-1) {}
|
||||
|
||||
//
|
||||
// VoiceData
|
||||
//
|
||||
|
||||
|
||||
VoiceData::VoiceData()
|
||||
: gender(TTS_GENDER_NONE),
|
||||
remote(false),
|
||||
native(false) {}
|
||||
: gender(TTS_GENDER_NONE), remote(false), native(false) {}
|
||||
|
||||
VoiceData::~VoiceData() {}
|
||||
|
||||
|
||||
//
|
||||
// Utterance
|
||||
//
|
||||
|
@ -118,8 +108,7 @@ TtsControllerImpl::TtsControllerImpl()
|
|||
: current_utterance_(NULL),
|
||||
paused_(false),
|
||||
platform_impl_(NULL),
|
||||
tts_engine_delegate_(NULL) {
|
||||
}
|
||||
tts_engine_delegate_(NULL) {}
|
||||
|
||||
TtsControllerImpl::~TtsControllerImpl() {
|
||||
if (current_utterance_) {
|
||||
|
@ -215,12 +204,9 @@ void TtsControllerImpl::SpeakNow(Utterance* utterance) {
|
|||
// during |speak|.
|
||||
current_utterance_ = utterance;
|
||||
GetPlatformImpl()->clear_error();
|
||||
bool success = GetPlatformImpl()->Speak(
|
||||
utterance->id(),
|
||||
utterance->text(),
|
||||
utterance->lang(),
|
||||
voice,
|
||||
utterance->continuous_parameters());
|
||||
bool success = GetPlatformImpl()->Speak(utterance->id(), utterance->text(),
|
||||
utterance->lang(), voice,
|
||||
utterance->continuous_parameters());
|
||||
if (!success)
|
||||
current_utterance_ = NULL;
|
||||
|
||||
|
@ -288,9 +274,9 @@ void TtsControllerImpl::Resume() {
|
|||
}
|
||||
|
||||
void TtsControllerImpl::OnTtsEvent(int utterance_id,
|
||||
TtsEventType event_type,
|
||||
int char_index,
|
||||
const std::string& error_message) {
|
||||
TtsEventType event_type,
|
||||
int char_index,
|
||||
const std::string& error_message) {
|
||||
// We may sometimes receive completion callbacks "late", after we've
|
||||
// already finished the utterance (for example because another utterance
|
||||
// interrupted or we got a call to Stop). This is normal and we can
|
||||
|
@ -306,7 +292,7 @@ void TtsControllerImpl::OnTtsEvent(int utterance_id,
|
|||
}
|
||||
|
||||
void TtsControllerImpl::GetVoices(content::BrowserContext* browser_context,
|
||||
std::vector<VoiceData>* out_voices) {
|
||||
std::vector<VoiceData>* out_voices) {
|
||||
#if !defined(OS_ANDROID)
|
||||
if (browser_context && tts_engine_delegate_)
|
||||
tts_engine_delegate_->GetVoices(browser_context, out_voices);
|
||||
|
@ -362,8 +348,7 @@ void TtsControllerImpl::ClearUtteranceQueue(bool send_events) {
|
|||
}
|
||||
}
|
||||
|
||||
void TtsControllerImpl::SetPlatformImpl(
|
||||
TtsPlatformImpl* platform_impl) {
|
||||
void TtsControllerImpl::SetPlatformImpl(TtsPlatformImpl* platform_impl) {
|
||||
platform_impl_ = platform_impl;
|
||||
}
|
||||
|
||||
|
@ -377,8 +362,8 @@ TtsPlatformImpl* TtsControllerImpl::GetPlatformImpl() {
|
|||
return platform_impl_;
|
||||
}
|
||||
|
||||
int TtsControllerImpl::GetMatchingVoice(
|
||||
const Utterance* utterance, std::vector<VoiceData>& voices) {
|
||||
int TtsControllerImpl::GetMatchingVoice(const Utterance* utterance,
|
||||
std::vector<VoiceData>& voices) {
|
||||
// Make two passes: the first time, do strict language matching
|
||||
// ('fr-FR' does not match 'fr-CA'). The second time, do prefix
|
||||
// language matching ('fr-FR' matches 'fr' and 'fr-CA')
|
||||
|
@ -391,8 +376,7 @@ int TtsControllerImpl::GetMatchingVoice(
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!voice.name.empty() &&
|
||||
!utterance->voice_name().empty() &&
|
||||
if (!voice.name.empty() && !utterance->voice_name().empty() &&
|
||||
voice.name != utterance->voice_name()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -417,8 +401,7 @@ int TtsControllerImpl::GetMatchingVoice(
|
|||
bool has_all_required_event_types = true;
|
||||
for (std::set<TtsEventType>::const_iterator iter =
|
||||
utterance->required_event_types().begin();
|
||||
iter != utterance->required_event_types().end();
|
||||
++iter) {
|
||||
iter != utterance->required_event_types().end(); ++iter) {
|
||||
if (voice.events.find(*iter) == voice.events.end()) {
|
||||
has_all_required_event_types = false;
|
||||
break;
|
||||
|
@ -453,8 +436,7 @@ void TtsControllerImpl::RemoveVoicesChangedDelegate(
|
|||
voices_changed_delegates_.erase(delegate);
|
||||
}
|
||||
|
||||
void TtsControllerImpl::SetTtsEngineDelegate(
|
||||
TtsEngineDelegate* delegate) {
|
||||
void TtsControllerImpl::SetTtsEngineDelegate(TtsEngineDelegate* delegate) {
|
||||
tts_engine_delegate_ = delegate;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class TtsPlatformImplLinux : public TtsPlatformImpl {
|
|||
|
||||
// Map a string composed of a voicename and module to the voicename. Used to
|
||||
// uniquely identify a voice across all available modules.
|
||||
std::unique_ptr<std::map<std::string, SPDChromeVoice> > all_native_voices_;
|
||||
std::unique_ptr<std::map<std::string, SPDChromeVoice>> all_native_voices_;
|
||||
|
||||
friend struct base::DefaultSingletonTraits<TtsPlatformImplLinux>;
|
||||
|
||||
|
@ -89,20 +89,17 @@ class TtsPlatformImplLinux : public TtsPlatformImpl {
|
|||
};
|
||||
|
||||
// static
|
||||
SPDNotificationType TtsPlatformImplLinux::current_notification_ =
|
||||
SPD_EVENT_END;
|
||||
SPDNotificationType TtsPlatformImplLinux::current_notification_ = SPD_EVENT_END;
|
||||
|
||||
TtsPlatformImplLinux::TtsPlatformImplLinux()
|
||||
: utterance_id_(0) {
|
||||
TtsPlatformImplLinux::TtsPlatformImplLinux() : utterance_id_(0) {
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
if (!command_line.HasSwitch(switches::kEnableSpeechDispatcher))
|
||||
return;
|
||||
|
||||
BrowserThread::PostTask(BrowserThread::FILE,
|
||||
FROM_HERE,
|
||||
base::Bind(&TtsPlatformImplLinux::Initialize,
|
||||
base::Unretained(this)));
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::FILE, FROM_HERE,
|
||||
base::Bind(&TtsPlatformImplLinux::Initialize, base::Unretained(this)));
|
||||
}
|
||||
|
||||
void TtsPlatformImplLinux::Initialize() {
|
||||
|
@ -115,19 +112,15 @@ void TtsPlatformImplLinux::Initialize() {
|
|||
// spd_open has memory leaks which are hard to suppress.
|
||||
// http://crbug.com/317360
|
||||
ANNOTATE_SCOPED_MEMORY_LEAK;
|
||||
conn_ = libspeechd_loader_.spd_open(
|
||||
"chrome", "extension_api", NULL, SPD_MODE_THREADED);
|
||||
conn_ = libspeechd_loader_.spd_open("chrome", "extension_api", NULL,
|
||||
SPD_MODE_THREADED);
|
||||
}
|
||||
if (!conn_)
|
||||
return;
|
||||
|
||||
// Register callbacks for all events.
|
||||
conn_->callback_begin =
|
||||
conn_->callback_end =
|
||||
conn_->callback_cancel =
|
||||
conn_->callback_pause =
|
||||
conn_->callback_resume =
|
||||
&NotificationCallback;
|
||||
conn_->callback_begin = conn_->callback_end = conn_->callback_cancel =
|
||||
conn_->callback_pause = conn_->callback_resume = &NotificationCallback;
|
||||
|
||||
conn_->callback_im = &IndexMarkCallback;
|
||||
|
||||
|
@ -150,8 +143,8 @@ void TtsPlatformImplLinux::Reset() {
|
|||
base::AutoLock lock(initialization_lock_);
|
||||
if (conn_)
|
||||
libspeechd_loader_.spd_close(conn_);
|
||||
conn_ = libspeechd_loader_.spd_open(
|
||||
"chrome", "extension_api", NULL, SPD_MODE_THREADED);
|
||||
conn_ = libspeechd_loader_.spd_open("chrome", "extension_api", NULL,
|
||||
SPD_MODE_THREADED);
|
||||
}
|
||||
|
||||
bool TtsPlatformImplLinux::PlatformImplAvailable() {
|
||||
|
@ -162,12 +155,11 @@ bool TtsPlatformImplLinux::PlatformImplAvailable() {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool TtsPlatformImplLinux::Speak(
|
||||
int utterance_id,
|
||||
const std::string& utterance,
|
||||
const std::string& lang,
|
||||
const VoiceData& voice,
|
||||
const UtteranceContinuousParameters& params) {
|
||||
bool TtsPlatformImplLinux::Speak(int utterance_id,
|
||||
const std::string& utterance,
|
||||
const std::string& lang,
|
||||
const VoiceData& voice,
|
||||
const UtteranceContinuousParameters& params) {
|
||||
if (!PlatformImplAvailable()) {
|
||||
error_ = kNotSupportedError;
|
||||
return false;
|
||||
|
@ -232,8 +224,7 @@ bool TtsPlatformImplLinux::IsSpeaking() {
|
|||
return current_notification_ == SPD_EVENT_BEGIN;
|
||||
}
|
||||
|
||||
void TtsPlatformImplLinux::GetVoices(
|
||||
std::vector<VoiceData>* out_voices) {
|
||||
void TtsPlatformImplLinux::GetVoices(std::vector<VoiceData>* out_voices) {
|
||||
if (!all_native_voices_.get()) {
|
||||
all_native_voices_.reset(new std::map<std::string, SPDChromeVoice>());
|
||||
char** modules = libspeechd_loader_.spd_list_modules(conn_);
|
||||
|
@ -267,8 +258,7 @@ void TtsPlatformImplLinux::GetVoices(
|
|||
|
||||
for (std::map<std::string, SPDChromeVoice>::iterator it =
|
||||
all_native_voices_->begin();
|
||||
it != all_native_voices_->end();
|
||||
it++) {
|
||||
it != all_native_voices_->end(); it++) {
|
||||
out_voices->push_back(VoiceData());
|
||||
VoiceData& voice = out_voices->back();
|
||||
voice.native = true;
|
||||
|
@ -285,40 +275,40 @@ void TtsPlatformImplLinux::GetVoices(
|
|||
void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) {
|
||||
TtsController* controller = TtsController::GetInstance();
|
||||
switch (type) {
|
||||
case SPD_EVENT_BEGIN:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string());
|
||||
break;
|
||||
case SPD_EVENT_RESUME:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME, 0, std::string());
|
||||
break;
|
||||
case SPD_EVENT_END:
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_END, utterance_.size(), std::string());
|
||||
break;
|
||||
case SPD_EVENT_PAUSE:
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_PAUSE, utterance_.size(), std::string());
|
||||
break;
|
||||
case SPD_EVENT_CANCEL:
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_CANCELLED, 0, std::string());
|
||||
break;
|
||||
case SPD_EVENT_INDEX_MARK:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string());
|
||||
break;
|
||||
case SPD_EVENT_BEGIN:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string());
|
||||
break;
|
||||
case SPD_EVENT_RESUME:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME, 0, std::string());
|
||||
break;
|
||||
case SPD_EVENT_END:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_END, utterance_.size(),
|
||||
std::string());
|
||||
break;
|
||||
case SPD_EVENT_PAUSE:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_PAUSE, utterance_.size(),
|
||||
std::string());
|
||||
break;
|
||||
case SPD_EVENT_CANCEL:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_CANCELLED, 0,
|
||||
std::string());
|
||||
break;
|
||||
case SPD_EVENT_INDEX_MARK:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void TtsPlatformImplLinux::NotificationCallback(
|
||||
size_t msg_id, size_t client_id, SPDNotificationType type) {
|
||||
void TtsPlatformImplLinux::NotificationCallback(size_t msg_id,
|
||||
size_t client_id,
|
||||
SPDNotificationType type) {
|
||||
// We run Speech Dispatcher in threaded mode, so these callbacks should always
|
||||
// be in a separate thread.
|
||||
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
||||
current_notification_ = type;
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::UI,
|
||||
FROM_HERE,
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&TtsPlatformImplLinux::OnSpeechEvent,
|
||||
base::Unretained(TtsPlatformImplLinux::GetInstance()),
|
||||
type));
|
||||
|
@ -327,9 +317,9 @@ void TtsPlatformImplLinux::NotificationCallback(
|
|||
|
||||
// static
|
||||
void TtsPlatformImplLinux::IndexMarkCallback(size_t msg_id,
|
||||
size_t client_id,
|
||||
SPDNotificationType state,
|
||||
char* index_mark) {
|
||||
size_t client_id,
|
||||
SPDNotificationType state,
|
||||
char* index_mark) {
|
||||
// TODO(dtseng): index_mark appears to specify an index type supplied by a
|
||||
// client. Need to explore how this is used before hooking it up with existing
|
||||
// word, sentence events.
|
||||
|
@ -337,10 +327,11 @@ void TtsPlatformImplLinux::IndexMarkCallback(size_t msg_id,
|
|||
// be in a separate thread.
|
||||
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
||||
current_notification_ = state;
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&TtsPlatformImplLinux::OnSpeechEvent,
|
||||
base::Unretained(TtsPlatformImplLinux::GetInstance()),
|
||||
state));
|
||||
base::Unretained(TtsPlatformImplLinux::GetInstance()),
|
||||
state));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,16 +25,16 @@ TtsMessageFilter::TtsMessageFilter(int render_process_id,
|
|||
AddRef();
|
||||
}
|
||||
|
||||
void TtsMessageFilter::OverrideThreadForMessage(
|
||||
const IPC::Message& message, BrowserThread::ID* thread) {
|
||||
void TtsMessageFilter::OverrideThreadForMessage(const IPC::Message& message,
|
||||
BrowserThread::ID* thread) {
|
||||
switch (message.type()) {
|
||||
case TtsHostMsg_InitializeVoiceList::ID:
|
||||
case TtsHostMsg_Speak::ID:
|
||||
case TtsHostMsg_Pause::ID:
|
||||
case TtsHostMsg_Resume::ID:
|
||||
case TtsHostMsg_Cancel::ID:
|
||||
*thread = BrowserThread::UI;
|
||||
break;
|
||||
case TtsHostMsg_InitializeVoiceList::ID:
|
||||
case TtsHostMsg_Speak::ID:
|
||||
case TtsHostMsg_Pause::ID:
|
||||
case TtsHostMsg_Resume::ID:
|
||||
case TtsHostMsg_Cancel::ID:
|
||||
*thread = BrowserThread::UI;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,8 +144,8 @@ void TtsMessageFilter::OnTtsEvent(Utterance* utterance,
|
|||
Send(new TtsMsg_WasCancelled(utterance->src_id()));
|
||||
break;
|
||||
case TTS_EVENT_ERROR:
|
||||
Send(new TtsMsg_SpeakingErrorOccurred(
|
||||
utterance->src_id(), error_message));
|
||||
Send(
|
||||
new TtsMsg_SpeakingErrorOccurred(utterance->src_id(), error_message));
|
||||
break;
|
||||
case TTS_EVENT_PAUSE:
|
||||
Send(new TtsMsg_DidPauseSpeaking(utterance->src_id()));
|
||||
|
|
|
@ -16,16 +16,13 @@
|
|||
|
||||
class TtsPlatformImplWin : public TtsPlatformImpl {
|
||||
public:
|
||||
bool PlatformImplAvailable() override {
|
||||
return true;
|
||||
}
|
||||
bool PlatformImplAvailable() override { return true; }
|
||||
|
||||
bool Speak(
|
||||
int utterance_id,
|
||||
const std::string& utterance,
|
||||
const std::string& lang,
|
||||
const VoiceData& voice,
|
||||
const UtteranceContinuousParameters& params) override;
|
||||
bool Speak(int utterance_id,
|
||||
const std::string& utterance,
|
||||
const std::string& lang,
|
||||
const VoiceData& voice,
|
||||
const UtteranceContinuousParameters& params) override;
|
||||
|
||||
bool StopSpeaking() override;
|
||||
|
||||
|
@ -68,12 +65,11 @@ TtsPlatformImpl* TtsPlatformImpl::GetInstance() {
|
|||
return TtsPlatformImplWin::GetInstance();
|
||||
}
|
||||
|
||||
bool TtsPlatformImplWin::Speak(
|
||||
int utterance_id,
|
||||
const std::string& src_utterance,
|
||||
const std::string& lang,
|
||||
const VoiceData& voice,
|
||||
const UtteranceContinuousParameters& params) {
|
||||
bool TtsPlatformImplWin::Speak(int utterance_id,
|
||||
const std::string& src_utterance,
|
||||
const std::string& lang,
|
||||
const VoiceData& voice,
|
||||
const UtteranceContinuousParameters& params) {
|
||||
std::wstring prefix;
|
||||
std::wstring suffix;
|
||||
|
||||
|
@ -114,10 +110,8 @@ bool TtsPlatformImplWin::Speak(
|
|||
std::wstring merged_utterance = prefix + utterance_ + suffix;
|
||||
prefix_len_ = prefix.size();
|
||||
|
||||
HRESULT result = speech_synthesizer_->Speak(
|
||||
merged_utterance.c_str(),
|
||||
SPF_ASYNC,
|
||||
&stream_number_);
|
||||
HRESULT result = speech_synthesizer_->Speak(merged_utterance.c_str(),
|
||||
SPF_ASYNC, &stream_number_);
|
||||
return (result == S_OK);
|
||||
}
|
||||
|
||||
|
@ -143,8 +137,8 @@ void TtsPlatformImplWin::Pause() {
|
|||
if (speech_synthesizer_.Get() && utterance_id_ && !paused_) {
|
||||
speech_synthesizer_->Pause();
|
||||
paused_ = true;
|
||||
TtsController::GetInstance()->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_PAUSE, char_position_, "");
|
||||
TtsController::GetInstance()->OnTtsEvent(utterance_id_, TTS_EVENT_PAUSE,
|
||||
char_position_, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +146,8 @@ void TtsPlatformImplWin::Resume() {
|
|||
if (speech_synthesizer_.Get() && utterance_id_ && paused_) {
|
||||
speech_synthesizer_->Resume();
|
||||
paused_ = false;
|
||||
TtsController::GetInstance()->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_RESUME, char_position_, "");
|
||||
TtsController::GetInstance()->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME,
|
||||
char_position_, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,8 +165,7 @@ bool TtsPlatformImplWin::IsSpeaking() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void TtsPlatformImplWin::GetVoices(
|
||||
std::vector<VoiceData>* out_voices) {
|
||||
void TtsPlatformImplWin::GetVoices(std::vector<VoiceData>* out_voices) {
|
||||
// TODO: get all voices, not just default voice.
|
||||
// http://crbug.com/88059
|
||||
out_voices->push_back(VoiceData());
|
||||
|
@ -196,51 +189,47 @@ void TtsPlatformImplWin::OnSpeechEvent() {
|
|||
continue;
|
||||
|
||||
switch (event.eEventId) {
|
||||
case SPEI_START_INPUT_STREAM:
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_START, 0, std::string());
|
||||
break;
|
||||
case SPEI_END_INPUT_STREAM:
|
||||
char_position_ = utterance_.size();
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_END, char_position_, std::string());
|
||||
break;
|
||||
case SPEI_TTS_BOOKMARK:
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_MARKER, char_position_, std::string());
|
||||
break;
|
||||
case SPEI_WORD_BOUNDARY:
|
||||
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_WORD, char_position_,
|
||||
std::string());
|
||||
break;
|
||||
case SPEI_SENTENCE_BOUNDARY:
|
||||
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
|
||||
controller->OnTtsEvent(
|
||||
utterance_id_, TTS_EVENT_SENTENCE, char_position_,
|
||||
std::string());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case SPEI_START_INPUT_STREAM:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0,
|
||||
std::string());
|
||||
break;
|
||||
case SPEI_END_INPUT_STREAM:
|
||||
char_position_ = utterance_.size();
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_END, char_position_,
|
||||
std::string());
|
||||
break;
|
||||
case SPEI_TTS_BOOKMARK:
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, char_position_,
|
||||
std::string());
|
||||
break;
|
||||
case SPEI_WORD_BOUNDARY:
|
||||
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_WORD, char_position_,
|
||||
std::string());
|
||||
break;
|
||||
case SPEI_SENTENCE_BOUNDARY:
|
||||
char_position_ = static_cast<ULONG>(event.lParam) - prefix_len_;
|
||||
controller->OnTtsEvent(utterance_id_, TTS_EVENT_SENTENCE,
|
||||
char_position_, std::string());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TtsPlatformImplWin::TtsPlatformImplWin()
|
||||
: utterance_id_(0),
|
||||
prefix_len_(0),
|
||||
stream_number_(0),
|
||||
char_position_(0),
|
||||
paused_(false) {
|
||||
: utterance_id_(0),
|
||||
prefix_len_(0),
|
||||
stream_number_(0),
|
||||
char_position_(0),
|
||||
paused_(false) {
|
||||
::CoCreateInstance(CLSID_SpVoice, nullptr, CLSCTX_ALL,
|
||||
IID_PPV_ARGS(&speech_synthesizer_));
|
||||
if (speech_synthesizer_.Get()) {
|
||||
ULONGLONG event_mask =
|
||||
SPFEI(SPEI_START_INPUT_STREAM) |
|
||||
SPFEI(SPEI_TTS_BOOKMARK) |
|
||||
SPFEI(SPEI_WORD_BOUNDARY) |
|
||||
SPFEI(SPEI_SENTENCE_BOUNDARY) |
|
||||
SPFEI(SPEI_START_INPUT_STREAM) | SPFEI(SPEI_TTS_BOOKMARK) |
|
||||
SPFEI(SPEI_WORD_BOUNDARY) | SPFEI(SPEI_SENTENCE_BOUNDARY) |
|
||||
SPFEI(SPEI_END_INPUT_STREAM);
|
||||
speech_synthesizer_->SetInterest(event_mask, event_mask);
|
||||
speech_synthesizer_->SetNotifyCallbackFunction(
|
||||
|
@ -255,7 +244,6 @@ TtsPlatformImplWin* TtsPlatformImplWin::GetInstance() {
|
|||
}
|
||||
|
||||
// static
|
||||
void TtsPlatformImplWin::SpeechEventCallback(
|
||||
WPARAM w_param, LPARAM l_param) {
|
||||
void TtsPlatformImplWin::SpeechEventCallback(WPARAM w_param, LPARAM l_param) {
|
||||
GetInstance()->OnSpeechEvent();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue