| Index: chrome/browser/speech/tts_request_handler.cc
|
| diff --git a/chrome/browser/speech/tts_request_handler.cc b/chrome/browser/speech/tts_request_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8752e5ba15ef3c19ea5ed8c8fa407c522991279e
|
| --- /dev/null
|
| +++ b/chrome/browser/speech/tts_request_handler.cc
|
| @@ -0,0 +1,130 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/speech/tts_request_handler.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/speech/tts_controller.h"
|
| +#include "content/public/browser/browser_context.h"
|
| +
|
| +class TtsRequestEventHandler : public UtteranceEventDelegate {
|
| + public:
|
| + explicit TtsRequestEventHandler(content::TtsDispatcherHost* dispatcher_host);
|
| + virtual void OnTtsEvent(Utterance* utterance,
|
| + TtsEventType event_type,
|
| + int char_index,
|
| + const std::string& error_message) OVERRIDE;
|
| + private:
|
| + content::TtsDispatcherHost* dispatcher_host_;
|
| +};
|
| +
|
| +TtsRequestEventHandler::TtsRequestEventHandler(
|
| + content::TtsDispatcherHost* dispatcher_host)
|
| + : dispatcher_host_(dispatcher_host) {
|
| +}
|
| +
|
| +void TtsRequestEventHandler::OnTtsEvent(Utterance* utterance,
|
| + TtsEventType event_type,
|
| + int char_index,
|
| + const std::string& error_message) {
|
| + switch (event_type) {
|
| + case TTS_EVENT_START:
|
| + dispatcher_host_->DidStartSpeaking(utterance->src_id());
|
| + break;
|
| + case TTS_EVENT_END:
|
| + dispatcher_host_->DidFinishSpeaking(utterance->src_id());
|
| + break;
|
| + case TTS_EVENT_WORD:
|
| + dispatcher_host_->WordBoundary(
|
| + utterance->src_id(), char_index);
|
| + break;
|
| + case TTS_EVENT_SENTENCE:
|
| + dispatcher_host_->SentenceBoundary(
|
| + utterance->src_id(), char_index);
|
| + break;
|
| + case TTS_EVENT_MARKER:
|
| + dispatcher_host_->MarkerEvent(
|
| + utterance->src_id(), char_index);
|
| + break;
|
| + case TTS_EVENT_INTERRUPTED:
|
| + dispatcher_host_->WasInterrupted(utterance->src_id());
|
| + break;
|
| + case TTS_EVENT_CANCELLED:
|
| + dispatcher_host_->WasCancelled(utterance->src_id());
|
| + break;
|
| + case TTS_EVENT_ERROR:
|
| + dispatcher_host_->SpeakingErrorOccurred(
|
| + utterance->src_id(), error_message);
|
| + break;
|
| + }
|
| +
|
| + if (utterance->finished())
|
| + delete this;
|
| +}
|
| +
|
| +
|
| +TtsRequestHandler::TtsRequestHandler() {
|
| +}
|
| +
|
| +TtsRequestHandler::~TtsRequestHandler() {
|
| +}
|
| +
|
| +void TtsRequestHandler::OnInitializeVoiceList(
|
| + content::TtsDispatcherHost* dispatcher_host) {
|
| + content::BrowserContext* context = dispatcher_host->GetBrowserContext();
|
| + Profile* profile = Profile::FromBrowserContext(context);
|
| + CHECK(profile);
|
| + TtsController* tts_controller = TtsController::GetInstance();
|
| + std::vector<VoiceData> voices;
|
| + tts_controller->GetVoices(profile, &voices);
|
| +
|
| + std::vector<content::TtsVoice> out_voices;
|
| + out_voices.resize(voices.size());
|
| + for (size_t i = 0; i < voices.size(); ++i) {
|
| + content::TtsVoice& out_voice = out_voices[i];
|
| + out_voice.voice_uri = voices[i].name;
|
| + out_voice.name = voices[i].name;
|
| + out_voice.lang = voices[i].lang;
|
| + out_voice.local_service = true;
|
| + out_voice.is_default = (i == 0);
|
| + }
|
| + dispatcher_host->SendVoiceList(out_voices);
|
| +}
|
| +
|
| +void TtsRequestHandler::OnSpeak(content::TtsDispatcherHost* dispatcher_host,
|
| + const content::TtsUtteranceRequest& request) {
|
| + content::BrowserContext* context = dispatcher_host->GetBrowserContext();
|
| + Profile* profile = Profile::FromBrowserContext(context);
|
| + CHECK(profile);
|
| +
|
| + scoped_ptr<Utterance> utterance(new Utterance(profile));
|
| + utterance->set_src_id(request.id);
|
| + utterance->set_text(request.text);
|
| + utterance->set_lang(request.lang);
|
| + utterance->set_voice_name(request.voice);
|
| + utterance->set_can_enqueue(true);
|
| +
|
| + UtteranceContinuousParameters params;
|
| + params.rate = request.rate;
|
| + params.pitch = request.pitch;
|
| + params.volume = request.volume;
|
| + utterance->set_continuous_parameters(params);
|
| +
|
| + utterance->set_event_delegate(new TtsRequestEventHandler(dispatcher_host));
|
| +
|
| + TtsController::GetInstance()->SpeakOrEnqueue(utterance.release());
|
| +}
|
| +
|
| +void TtsRequestHandler::OnPause(content::TtsDispatcherHost* dispatcher_host) {
|
| + // TODO(dmazzoni): Not supported by TtsController yet.
|
| +}
|
| +
|
| +void TtsRequestHandler::OnResume(content::TtsDispatcherHost* dispatcher_host) {
|
| + // TODO(dmazzoni): Not supported by TtsController yet.
|
| +}
|
| +
|
| +void TtsRequestHandler::OnCancel(content::TtsDispatcherHost* dispatcher_host) {
|
| + TtsController::GetInstance()->Stop();
|
| +}
|
|
|